• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3647

13 Mar 2025 05:26AM UTC coverage: 25.9% (-2.5%) from 28.375%
#3647

push

travis-ci

web-flow
Merge pull request #30158 from taosdata/docs/anchor-caps-30

docs: lowercase anchors for 3.0

53974 of 285572 branches covered (18.9%)

Branch coverage included in aggregate %.

92870 of 281392 relevant lines covered (33.0%)

617448.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

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

16
#define _DEFAULT_SOURCE
17
#include "taoserror.h"
18
#include "tlog.h"
19
#include "tqueue.h"
20
#include "tutil.h"
21

22
int64_t tsQueueMemoryAllowed = 0;
23
int64_t tsQueueMemoryUsed = 0;
24

25
int64_t tsApplyMemoryAllowed = 0;
26
int64_t tsApplyMemoryUsed = 0;
27
struct STaosQueue {
28
  STaosQnode   *head;
29
  STaosQnode   *tail;
30
  STaosQueue   *next;     // for queue set
31
  STaosQset    *qset;     // for queue set
32
  void         *ahandle;  // for queue set
33
  FItem         itemFp;
34
  FItems        itemsFp;
35
  TdThreadMutex mutex;
36
  int64_t       memOfItems;
37
  int32_t       numOfItems;
38
  int64_t       threadId;
39
  int64_t       memLimit;
40
  int64_t       itemLimit;
41
};
42

43
struct STaosQset {
44
  STaosQueue   *head;
45
  STaosQueue   *current;
46
  TdThreadMutex mutex;
47
  tsem_t        sem;
48
  int32_t       numOfQueues;
49
  int32_t       numOfItems;
50
};
51

52
struct STaosQall {
53
  STaosQnode *current;
54
  STaosQnode *start;
55
  int32_t     numOfItems;
56
  int64_t     memOfItems;
57
  int32_t     unAccessedNumOfItems;
58
  int64_t     unAccessMemOfItems;
59
};
60

61
void taosSetQueueMemoryCapacity(STaosQueue *queue, int64_t cap) { queue->memLimit = cap; }
×
62
void taosSetQueueCapacity(STaosQueue *queue, int64_t size) { queue->itemLimit = size; }
×
63

64
int32_t taosOpenQueue(STaosQueue **queue) {
322✔
65
  *queue = taosMemoryCalloc(1, sizeof(STaosQueue));
322!
66
  if (*queue == NULL) {
322!
67
    return terrno;
×
68
  }
69

70
  int32_t code = taosThreadMutexInit(&(*queue)->mutex, NULL);
322✔
71
  if (code) {
322!
72
    taosMemoryFreeClear(*queue);
×
73
    return (terrno = TAOS_SYSTEM_ERROR(code));
×
74
  }
75

76
  uDebug("queue:%p is opened", queue);
322✔
77
  return 0;
322✔
78
}
79

80
void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp) {
307✔
81
  if (queue == NULL) return;
307!
82
  queue->itemFp = itemFp;
307✔
83
  queue->itemsFp = itemsFp;
307✔
84
}
85

86
void taosCloseQueue(STaosQueue *queue) {
305✔
87
  if (queue == NULL) return;
305!
88
  STaosQnode *pTemp;
89
  STaosQset  *qset;
90

91
  (void)taosThreadMutexLock(&queue->mutex);
305✔
92
  STaosQnode *pNode = queue->head;
305✔
93
  queue->head = NULL;
305✔
94
  qset = queue->qset;
305✔
95
  (void)taosThreadMutexUnlock(&queue->mutex);
305✔
96

97
  if (queue->qset) {
305✔
98
    taosRemoveFromQset(qset, queue);
120✔
99
  }
100

101
  while (pNode) {
305!
102
    pTemp = pNode;
×
103
    pNode = pNode->next;
×
104
    taosMemoryFree(pTemp);
×
105
  }
106

107
  (void)taosThreadMutexDestroy(&queue->mutex);
305✔
108
  taosMemoryFree(queue);
305!
109

110
  uDebug("queue:%p is closed", queue);
305✔
111
}
112

