tqueue.c 10.7 KB
Newer Older
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "os.h"
17

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
18
#include "taoserror.h"
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
19
#include "tqueue.h"
20 21 22
#include "ulog.h"

typedef struct STaosQnode STaosQnode;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
23

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
24
typedef struct STaosQnode {
25 26
  STaosQnode *next;
  char        item[];
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
27 28
} STaosQnode;

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
29
typedef struct STaosQueue {
30 31 32 33 34 35 36 37 38 39
  int32_t         itemSize;
  int32_t         numOfItems;
  STaosQnode     *head;
  STaosQnode     *tail;
  STaosQueue     *next;     // for queue set
  STaosQset      *qset;     // for queue set
  void           *ahandle;  // for queue set
  FProcessItem    itemFp;
  FProcessItems   itemsFp;
  pthread_mutex_t mutex;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
40 41
} STaosQueue;

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
42
typedef struct STaosQset {
S
Shengliang Guan 已提交
43 44 45 46 47 48
  STaosQueue     *head;
  STaosQueue     *current;
  pthread_mutex_t mutex;
  int32_t         numOfQueues;
  int32_t         numOfItems;
  tsem_t          sem;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
49 50
} STaosQset;

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
51
typedef struct STaosQall {
S
Shengliang Guan 已提交
52 53 54 55 56 57
  STaosQnode *current;
  STaosQnode *start;
  int32_t     itemSize;
  int32_t     numOfItems;
} STaosQall;

58 59
STaosQueue *taosOpenQueue() {
  STaosQueue *queue = calloc(sizeof(STaosQueue), 1);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
60
  if (queue == NULL) {
S
Shengliang Guan 已提交
61
    terrno = TSDB_CODE_OUT_OF_MEMORY;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
62
    return NULL;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
63 64
  }

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
65
  pthread_mutex_init(&queue->mutex, NULL);
66

S
TD-1843  
Shengliang Guan 已提交
67
  uTrace("queue:%p is opened", queue);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
68 69
  return queue;
}
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
70

71 72
void taosSetQueueFp(STaosQueue *queue, FProcessItem itemFp, FProcessItems itemsFp) {
  if (queue == NULL) return;
S
Shengliang Guan 已提交
73 74
  queue->itemFp = itemFp;
  queue->itemsFp = itemsFp;
S
Shengliang Guan 已提交
75 76
}

