tqueue.h 3.0 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
S
Shengliang Guan 已提交
18
#include "os.h"
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
19 20 21 22 23

#ifdef __cplusplus
extern "C" {
#endif

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
24 25
/*

26 27 28
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
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
29 30 31
a single API instead of looping every queue by itself.

Notes:
32
1: taosOpenQueue/taosCloseQueue, taosOpenQset/taosCloseQset is NOT multi-thread safe
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
33 34 35 36
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)
37
shall be used to set up the protection.
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
38 39 40

*/

41 42 43
typedef struct STaosQueue STaosQueue;
typedef struct STaosQset  STaosQset;
typedef struct STaosQall  STaosQall;
S
Shengliang Guan 已提交
44
typedef void (*FProcessItem)(void *ahandle, void *pItem);
45 46 47 48 49 50 51 52 53 54
typedef void (*FProcessItems)(void *ahandle, STaosQall *qall, int32_t numOfItems);

STaosQueue *taosOpenQueue();
void        taosCloseQueue(STaosQueue *queue);
void        taosSetQueueFp(STaosQueue *queue, FProcessItem itemFp, FProcessItems itemsFp);
void       *taosAllocateQitem(int32_t size);
void        taosFreeQitem(void *pItem);
int32_t     taosWriteQitem(STaosQueue *queue, void *pItem);
int32_t     taosReadQitem(STaosQueue *queue, void **ppItem);
bool        taosQueueEmpty(STaosQueue *queue);
55
int32_t     taosQueueSize(STaosQueue *queue);
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

STaosQall *taosAllocateQall();
void       taosFreeQall(STaosQall *qall);
int32_t    taosReadAllQitems(STaosQueue *queue, STaosQall *qall);
int32_t    taosGetQitem(STaosQall *qall, void **ppItem);
void       taosResetQitems(STaosQall *qall);

STaosQset *taosOpenQset();
void       taosCloseQset(STaosQset *qset);
void       taosQsetThreadResume(STaosQset *qset);
int32_t    taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle);
void       taosRemoveFromQset(STaosQset *qset, STaosQueue *queue);
int32_t    taosGetQueueNumber(STaosQset *qset);

int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FProcessItem *itemFp);
int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahandle, FProcessItems *itemsFp);

int32_t taosGetQueueItemsNumber(STaosQueue *queue);
int32_t taosGetQsetItemsNumber(STaosQset *qset);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
75 76 77 78 79

#ifdef __cplusplus
}
#endif

80
#endif /*_TD_UTIL_QUEUE_H*/