113
bool taosQueueEmpty(STaosQueue *queue) {
294✔
114
  if (queue == NULL) return true;
294!
115

116
  bool empty = false;
294✔
117
  (void)taosThreadMutexLock(&queue->mutex);
294✔
118
  if (queue->head == NULL && queue->tail == NULL && queue->numOfItems == 0 /*&& queue->memOfItems == 0*/) {
294!
119
    empty = true;
292✔
120
  }
121
  (void)taosThreadMutexUnlock(&queue->mutex);
294✔
122

123
  return empty;
294✔
124
}
125

126
void taosUpdateItemSize(STaosQueue *queue, int32_t items) {
3,570✔
127
  if (queue == NULL) return;
3,570!
128

129
  (void)taosThreadMutexLock(&queue->mutex);
3,570✔
130
  queue->numOfItems -= items;
3,570✔
131
  (void)taosThreadMutexUnlock(&queue->mutex);
3,570✔
132
}
133

134
int32_t taosQueueItemSize(STaosQueue *queue) {
40✔
135
  if (queue == NULL) return 0;
40!
136

137
  (void)taosThreadMutexLock(&queue->mutex);
40✔
138
  int32_t numOfItems = queue->numOfItems;
40✔
139
  (void)taosThreadMutexUnlock(&queue->mutex);
40✔
140

141
  uTrace("queue:%p, numOfItems:%d memOfItems:%" PRId64, queue, queue->numOfItems, queue->memOfItems);
40!
142
  return numOfItems;
40✔
143
}
144

145
int64_t taosQueueMemorySize(STaosQueue *queue) {
×
146
  (void)taosThreadMutexLock(&queue->mutex);
×
147
  int64_t memOfItems = queue->memOfItems;
×
148
  (void)taosThreadMutexUnlock(&queue->mutex);
×
149
  return memOfItems;
×
150
}
151

152
int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void **item) {
3,592✔
153
  int64_t alloced = -1;
3,592✔
154

155
  if (itype == RPC_QITEM) {
3,592✔
156
    alloced = atomic_add_fetch_64(&tsQueueMemoryUsed, size + dataSize);
643✔
157
    if (alloced > tsQueueMemoryAllowed) {
643!
158
      uError("failed to alloc qitem, size:%" PRId64 " alloc:%" PRId64 " allowed:%" PRId64, size + dataSize, alloced,
×
159
             tsQueueMemoryAllowed);
160
      (void)atomic_sub_fetch_64(&tsQueueMemoryUsed, size + dataSize);
×
161
      return (terrno = TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE);
×
162
    }
163
  } else if (itype == APPLY_QITEM) {
2,949✔
164
    alloced = atomic_add_fetch_64(&tsApplyMemoryUsed, size + dataSize);
20✔
165
    if (alloced > tsApplyMemoryAllowed) {
20!
166
      uDebug("failed to alloc qitem, size:%" PRId64 " alloc:%" PRId64 " allowed:%" PRId64, size + dataSize, alloced,
×
167
             tsApplyMemoryAllowed);
168
      (void)atomic_sub_fetch_64(&tsApplyMemoryUsed, size + dataSize);
×
169
      return (terrno = TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE);
×
170
    }
171
  }
172

173
  *item = NULL;
3,592✔
174
  STaosQnode *pNode = taosMemoryCalloc(1, sizeof(STaosQnode) + size);
3,592!
175
  if (pNode == NULL) {
3,592!
176
    if (itype == RPC_QITEM) {
×
177
      (void)atomic_sub_fetch_64(&tsQueueMemoryUsed, size + dataSize);
×
178
    } else if (itype == APPLY_QITEM) {
×
179
      (void)atomic_sub_fetch_64(&tsApplyMemoryUsed, size + dataSize);
×
180
    }
181
    return terrno;
×
182
  }
183

184
  pNode->dataSize = dataSize;
3,592✔
185
  pNode->size = size;
3,592✔
186
  pNode->itype = itype;
3,592✔
187
  pNode->timestamp = taosGetTimestampUs();
3,592✔
188
  uTrace("item:%p, node:%p is allocated, alloc:%" PRId64, pNode->item, pNode, alloced);
3,592!
189
  *item = pNode->item;
3,592✔
190
  return 0;
3,592✔
191
}
192

193
void taosFreeQitem(void *pItem) {
3,592✔
194
  if (pItem == NULL) return;
3,592!
195

196
  STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode));
3,592✔
197
  int64_t     alloced = -1;
