diff --git a/HISTORY b/HISTORY index fcd5c18..ce88fe2 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.44 2020-03-21 +Version 1.44 2020-03-22 * add test file src/tests/test_pthread_lock.c * add uniq_skiplist.[hc] * add function split_string_ex diff --git a/src/common_blocked_queue.c b/src/common_blocked_queue.c index 89efa6d..83481b0 100644 --- a/src/common_blocked_queue.c +++ b/src/common_blocked_queue.c @@ -65,7 +65,8 @@ int common_blocked_queue_push(struct common_blocked_queue *queue, void *data) return result; } - node = (struct common_blocked_node *)fast_mblock_alloc_object(&queue->mblock); + node = (struct common_blocked_node *)fast_mblock_alloc_object( + &queue->mblock); if (node == NULL) { pthread_mutex_unlock(&(queue->lock)); @@ -202,9 +203,11 @@ void common_blocked_queue_free_all_nodes(struct common_blocked_queue *queue, { struct common_blocked_node *deleted; + pthread_mutex_lock(&(queue->lock)); while (node != NULL) { deleted = node; node = node->next; fast_mblock_free_object(&queue->mblock, deleted); } + pthread_mutex_unlock(&(queue->lock)); } diff --git a/src/tests/Makefile b/src/tests/Makefile index a2e621d..6e6adc3 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -8,7 +8,7 @@ ALL_PRGS = test_allocator test_skiplist test_multi_skiplist test_mblock test_blo test_id_generator test_ini_parser test_char_convert test_char_convert_loader \ test_logger test_skiplist_set test_crc32 test_thourands_seperator test_sched_thread \ test_json_parser test_pthread_lock test_uniq_skiplist test_split_string \ - test_server_id_func test_pipe + test_server_id_func test_pipe test_atomic all: $(ALL_PRGS) .c: diff --git a/src/tests/test_atomic.c b/src/tests/test_atomic.c new file mode 100644 index 0000000..bf45d9c --- /dev/null +++ b/src/tests/test_atomic.c @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include +#include +#include +#include "fastcommon/logger.h" +#include "fastcommon/shared_func.h" +#include "fastcommon/sched_thread.h" +#include "fastcommon/pthread_func.h" +#include "fastcommon/ini_file_reader.h" +#include "fastcommon/fast_allocator.h" + +#define LOOP_COUNT (100 * 1000 * 1000) +#define barrier() __asm__ __volatile__("" ::: "memory") + +static volatile int counter = 0; + +#define THREAD_COUNT 9 +pthread_t tids[THREAD_COUNT]; + +void *thread2_func(void *args) +{ + int i; + for (i=0; i