tqueue.h 2.8 KB
Newer Older
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

16 17
#ifndef _TD_UTIL_QUEUE_H
#define _TD_UTIL_QUEUE_H
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/*

This set of API for queue is designed specially for vnode/mnode. The main purpose is to 
consume all the items instead of one item from a queue by one single read. Also, it can 
combine multiple queues into a queue set, a consumer thread can consume a queue set via 
a single API instead of looping every queue by itself.

Notes:
1: taosOpenQueue/taosCloseQueue, taosOpenQset/taosCloseQset is NOT multi-thread safe 
2: after taosCloseQueue/taosCloseQset is called, read/write operation APIs are not safe.
3: read/write operation APIs are multi-thread safe

To remove the limitation and make this set of queue APIs multi-thread safe, REF(tref.c)
shall be used to set up the protection. 

*/

S
Shengliang Guan 已提交
40 41 42
typedef void *taos_queue;
typedef void *taos_qset;
typedef void *taos_qall;
S
Shengliang Guan 已提交
43 44
typedef void (*FProcessItem)(void *ahandle, void *pItem);
typedef void (*FProcessItems)(void *ahandle, taos_qall qall, int numOfItems);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
45

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
46
taos_queue taosOpenQueue();
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
47
void       taosCloseQueue(taos_queue);
S
Shengliang Guan 已提交
48
void       taosSetQueueFp(taos_queue, FProcessItem, FProcessItems);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
49
void      *taosAllocateQitem(int size);
S
Shengliang Guan 已提交
50 51 52
void       taosFreeQitem(void *pItem);
int        taosWriteQitem(taos_queue, void *pItem);
int        taosReadQitem(taos_queue, void **pItem);
S
Shengliang Guan 已提交
53
bool       taosQueueEmpty(taos_queue);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
54

55 56 57
taos_qall  taosAllocateQall();
void       taosFreeQall(taos_qall);
int        taosReadAllQitems(taos_queue, taos_qall);
S
Shengliang Guan 已提交
58
int        taosGetQitem(taos_qall, void **pItem);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
59 60 61 62
void       taosResetQitems(taos_qall);

taos_qset  taosOpenQset();
void       taosCloseQset();
63
void       taosQsetThreadResume(taos_qset param);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
64
int        taosAddIntoQset(taos_qset, taos_queue, void *ahandle);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
65 66 67
void       taosRemoveFromQset(taos_qset, taos_queue);
int        taosGetQueueNumber(taos_qset);

S
Shengliang Guan 已提交
68 69
int        taosReadQitemFromQset(taos_qset, void **pItem, void **ahandle, FProcessItem *);
int        taosReadAllQitemsFromQset(taos_qset, taos_qall, void **ahandle, FProcessItems *);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
70 71 72

int        taosGetQueueItemsNumber(taos_queue param);
int        taosGetQsetItemsNumber(taos_qset param);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
73 74 75 76 77

#ifdef __cplusplus
}
#endif

78
#endif /*_TD_UTIL_QUEUE_H*/
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
79 80