3,592✔
198
  if (pNode->itype == RPC_QITEM) {
3,592✔
199
    alloced = atomic_sub_fetch_64(&tsQueueMemoryUsed, pNode->size + pNode->dataSize);
643✔
200
  } else if (pNode->itype == APPLY_QITEM) {
2,949✔
201
    alloced = atomic_sub_fetch_64(&tsApplyMemoryUsed, pNode->size + pNode->dataSize);
20✔
202
  }
203
  uTrace("item:%p, node:%p is freed, alloc:%" PRId64, pItem, pNode, alloced);
3,592!
204

205
  taosMemoryFree(pNode);
3,592!
206
}
207

208
int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
3,575✔
209
  int32_t     code = 0;
3,575✔
210
  STaosQnode *pNode = (STaosQnode *)(((char *)pItem) - sizeof(STaosQnode));
3,575✔
211
  pNode->timestamp = taosGetTimestampUs();
3,575✔
212
  pNode->next = NULL;
3,575✔
213

214
  (void)taosThreadMutexLock(&queue->mutex);
3,575✔
215
  if (queue->memLimit > 0 && (queue->memOfItems + pNode->size + pNode->dataSize) > queue->memLimit) {
3,575!
216
    code = TSDB_CODE_UTIL_QUEUE_OUT_OF_MEMORY;
×
217
    uError("item:%p, failed to put into queue:%p, queue mem limit:%" PRId64 ", reason:%s" PRId64, pItem, queue,
×
218
           queue->memLimit, tstrerror(code));
219

220
    (void)taosThreadMutexUnlock(&queue->mutex);
×
221
    return code;
×
222
  } else if (queue->itemLimit > 0 && queue->numOfItems + 1 > queue->itemLimit) {
3,575!
223
    code = TSDB_CODE_UTIL_QUEUE_OUT_OF_MEMORY;
×
224
    uError("item:%p, failed to put into queue:%p, queue size limit:%" PRId64 ", reason:%s" PRId64, pItem, queue,
×
225
           queue->itemLimit, tstrerror(code));
226
    (void)taosThreadMutexUnlock(&queue->mutex);
×
227
    return code;
×
228
  }
229

230
  if (queue->tail) {
3,575✔
231
    queue->tail->next = pNode;
69✔
232
    queue->tail = pNode;
69✔
233
  } else {
234
    queue->head = pNode;
3,506✔
235
    queue->tail = pNode;
3,506✔
236
  }
237
  queue->numOfItems++;
3,575✔
238
  queue->memOfItems += (pNode->size + pNode->dataSize);
3,575✔
239
  if (queue->qset) {
3,575✔
240
    (void)atomic_add_fetch_32(&queue->qset->numOfItems, 1);
3,570✔
241
  }
242

243
  uTrace("item:%p, is put into queue:%p, items:%d mem:%" PRId64, pItem, queue, queue->numOfItems, queue->memOfItems);
3,575!
244

245
  (void)taosThreadMutexUnlock(&queue->mutex);
3,575✔
246

247
  if (queue->qset) {
3,575✔
248
    if (tsem_post(&queue->qset->sem) != 0) {
3,570!
249
      uError("failed to post semaphore for queue set:%p", queue->qset);
×
250
    }
251
  }
252
  return code;
3,575✔
253
}
254

255
void taosReadQitem(STaosQueue *queue, void **ppItem) {
1,376✔
256
  STaosQnode *pNode = NULL;
1,376✔
257

258
  (void)taosThreadMutexLock(&queue->mutex);
1,376✔
259

260
  if (queue->head) {
1,376✔
261
    pNode = queue->head;
5✔
262
    *ppItem = pNode->item;
5✔
263
    queue->head = pNode->next;
5✔
264
    if (queue->head == NULL) {
5!
265
      queue->tail = NULL;
5✔
266
    }
267
    queue->numOfItems--;
5✔
268
    queue->memOfItems -= (pNode->size + pNode->dataSize);
5✔
269
    if (queue->qset) {
5!
270
      (void)atomic_sub_fetch_32(&queue->qset->numOfItems, 1);
×
271
    }
272
    uTrace("item:%p, is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems,
5!
273
           queue->memOfItems);
274
  }
275

276
  (void)taosThreadMutexUnlock(&queue->mutex);
1,376✔
277
}
1,376✔
278