77 78
void taosCloseQueue(STaosQueue *queue) {
  if (queue == NULL) return;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
79
  STaosQnode *pTemp;
80 81 82
  STaosQset  *qset;

  pthread_mutex_lock(&queue->mutex);
S
Shengliang Guan 已提交
83
  STaosQnode *pNode = queue->head;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
84
  queue->head = NULL;
85 86
  qset = queue->qset;
  pthread_mutex_unlock(&queue->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
87

S
Shengliang Guan 已提交
88
  if (queue->qset) taosRemoveFromQset(qset, queue);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
89

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
90 91 92
  while (pNode) {
    pTemp = pNode;
    pNode = pNode->next;
S
Shengliang Guan 已提交
93
    free(pTemp);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
94 95
  }

96
  pthread_mutex_destroy(&queue->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
97
  free(queue);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
98 99

  uTrace("queue:%p is closed", queue);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
100
}
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
101

102 103
bool taosQueueEmpty(STaosQueue *queue) {
  if (queue == NULL) return true;
S
Shengliang Guan 已提交
104 105 106 107 108 109

  bool empty = false;
  pthread_mutex_lock(&queue->mutex);
  if (queue->head == NULL && queue->tail == NULL) {
    empty = true;
  }
110
  pthread_mutex_unlock(&queue->mutex);
S
Shengliang Guan 已提交
111 112 113 114

  return empty;
}

115
void *taosAllocateQitem(int32_t size) {
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
116
  STaosQnode *pNode = (STaosQnode *)calloc(sizeof(STaosQnode) + size, 1);
S
Shengliang Guan 已提交
117

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
118
  if (pNode == NULL) return NULL;
119
  uTrace("item:%p, node:%p is allocated", pNode->item, pNode);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
120 121
  return (void *)pNode->item;
}
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
122

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
123 124 125 126 127
void taosFreeQitem(void *param) {
  if (param == NULL) return;

  char *temp = (char *)param;
  temp -= sizeof(STaosQnode);
128
  uTrace("item:%p, node:%p is freed", param, temp);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
129 130
  free(temp);
}
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
131

132 133
int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
  STaosQnode *pNode = (STaosQnode *)(((char *)pItem) - sizeof(STaosQnode));
134
  pNode->next = NULL;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
135

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
136
  pthread_mutex_lock(&queue->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
137

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
138 139 140 141 142
  if (queue->tail) {
    queue->tail->next = pNode;
    queue->tail = pNode;
  } else {
    queue->head = pNode;
S
Shengliang Guan 已提交
143
    queue->tail = pNode;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
144 145 146 147
  }

  queue->numOfItems++;
  if (queue->qset) atomic_add_fetch_32(&queue->qset->numOfItems, 1);
148
  uTrace("item:%p is put into queue:%p, items:%d", pItem, queue, queue->numOfItems);
149

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
150
  pthread_mutex_unlock(&queue->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
151

152 153
  if (queue->qset) tsem_post(&queue->qset->sem);

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
154
  return 0;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
155 156
}

157
int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
158
  STaosQnode *pNode = NULL;
159
  int32_t     code = 0;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
160

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
161
  pthread_mutex_lock(&queue->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
162

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
163
  if (queue->head) {
S
Shengliang Guan 已提交
164
    pNode = queue->head;
165
    *ppItem = pNode->item;
S
Shengliang Guan 已提交
166 167 168 169 170
    queue->head = pNode->next;
    if (queue->head == NULL) queue->tail = NULL;
    queue->numOfItems--;
    if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, 1);
    code = 1;
171
    uDebug("item:%p is read out from queue:%p, items:%d", *ppItem, queue, queue->numOfItems);
S
Shengliang Guan 已提交
172
  }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
173

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
174
  pthread_mutex_unlock(&queue->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
175

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
176 177
  return code;
}
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
178

179
STaosQall *taosAllocateQall() { return calloc(sizeof(STaosQall), 1); }
180

181
void taosFreeQall(STaosQall *qall) { free(qall); }
182

183 184 185
int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
  int32_t code = 0;
  bool    empty;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
186 187 188

  pthread_mutex_lock(&queue->mutex);

J
Jun Li 已提交
189 190
  empty = queue->head == NULL;
  if (!empty) {
191 192 193 194 195 196 197 198 199 200 201
    memset(qall, 0, sizeof(STaosQall));
    qall->current = queue->head;
    qall->start = queue->head;
    qall->numOfItems = queue->numOfItems;
    qall->itemSize = queue->itemSize;
    code = qall->numOfItems;

    queue->head = NULL;
    queue->tail = NULL;
    queue->numOfItems = 0;
    if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems);
J
Jun Li 已提交
202
  }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
203

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
204
  pthread_mutex_unlock(&queue->mutex);
J
Jun Li 已提交
205 206 207 208 209 210 211 212

  // if source queue is empty, we set destination qall to empty too.
  if (empty) {
    qall->current = NULL;
    qall->start = NULL;
    qall->numOfItems = 0;
  }
  return code;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
213
}
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
214

215
int32_t taosGetQitem(STaosQall *qall, void **ppItem) {
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
216
  STaosQnode *pNode;
217
  int32_t     num = 0;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
218

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
219
  pNode = qall->current;
S
Shengliang Guan 已提交
220 221
  if (pNode) qall->current = pNode->next;

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
222
  if (pNode) {
223
    *ppItem = pNode->item;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
224
    num = 1;
225
    uTrace("item:%p is fetched", *ppItem);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
226 227
  }

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
228
  return num;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
229 230
}

231
void taosResetQitems(STaosQall *qall) { qall->current = qall->start; }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
232

233
STaosQset *taosOpenQset() {
S
Shengliang Guan 已提交
234
  STaosQset *qset = (STaosQset *)calloc(sizeof(STaosQset), 1);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
235
  if (qset == NULL) {
S
Shengliang Guan 已提交
236
    terrno = TSDB_CODE_OUT_OF_MEMORY;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
237
    return NULL;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
238 239
  }

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
240
  pthread_mutex_init(&qset->mutex, NULL);
241
  tsem_init(&qset->sem, 0, 0);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
242

S
TD-1843  
Shengliang Guan 已提交
243
  uTrace("qset:%p is opened", qset);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
244 245
  return qset;
}
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
246

247 248
void taosCloseQset(STaosQset *qset) {
  if (qset == NULL) return;
249 250 251 252 253 254 255 256 257 258 259 260

  // remove all the queues from qset
  pthread_mutex_lock(&qset->mutex);
  while (qset->head) {
    STaosQueue *queue = qset->head;
    qset->head = qset->head->next;

    queue->qset = NULL;
    queue->next = NULL;
  }
  pthread_mutex_unlock(&qset->mutex);

261 262
  pthread_mutex_destroy(&qset->mutex);
  tsem_destroy(&qset->sem);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
263
  free(qset);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
264
  uTrace("qset:%p is closed", qset);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
265 266
}

267 268 269
// tsem_post 'qset->sem', so that reader threads waiting for it
// resumes execution and return, should only be used to signal the
// thread to exit.
270
void taosQsetThreadResume(STaosQset *qset) {
S
TD-1670  
Shengliang Guan 已提交
271
  uDebug("qset:%p, it will exit", qset);
272 273 274
  tsem_post(&qset->sem);
}

275
int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) {
S
Shengliang Guan 已提交
276
  if (queue->qset) return -1;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
277 278 279 280

  pthread_mutex_lock(&qset->mutex);

  queue->next = qset->head;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
281
  queue->ahandle = ahandle;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
282 283 284 285 286 287 288 289 290
  qset->head = queue;
  qset->numOfQueues++;

  pthread_mutex_lock(&queue->mutex);
  atomic_add_fetch_32(&qset->numOfItems, queue->numOfItems);
  queue->qset = qset;
  pthread_mutex_unlock(&queue->mutex);

  pthread_mutex_unlock(&qset->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
291

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
292
  uTrace("queue:%p is added into qset:%p", queue, qset);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
293 294 295
  return 0;
}

296
void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) {
297
  STaosQueue *tqueue = NULL;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
298 299 300 301 302 303

  pthread_mutex_lock(&qset->mutex);

  if (qset->head) {
    if (qset->head == queue) {
      qset->head = qset->head->next;
304
      tqueue = queue;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
305 306 307 308
    } else {
      STaosQueue *prev = qset->head;
      tqueue = qset->head->next;
      while (tqueue) {
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
309
        assert(tqueue->qset);
S
Shengliang Guan 已提交
310
        if (tqueue == queue) {
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
311
          prev->next = tqueue->next;
312
          break;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
313 314 315 316 317 318
        } else {
          prev = tqueue;
          tqueue = tqueue->next;
        }
      }
    }
319 320 321 322 323 324 325 326

    if (tqueue) {
      if (qset->current == queue) qset->current = tqueue->next;
      qset->numOfQueues--;

      pthread_mutex_lock(&queue->mutex);
      atomic_sub_fetch_32(&qset->numOfItems, queue->numOfItems);
      queue->qset = NULL;
327
      queue->next = NULL;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
328
      pthread_mutex_unlock(&queue->mutex);
329
    }
S
Shengliang Guan 已提交
330 331
  }

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
332
  pthread_mutex_unlock(&qset->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
333 334

  uTrace("queue:%p is removed from qset:%p", queue, qset);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
335 336
}

337
int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
338

339
int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FProcessItem *itemFp) {
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
340
  STaosQnode *pNode = NULL;
341
  int32_t     code = 0;
S
Shengliang Guan 已提交
342

343 344
  tsem_wait(&qset->sem);

J
Jeff Tao 已提交
345
  pthread_mutex_lock(&qset->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
346

347
  for (int32_t i = 0; i < qset->numOfQueues; ++i) {
S
Shengliang Guan 已提交
348
    if (qset->current == NULL) qset->current = qset->head;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
349
    STaosQueue *queue = qset->current;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
350 351
    if (queue) qset->current = queue->next;
    if (queue == NULL) break;
J
jtao1735 已提交
352
    if (queue->head == NULL) continue;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
353 354 355 356

    pthread_mutex_lock(&queue->mutex);

    if (queue->head) {
S
Shengliang Guan 已提交
357
      pNode = queue->head;
358
      *ppItem = pNode->item;
S
Shengliang Guan 已提交
359
      if (ahandle) *ahandle = queue->ahandle;
S
Shengliang Guan 已提交
360
      if (itemFp) *itemFp = queue->itemFp;
S
Shengliang Guan 已提交
361 362 363 364 365
      queue->head = pNode->next;
      if (queue->head == NULL) queue->tail = NULL;
      queue->numOfItems--;
      atomic_sub_fetch_32(&qset->numOfItems, 1);
      code = 1;
366
      uTrace("item:%p is read out from queue:%p, items:%d", *ppItem, queue, queue->numOfItems);
S
Shengliang Guan 已提交
367
    }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
368 369 370 371 372

    pthread_mutex_unlock(&queue->mutex);
    if (pNode) break;
  }

J
Jeff Tao 已提交
373 374
  pthread_mutex_unlock(&qset->mutex);

S
Shengliang Guan 已提交
375
  return code;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
376 377
}

378
int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahandle, FProcessItems *itemsFp) {
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
379
  STaosQueue *queue;
380
  int32_t     code = 0;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
381

382
  tsem_wait(&qset->sem);
J
Jeff Tao 已提交
383 384
  pthread_mutex_lock(&qset->mutex);

385 386
  for (int32_t i = 0; i < qset->numOfQueues; ++i) {
    if (qset->current == NULL) qset->current = qset->head;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
387
    queue = qset->current;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
388 389
    if (queue) qset->current = queue->next;
    if (queue == NULL) break;
J
jtao1735 已提交
390
    if (queue->head == NULL) continue;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
391 392 393 394

    pthread_mutex_lock(&queue->mutex);

    if (queue->head) {
395 396 397 398 399
      qall->current = queue->head;
      qall->start = queue->head;
      qall->numOfItems = queue->numOfItems;
      qall->itemSize = queue->itemSize;
      code = qall->numOfItems;
S
Shengliang Guan 已提交
400
      if (ahandle) *ahandle = queue->ahandle;
S
Shengliang Guan 已提交
401
      if (itemsFp) *itemsFp = queue->itemsFp;
S
Shengliang Guan 已提交
402

403 404 405 406
      queue->head = NULL;
      queue->tail = NULL;
      queue->numOfItems = 0;
      atomic_sub_fetch_32(&qset->numOfItems, qall->numOfItems);
407 408
      for (int32_t j = 1; j < qall->numOfItems; ++j) tsem_wait(&qset->sem);
    }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
409 410 411

    pthread_mutex_unlock(&queue->mutex);

412
    if (code != 0) break;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
413
  }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
414

J
Jeff Tao 已提交
415
  pthread_mutex_unlock(&qset->mutex);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
416 417
  return code;
}
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
418

419
int32_t taosGetQueueItemsNumber(STaosQueue *queue) {
J
Jun Li 已提交
420 421
  if (!queue) return 0;

422
  int32_t num;
J
Jun Li 已提交
423 424 425 426
  pthread_mutex_lock(&queue->mutex);
  num = queue->numOfItems;
  pthread_mutex_unlock(&queue->mutex);
  return num;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
427 428
}

429
int32_t taosGetQsetItemsNumber(STaosQset *qset) {
J
Jun Li 已提交
430 431
  if (!qset) return 0;

432
  int32_t num = 0;
J
Jun Li 已提交
433 434 435 436
  pthread_mutex_lock(&qset->mutex);
  num = qset->numOfItems;
  pthread_mutex_unlock(&qset->mutex);
  return num;
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
437
}