未验证 提交 75f50850 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #2077 from taosdata/hotfix/queue

set pNode->next to null, since item may be write into queue multiple …
...@@ -18,24 +18,24 @@ ...@@ -18,24 +18,24 @@
#include "taoserror.h" #include "taoserror.h"
#include "tqueue.h" #include "tqueue.h"
typedef struct _taos_qnode { typedef struct STaosQnode {
int type; int type;
struct _taos_qnode *next; struct STaosQnode *next;
char item[]; char item[];
} STaosQnode; } STaosQnode;
typedef struct _taos_q { typedef struct STaosQueue {
int32_t itemSize; int32_t itemSize;
int32_t numOfItems; int32_t numOfItems;
struct _taos_qnode *head; struct STaosQnode *head;
struct _taos_qnode *tail; struct STaosQnode *tail;
struct _taos_q *next; // for queue set struct STaosQueue *next; // for queue set
struct _taos_qset *qset; // for queue set struct STaosQset *qset; // for queue set
void *ahandle; // for queue set void *ahandle; // for queue set
pthread_mutex_t mutex; pthread_mutex_t mutex;
} STaosQueue; } STaosQueue;
typedef struct _taos_qset { typedef struct STaosQset {
STaosQueue *head; STaosQueue *head;
STaosQueue *current; STaosQueue *current;
pthread_mutex_t mutex; pthread_mutex_t mutex;
...@@ -44,7 +44,7 @@ typedef struct _taos_qset { ...@@ -44,7 +44,7 @@ typedef struct _taos_qset {
tsem_t sem; tsem_t sem;
} STaosQset; } STaosQset;
typedef struct _taos_qall { typedef struct STaosQall {
STaosQnode *current; STaosQnode *current;
STaosQnode *start; STaosQnode *start;
int32_t itemSize; int32_t itemSize;
...@@ -95,6 +95,7 @@ void *taosAllocateQitem(int size) { ...@@ -95,6 +95,7 @@ void *taosAllocateQitem(int size) {
void taosFreeQitem(void *param) { void taosFreeQitem(void *param) {
if (param == NULL) return; if (param == NULL) return;
uTrace("item:%p is freed", param);
char *temp = (char *)param; char *temp = (char *)param;
temp -= sizeof(STaosQnode); temp -= sizeof(STaosQnode);
free(temp); free(temp);
...@@ -104,6 +105,7 @@ int taosWriteQitem(taos_queue param, int type, void *item) { ...@@ -104,6 +105,7 @@ int taosWriteQitem(taos_queue param, int type, void *item) {
STaosQueue *queue = (STaosQueue *)param; STaosQueue *queue = (STaosQueue *)param;
STaosQnode *pNode = (STaosQnode *)(((char *)item) - sizeof(STaosQnode)); STaosQnode *pNode = (STaosQnode *)(((char *)item) - sizeof(STaosQnode));
pNode->type = type; pNode->type = type;
pNode->next = NULL;
pthread_mutex_lock(&queue->mutex); pthread_mutex_lock(&queue->mutex);
...@@ -143,7 +145,7 @@ int taosReadQitem(taos_queue param, int *type, void **pitem) { ...@@ -143,7 +145,7 @@ int taosReadQitem(taos_queue param, int *type, void **pitem) {
queue->numOfItems--; queue->numOfItems--;
if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, 1); if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, 1);
code = 1; code = 1;
uTrace("item:%p is read out from queue, items:%d", *pitem, queue->numOfItems); uTrace("item:%p is read out from queue:%p, type:%d items:%d", *pitem, *type, queue->numOfItems);
} }
pthread_mutex_unlock(&queue->mutex); pthread_mutex_unlock(&queue->mutex);
...@@ -337,6 +339,7 @@ int taosReadQitemFromQset(taos_qset param, int *type, void **pitem, void **phand ...@@ -337,6 +339,7 @@ int taosReadQitemFromQset(taos_qset param, int *type, void **pitem, void **phand
queue->numOfItems--; queue->numOfItems--;
atomic_sub_fetch_32(&qset->numOfItems, 1); atomic_sub_fetch_32(&qset->numOfItems, 1);
code = 1; code = 1;
uTrace("item:%p is read out from queue:%p, type:%d items:%d", *pitem, queue, *type, queue->numOfItems);
} }
pthread_mutex_unlock(&queue->mutex); pthread_mutex_unlock(&queue->mutex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册