279
int32_t taosAllocateQall(STaosQall **qall) {
90✔
280
  *qall = taosMemoryCalloc(1, sizeof(STaosQall));
90!
281
  if (*qall == NULL) {
90!
282
    return terrno;
×
283
  }
284
  return 0;
90✔
285
}
286

287
void taosFreeQall(STaosQall *qall) { taosMemoryFree(qall); }
90!
288

289
int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
×
290
  int32_t numOfItems = 0;
×
291
  bool    empty;
292

293
  (void)taosThreadMutexLock(&queue->mutex);
×
294

295
  empty = queue->head == NULL;
×
296
  if (!empty) {
×
297
    memset(qall, 0, sizeof(STaosQall));
×
298
    qall->current = queue->head;
×
299
    qall->start = queue->head;
×
300
    qall->numOfItems = queue->numOfItems;
×
301
    qall->memOfItems = queue->memOfItems;
×
302

303
    qall->unAccessedNumOfItems = queue->numOfItems;
×
304
    qall->unAccessMemOfItems = queue->memOfItems;
×
305

306
    numOfItems = qall->numOfItems;
×
307

308
    queue->head = NULL;
×
309
    queue->tail = NULL;
×
310
    queue->numOfItems = 0;
×
311
    queue->memOfItems = 0;
×
312
    uTrace("read %d items from queue:%p, items:%d mem:%" PRId64, numOfItems, queue, queue->numOfItems,
×
313
           queue->memOfItems);
314
    if (queue->qset) {
×
315
      (void)atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems);
×
316
    }
317
  }
318

319
  (void)taosThreadMutexUnlock(&queue->mutex);
×
320

321
  // if source queue is empty, we set destination qall to empty too.
322
  if (empty) {
×
323
    qall->current = NULL;
×
324
    qall->start = NULL;
×
325
    qall->numOfItems = 0;
×
326
  }
327
  return numOfItems;
×
328
}
329

330
int32_t taosGetQitem(STaosQall *qall, void **ppItem) {
77✔
331
  STaosQnode *pNode;
332
  int32_t     num = 0;
77✔
333

334
  pNode = qall->current;
77✔
335
  if (pNode) qall->current = pNode->next;
77!
336

337
  if (pNode) {
77!
338
    *ppItem = pNode->item;
77✔
339
    num = 1;
77✔
340

341
    qall->unAccessedNumOfItems -= 1;
77✔
342
    qall->unAccessMemOfItems -= pNode->dataSize;
77✔
343

344
    uTrace("item:%p, is fetched", *ppItem);
77!
345
  } else {
346
    *ppItem = NULL;
×
347
  }
348

349
  return num;
77✔
350
}
351

352
int32_t taosOpenQset(STaosQset **qset) {
221✔
353
  *qset = taosMemoryCalloc(sizeof(STaosQset), 1);
221!
354
  if (*qset == NULL) {
221!
355
    return terrno;
×
356
  }
357

358
  (void)taosThreadMutexInit(&(*qset)->mutex, NULL);
221✔
359
  if (tsem_init(&(*qset)->sem, 0, 0) != 0) {
221!
360
    taosMemoryFree(*qset);
×
361
    return terrno;
×
362
  }
363

364
  uDebug("qset:%p, is opened", qset);
221✔
365
  return 0;
221✔
366
}
367

368
void taosCloseQset(STaosQset *qset) {
221✔
369
  if (qset == NULL) return;
221!
370

371
  // remove all the queues from qset
372
  (void)taosThreadMutexLock(&qset->mutex);
221✔
373
  while (qset->head) {
408✔
374
    STaosQueue *queue = qset->head;
187✔
375
    qset->head = qset->head->next;
187✔
376

377
    queue->qset = NULL;
187✔
378
    queue->next = NULL;
187✔
379
  }
380
  (void)taosThreadMutexUnlock(&qset->mutex);
221✔
381

382
  (void)taosThreadMutexDestroy(&qset->mutex);
221✔
383
  if (tsem_destroy(&qset->sem) != 0) {
221!
384
    uError("failed to destroy semaphore for qset:%p", qset);
×
385
  }
386
  taosMemoryFree(qset);
221!
387
  uDebug("qset:%p, is closed", qset);
221✔
388
}
389

