Debian Codegraph @

crt/aws-c-io/include/aws/io/message_pool.h

raw symbols SCIP
1 #ifndef AWS_IO_MESSAGE_POOL_H
2 #define AWS_IO_MESSAGE_POOL_H
3 /**
4 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: Apache-2.0.
6 */
7 #include <aws/common/array_list.h>
8 #include <aws/io/io.h>
9
10 AWS_PUSH_SANE_WARNING_LEVEL
11
12 struct aws_memory_pool {
13 struct aws_allocator *alloc;
14 struct aws_array_list stack;
15 uint16_t ideal_segment_count;
16 size_t segment_size;
17 void *data_ptr;
18 };
19
20 struct aws_message_pool {
21 struct aws_allocator *alloc;
22 struct aws_memory_pool application_data_pool;
23 struct aws_memory_pool small_block_pool;
24 };
25
26 struct aws_message_pool_creation_args {
27 size_t application_data_msg_data_size;
28 uint8_t application_data_msg_count;
29 size_t small_block_msg_data_size;
30 uint8_t small_block_msg_count;
31 };
32
33 AWS_EXTERN_C_BEGIN
34
35 AWS_IO_API
36 int aws_memory_pool_init(
37 struct aws_memory_pool *mempool,
38 struct aws_allocator *alloc,
39 uint16_t ideal_segment_count,
40 size_t segment_size);
41
42 AWS_IO_API
43 void aws_memory_pool_clean_up(struct aws_memory_pool *mempool);
44
45 /**
46 * Acquires memory from the pool if available, otherwise, it attempts to allocate and returns the result.
47 */
48 AWS_IO_API
49 void *aws_memory_pool_acquire(struct aws_memory_pool *mempool);
50
51 /**
52 * Releases memory to the pool if space is available, otherwise frees `to_release`
53 */
54 AWS_IO_API
55 void aws_memory_pool_release(struct aws_memory_pool *mempool, void *to_release);
56
57 /**
58 * Initializes message pool using 'msg_pool' as the backing pool, 'args' is copied.
59 */
60 AWS_IO_API
61 int aws_message_pool_init(
62 struct aws_message_pool *msg_pool,
63 struct aws_allocator *alloc,
64 struct aws_message_pool_creation_args *args);
65
66 AWS_IO_API
67 void aws_message_pool_clean_up(struct aws_message_pool *msg_pool);
68
69 /**
70 * Acquires a message from the pool if available, otherwise, it attempts to allocate. If a message is acquired,
71 * note that size_hint is just a hint. the return value's capacity will be set to the actual buffer size.
72 */
73 AWS_IO_API
74 struct aws_io_message *aws_message_pool_acquire(
75 struct aws_message_pool *msg_pool,
76 enum aws_io_message_type message_type,
77 size_t size_hint);
78
79 /**
80 * Releases message to the pool if space is available, otherwise frees `message`
81 * @param message
82 */
83 AWS_IO_API
84 void aws_message_pool_release(struct aws_message_pool *msg_pool, struct aws_io_message *message);
85
86 AWS_EXTERN_C_END
87 AWS_POP_SANE_WARNING_LEVEL
88
89 #endif /* AWS_IO_MESSAGE_POOL_H */