summaryrefslogtreecommitdiff
path: root/librabbitmq/amqp_mem.c
diff options
context:
space:
mode:
authorAlan Antonuk <alan.antonuk@gmail.com>2013-06-21 16:57:32 -0700
committerAlan Antonuk <alan.antonuk@gmail.com>2013-06-21 16:57:32 -0700
commit4a2d899cd3ae3ef8bb9305eddd88c95d3dfc0463 (patch)
tree5d40072884197ddcd5cb3e71ecb4455f30a7881b /librabbitmq/amqp_mem.c
parent837a0b540595f8d0fab3214b0126ef436712aa98 (diff)
downloadrabbitmq-c-github-ask-4a2d899cd3ae3ef8bb9305eddd88c95d3dfc0463.tar.gz
Channel-based memory management
Assign a decoding pool on a per-channel basis. This allows memory to be released on a per-channel basis which is helpful for clients handling multiple channels
Diffstat (limited to 'librabbitmq/amqp_mem.c')
-rw-r--r--librabbitmq/amqp_mem.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/librabbitmq/amqp_mem.c b/librabbitmq/amqp_mem.c
index b0844e5..88b1e9f 100644
--- a/librabbitmq/amqp_mem.c
+++ b/librabbitmq/amqp_mem.c
@@ -202,3 +202,46 @@ void amqp_bytes_free(amqp_bytes_t bytes)
{
free(bytes.bytes);
}
+
+amqp_pool_t *amqp_get_or_create_channel_pool(amqp_connection_state_t state, amqp_channel_t channel)
+{
+ amqp_pool_table_entry_t *entry;
+ size_t index = channel % POOL_TABLE_SIZE;
+
+ entry = state->pool_table[index];
+
+ for ( ; NULL != entry; entry = entry->next) {
+ if (channel == entry->channel) {
+ return &entry->pool;
+ }
+ }
+
+ entry = malloc(sizeof(amqp_pool_table_entry_t));
+ if (NULL == entry) {
+ return NULL;
+ }
+
+ entry->channel = channel;
+ entry->next = state->pool_table[index];
+ state->pool_table[index] = entry;
+
+ init_amqp_pool(&entry->pool, state->frame_max);
+
+ return &entry->pool;
+}
+
+amqp_pool_t *amqp_get_channel_pool(amqp_connection_state_t state, amqp_channel_t channel)
+{
+ amqp_pool_table_entry_t *entry;
+ size_t index = channel % POOL_TABLE_SIZE;
+
+ entry = state->pool_table[index];
+
+ for ( ; NULL != entry; entry = entry->next) {
+ if (channel == entry->channel) {
+ return &entry->pool;
+ }
+ }
+
+ return NULL;
+}