390
// tsem_post 'qset->sem', so that reader threads waiting for it
391
// resumes execution and return, should only be used to signal the
392
// thread to exit.
393
void taosQsetThreadResume(STaosQset *qset) {
1,242✔
394
  uDebug("qset:%p, it will exit", qset);
1,242✔
395
  if (tsem_post(&qset->sem) != 0) {
1,242!
396
    uError("failed to post semaphore for qset:%p", qset);
×
397
  }
398
}
1,242✔
399

400
int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) {
307✔
401
  if (queue->qset) return TSDB_CODE_INVALID_PARA;
307!
402

403
  (void)taosThreadMutexLock(&qset->mutex);
307✔
404

405
  queue->next = qset->head;
307✔
406
  queue->ahandle = ahandle;
307✔
407
  qset->head = queue;
307✔
408
  qset->numOfQueues++;
307✔
409

410
  (void)taosThreadMutexLock(&queue->mutex);
307✔
411
  (void)atomic_add_fetch_32(&qset->numOfItems, queue->numOfItems);
307✔
412
  queue->qset = qset;
307✔
413
  (void)taosThreadMutexUnlock(&queue->mutex);
307✔
414

415
  (void)taosThreadMutexUnlock(&qset->mutex);
307✔
416

417
  uTrace("queue:%p, is added into qset:%p", queue, qset);
307!
418
  return 0;
307✔
419
}
420

421
void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) {
120✔
422
  STaosQueue *tqueue = NULL;
120✔
423

424
  (void)taosThreadMutexLock(&qset->mutex);
120✔
425

426
  if (qset->head) {
120!
427
    if (qset->head == queue) {
120✔
428
      qset->head = qset->head->next;
95✔
429
      tqueue = queue;
95✔
430
    } else {
431
      STaosQueue *prev = qset->head;
25✔
432
      tqueue = qset->head->next;
25✔
433
      while (tqueue) {
25!
434
        if (tqueue == queue) {
25!
435
          prev->next = tqueue->next;
25✔
436
          break;
25✔
437
        } else {
438
          prev = tqueue;
×
439
          tqueue = tqueue->next;
×
440
        }
441
      }
442
    }
443

444
    if (tqueue) {
120!
445
      if (qset->current == queue) qset->current = tqueue->next;
120✔
446
      qset->numOfQueues--;
120✔
447

448
      (void)taosThreadMutexLock(&queue->mutex);
120✔
449
      (void)atomic_sub_fetch_32(&qset->numOfItems, queue->numOfItems);
120✔
450
      queue->qset = NULL;
120✔
451
      queue->next = NULL;
120✔
452
      (void)taosThreadMutexUnlock(&queue->mutex);
120✔
453
    }
454
  }
455

456
  (void)taosThreadMutexUnlock(&qset->mutex);
120✔
457

458
  uDebug("queue:%p, is removed from qset:%p", queue, qset);
120!
459
}
120✔
460

461
int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) {
4,645✔
462
  STaosQnode *pNode = NULL;
4,645✔
463
  int32_t     code = 0;
4,645✔
464

465
  if (tsem_wait(&qset->sem) != 0) {
4,645!
466
    uError("failed to wait semaphore for qset:%p", qset);
×
467
  }
468

469
  (void)taosThreadMutexLock(&qset->mutex);
4,632✔
470

471
  for (int32_t i = 0; i < qset->numOfQueues; ++i) {
5,764✔
472
    if (qset->current == NULL) qset->current = qset->head;
4,612✔
473
    STaosQueue *queue = qset->current;
4,612✔
474
    if (queue) qset->current = queue->next;
4,612!
475
    if (queue == NULL) break;
4,612!
476
    if (queue->head == NULL) continue;
4,612✔
477

478
    (void)taosThreadMutexLock(&queue->mutex);
3,493✔
479

480
    if (queue->head) {
3,493!
481
      pNode = queue->head;
3,493✔
482
      *ppItem = pNode->item;
3,493✔
483
      qinfo->ahandle = queue->ahandle;
3,493✔
484
      qinfo->fp = queue->itemFp;
3,493✔
485
      qinfo->queue = queue;
3,493✔
486
      qinfo->timestamp = pNode->timestamp;
3,493✔
487

488
      queue->head = pNode->next;
3,493✔
489
      if (queue->head == NULL) queue->tail = NULL;
3,493✔
490
      // queue->numOfItems--;
491
      queue->memOfItems -= (pNode->size + pNode->dataSize);
3,493✔
492
      (void)atomic_sub_fetch_32(&qset->numOfItems, 1);
3,493✔
493
      code = 1;
3,493✔
494
      uTrace("item:%p, is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems - 1,
3,493!
495
             queue->memOfItems);
496
    }
497

498
    (void)taosThreadMutexUnlock(&queue->mutex);
3,493✔
499
    if (pNode) break;
3,493!
500
  }
501

502
  (void)taosThreadMutexUnlock(&qset->mutex);
4,645✔
503

504
  return code;
4,643✔
505
}
506

