diff --git a/HISTORY b/HISTORY index 185b0d9..748845d 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ -Version 1.72 2024-01-07 +Version 1.72 2024-01-21 * call fast_mblock_ref_counter_dec for delay free node correctly + * fc_queue.[hc]: add function fc_queue_remove Version 1.71 2023-12-23 * full support IPv6 by pull request #47 diff --git a/make.sh b/make.sh index 10b6faf..b0b7f62 100755 --- a/make.sh +++ b/make.sh @@ -222,12 +222,12 @@ done if [ -n "$pthread_path" ]; then LIBS="$LIBS -lpthread" - line=$(nm $pthread_path 2>/dev/null | fgrep pthread_rwlockattr_setkind_np | fgrep -w T) + line=$(nm $pthread_path 2>/dev/null | grep -F pthread_rwlockattr_setkind_np | grep -w T) if [ -n "$line" ]; then CFLAGS="$CFLAGS -DWITH_PTHREAD_RWLOCKATTR_SETKIND_NP=1" fi elif [ -f /usr/lib/libc_r.so ]; then - line=$(nm -D /usr/lib/libc_r.so 2>/dev/null | grep pthread_create | grep -w T) + line=$(nm -D /usr/lib/libc_r.so 2>/dev/null | grep -F pthread_create | grep -w T) if [ -n "$line" ]; then LIBS="$LIBS -lc_r" fi diff --git a/src/fc_queue.c b/src/fc_queue.c index 2a40c45..0bb4b98 100644 --- a/src/fc_queue.c +++ b/src/fc_queue.c @@ -295,3 +295,49 @@ int fc_queue_free_chain(struct fc_queue *queue, struct fast_mblock_man chain.tail = previous; return fast_mblock_batch_free(mblock, &chain); } + +int fc_queue_remove(struct fc_queue *queue, void *data) +{ + void *previous; + void *current; + int result; + + pthread_mutex_lock(&queue->lcp.lock); + if (queue->head == NULL) + { + result = ENOENT; + } + else if (queue->head == data) + { + queue->head = FC_QUEUE_NEXT_PTR(queue, queue->head); + if (queue->head == NULL) + { + queue->tail = NULL; + } + result = 0; + } + else + { + result = ENOENT; + previous = queue->head; + while ((current=FC_QUEUE_NEXT_PTR(queue, previous)) != NULL) + { + if (current == data) + { + FC_QUEUE_NEXT_PTR(queue, previous) = + FC_QUEUE_NEXT_PTR(queue, current); + if (queue->tail == current) + { + queue->tail = previous; + } + result = 0; + break; + } + + previous = current; + } + } + pthread_mutex_unlock(&queue->lcp.lock); + + return result; +} diff --git a/src/fc_queue.h b/src/fc_queue.h index 7765811..7972a0b 100644 --- a/src/fc_queue.h +++ b/src/fc_queue.h @@ -226,6 +226,8 @@ int fc_queue_alloc_chain(struct fc_queue *queue, struct fast_mblock_man int fc_queue_free_chain(struct fc_queue *queue, struct fast_mblock_man *mblock, struct fc_queue_info *qinfo); +int fc_queue_remove(struct fc_queue *queue, void *data); + #ifdef __cplusplus } #endif