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/>.
 */

S
queue  
Shengliang Guan 已提交
16 17 18
#ifndef _TD_UTIL_QUEUE_H_
#define _TD_UTIL_QUEUE_H_

S
Shengliang Guan 已提交
19
#include "os.h"
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
20 21 22 23 24

#ifdef __cplusplus
extern "C" {
#endif

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

27 28 29
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) 已提交
30 31 32
a single API instead of looping every queue by itself.

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

*/

42 43 44
typedef struct STaosQueue STaosQueue;
typedef struct STaosQset  STaosQset;
typedef struct STaosQall  STaosQall;
S
Shengliang Guan 已提交
45 46
typedef void (*FItem)(void *ahandle, void *pItem);
typedef void (*FItems)(void *ahandle, STaosQall *qall, int32_t numOfItems);
47 48 49

STaosQueue *taosOpenQueue();
void        taosCloseQueue(STaosQueue *queue);
S
Shengliang Guan 已提交
50
void        taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp);
S
queue  
Shengliang Guan 已提交
51
void       *taosAllocateQitem(int32_t size);
52 53 54 55
void        taosFreeQitem(void *pItem);
int32_t     taosWriteQitem(STaosQueue *queue, void *pItem);
int32_t     taosReadQitem(STaosQueue *queue, void **ppItem);
bool        taosQueueEmpty(STaosQueue *queue);
56
int32_t     taosQueueSize(STaosQueue *queue);
57 58 59 60 61 62 63 64 65 66 67 68 69 70

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);

S
Shengliang Guan 已提交
71 72 73
int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FItem *itemFp);
int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahandle, FItems *itemsFp);
void    taosResetQsetThread(STaosQset *qset, void *pItem);
74 75
int32_t taosGetQueueItemsNumber(STaosQueue *queue);
int32_t taosGetQsetItemsNumber(STaosQset *qset);
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
76 77 78 79 80

#ifdef __cplusplus
}
#endif

S
queue  
Shengliang Guan 已提交
81
#endif /*_TD_UTIL_QUEUE_H_*/