int main(int argc, char **argv) { BEGIN_TESTS(); struct core_fast_ring ring; int capacity = 64; int i; int value; int elements; elements = 0; #if 0 printf("Required %d\n", capacity); #endif core_fast_ring_init(&ring, capacity, sizeof(int)); capacity = core_fast_ring_capacity(&ring); #if 0 printf("Provided %d\n", capacity); #endif TEST_BOOLEAN_EQUALS(core_fast_ring_is_empty_from_consumer(&ring), 1); for (i = 0; i < capacity; i++) { TEST_BOOLEAN_EQUALS(core_fast_ring_push_from_producer(&ring, &i), 1); elements++; TEST_INT_EQUALS(core_fast_ring_size_from_producer(&ring), elements); TEST_INT_EQUALS(core_fast_ring_size_from_consumer(&ring), elements); } TEST_BOOLEAN_EQUALS(core_fast_ring_is_full_from_producer(&ring), 1); for (i = 0; i < capacity; i++) { TEST_BOOLEAN_EQUALS(core_fast_ring_pop_from_consumer(&ring, &value), 1); elements--; TEST_INT_EQUALS(value, i); TEST_INT_EQUALS(core_fast_ring_size_from_producer(&ring), elements); TEST_INT_EQUALS(core_fast_ring_size_from_consumer(&ring), elements); } core_fast_ring_destroy(&ring); { struct core_fast_ring ring; int capacity = 64; struct thorium_message message; int action; int count; void *buffer; int inserted; int pulled; action = 1234; count = 0; buffer = NULL; thorium_message_init(&message, action, count, buffer); core_fast_ring_init(&ring, capacity, sizeof(struct thorium_message)); core_fast_ring_use_multiple_producers(&ring); inserted = 0; while (core_fast_ring_push_from_producer(&ring, &message)) { ++inserted; } /* * 64 + 1 = 65, 128 is the next power of 2 for the mask. */ /* TEST_INT_EQUALS(inserted, capacity); */ pulled = 0; while (core_fast_ring_pop_from_consumer(&ring, &message)) { ++pulled; } TEST_INT_EQUALS(inserted, pulled); core_fast_ring_destroy(&ring); thorium_message_destroy(&message); } END_TESTS(); return 0; }
void thorium_worker_destroy(struct thorium_worker *worker) { void *buffer; thorium_load_profiler_destroy(&worker->profiler); if (core_bitmap_get_bit_uint32_t(&worker->flags, FLAG_ENABLE_ACTOR_LOAD_PROFILER)) { core_buffered_file_writer_destroy(&worker->load_profile_writer); } core_map_destroy(&worker->actor_received_messages); /* thorium_worker_print_balance(worker); */ while (thorium_worker_fetch_clean_outbound_buffer(worker, &buffer)) { core_memory_pool_free(&worker->outbound_message_memory_pool, buffer); #ifdef THORIUM_WORKER_DEBUG_INJECTION ++worker->counter_freed_outbound_buffers_from_other_workers; #endif } #ifdef THORIUM_WORKER_DEBUG_INJECTION printf("AFTER COLLECTION\n"); thorium_worker_print_balance(worker); printf("THORIUM-> clean_message_queue_for_triage has %d items\n", core_fast_queue_size(&worker->clean_message_queue_for_triage)); printf("THORIUM-> clean_message_ring_for_triage has %d items\n", core_fast_ring_size_from_producer(&worker->clean_message_ring_for_triage)); printf("THORIUM-> injected_clean_outbound_buffers has %d items\n", core_fast_ring_size_from_producer(&worker->injected_clean_outbound_buffers)); #endif core_timer_destroy(&worker->timer); #ifdef THORIUM_WORKER_ENABLE_LOCK core_lock_destroy(&worker->lock); #endif core_fast_ring_destroy(&worker->actors_to_schedule); #ifdef THORIUM_NODE_INJECT_CLEAN_WORKER_BUFFERS core_fast_ring_destroy(&worker->injected_clean_outbound_buffers); core_fast_ring_destroy(&worker->clean_message_ring_for_triage); core_fast_queue_destroy(&worker->clean_message_queue_for_triage); #endif thorium_scheduler_destroy(&worker->scheduler); core_fast_ring_destroy(&worker->outbound_message_queue); core_fast_queue_destroy(&worker->outbound_message_queue_buffer); core_map_destroy(&worker->actors); core_map_iterator_destroy(&worker->actor_iterator); core_set_destroy(&worker->evicted_actors); worker->node = NULL; worker->name = -1; core_bitmap_set_bit_uint32_t(&worker->flags, FLAG_DEAD); core_memory_pool_destroy(&worker->ephemeral_memory); core_memory_pool_destroy(&worker->outbound_message_memory_pool); thorium_priority_assigner_destroy(&worker->assigner); }