507
int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo *qinfo) {
167✔
508
  STaosQueue *queue;
509
  int32_t     code = 0;
167✔
510

511
  if (tsem_wait(&qset->sem) != 0) {
167!
512
    uError("failed to wait semaphore for qset:%p", qset);
×
513
  }
514
  (void)taosThreadMutexLock(&qset->mutex);
167✔
515

516
  for (int32_t i = 0; i < qset->numOfQueues; ++i) {
247✔
517
    if (qset->current == NULL) qset->current = qset->head;
157!
518
    queue = qset->current;
157✔
519
    if (queue) qset->current = queue->next;
157!
520
    if (queue == NULL) break;
157!
521
    if (queue->head == NULL) continue;
157✔
522

523
    (void)taosThreadMutexLock(&queue->mutex);
77✔
524

525
    if (queue->head) {
77!
526
      qall->current = queue->head;
77✔
527
      qall->start = queue->head;
77✔
528
      qall->numOfItems = queue->numOfItems;
77✔
529
      qall->memOfItems = queue->memOfItems;
77✔
530
      qall->unAccessedNumOfItems = queue->numOfItems;
77✔
531
      qall->unAccessMemOfItems = queue->memOfItems;
77✔
532

533
      code = qall->numOfItems;
77✔
534
      qinfo->ahandle = queue->ahandle;
77✔
535
      qinfo->fp = queue->itemsFp;
77✔
536
      qinfo->queue = queue;
77✔
537
      qinfo->timestamp = queue->head->timestamp;
77✔
538

539
      queue->head = NULL;
77✔
540
      queue->tail = NULL;
77✔
541
      // queue->numOfItems = 0;
542
      queue->memOfItems = 0;
77✔
543
      uTrace("read %d items from queue:%p, items:0 mem:%" PRId64, code, queue, queue->memOfItems);
77!
544

545
      (void)atomic_sub_fetch_32(&qset->numOfItems, qall->numOfItems);
77✔
546
      for (int32_t j = 1; j < qall->numOfItems; ++j) {
77!
547
        if (tsem_wait(&qset->sem) != 0) {
×
548
          uError("failed to wait semaphore for qset:%p", qset);
×
549
        }
550
      }
551
    }
552

553
    (void)taosThreadMutexUnlock(&queue->mutex);
77✔
554

555
    if (code != 0) break;
77!
556
  }
557

558
  (void)taosThreadMutexUnlock(&qset->mutex);
167✔
559
  return code;
167✔
560
}
561

562
int32_t taosQallItemSize(STaosQall *qall) { return qall->numOfItems; }
×
563
int64_t taosQallMemSize(STaosQall *qall) { return qall->memOfItems; }
×
564

565
int64_t taosQallUnAccessedItemSize(STaosQall *qall) { return qall->unAccessedNumOfItems; }
×
566
int64_t taosQallUnAccessedMemSize(STaosQall *qall) { return qall->unAccessMemOfItems; }
×
567

568
void    taosResetQitems(STaosQall *qall) { qall->current = qall->start; }
×
569
int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; }
40✔
570

571
void taosQueueSetThreadId(STaosQueue *pQueue, int64_t threadId) { pQueue->threadId = threadId; }
140✔
572

573
int64_t taosQueueGetThreadId(STaosQueue *pQueue) { return pQueue->threadId; }
240✔
574

575
#if 0
576

577
void taosResetQsetThread(STaosQset *qset, void *pItem) {
578
  if (pItem == NULL) return;
579
  STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode));
580

581
  (void)taosThreadMutexLock(&qset->mutex);
582
  for (int32_t i = 0; i < pNode->queue->numOfItems; ++i) {
583
    tsem_post(&qset->sem);
584
  }
585
  (void)taosThreadMutexUnlock(&qset->mutex);
586
}
587

588
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc