From 03987ef3d1ed9c2d604561a69db169cd535014b6 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期六, 25 七月 2020 16:17:04 +0800 Subject: [PATCH] commit --- src/queue/include/shm_queue.h | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/queue/include/shm_queue.h b/src/queue/include/shm_queue.h index 394545b..91e9530 100644 --- a/src/queue/include/shm_queue.h +++ b/src/queue/include/shm_queue.h @@ -2,12 +2,11 @@ #define __SHM_QUEUE_H__ #include "usg_common.h" -#include "mm.h" #include "hashtable.h" #include "lock_free_queue.h" #include "logger_factory.h" #include "shm_allocator.h" - +#include "sem_util.h" // default Queue size // #define LOCK_FREE_Q_DEFAULT_SIZE 16 @@ -33,7 +32,7 @@ inline bool push(const ELEM_T &a_data); inline bool push_nowait(const ELEM_T &a_data); - inline bool push_timeout(const ELEM_T &a_data, struct timespec * timeout); + inline bool push_timeout(const ELEM_T &a_data, const struct timespec * timeout); inline bool pop(ELEM_T &a_data); inline bool pop_nowait(ELEM_T &a_data); inline bool pop_timeout(ELEM_T &a_data, struct timespec * timeout); @@ -98,14 +97,18 @@ template < typename ELEM_T > SHMQueue<ELEM_T>::~SHMQueue() { + SemUtil::dec( queue->mutex); queue->reference--; LoggerFactory::getLogger().debug("SHMQueue destructor reference===%d", queue->reference.load()); if(queue->reference.load() == 0) { delete queue; hashtable_t *hashtable = mm_get_hashtable(); hashtable_remove(hashtable, KEY); - LoggerFactory::getLogger().debug("SHMQueue destructor delete queue"); +printf("SHMQueue destructor delete queue\n"); + } else { + SemUtil::inc(queue->mutex); } + } template < typename ELEM_T > @@ -143,7 +146,7 @@ } template < typename ELEM_T > -inline bool SHMQueue<ELEM_T>::push_timeout(const ELEM_T &a_data, struct timespec * timeout) +inline bool SHMQueue<ELEM_T>::push_timeout(const ELEM_T &a_data, const struct timespec * timeout) { return queue->push_timeout(a_data, timeout); @@ -156,7 +159,10 @@ template < typename ELEM_T > inline bool SHMQueue<ELEM_T>::pop(ELEM_T &a_data) { - return queue->pop(a_data); +// printf("SHMQueue pop before\n"); + int rv = queue->pop(a_data); +// printf("SHMQueue after before\n"); + return rv; } -- Gitblit v1.8.0