TDengine/include/util/tqueue.h

80 lines
2.7 KiB
C
Raw Normal View History

2020-02-25 07:26:29 +00:00
/*
* 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/>.
*/
2021-10-04 12:42:53 +00:00
#ifndef _TD_UTIL_QUEUE_H
#define _TD_UTIL_QUEUE_H
2020-02-25 07:26:29 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2020-11-10 13:00:31 +00:00
/*
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.
*/
2021-10-29 09:11:15 +00:00
typedef void *taos_queue;
typedef void *taos_qset;
typedef void *taos_qall;
2021-11-01 11:49:44 +00:00
typedef void *(*FProcessItem)(void *pItem, void *ahandle);
typedef void *(*FProcessItems)(taos_qall qall, int numOfItems, void *ahandle);
2020-02-25 07:26:29 +00:00
2020-03-15 05:44:07 +00:00
taos_queue taosOpenQueue();
2020-03-07 14:57:25 +00:00
void taosCloseQueue(taos_queue);
2021-11-01 11:49:44 +00:00
void taosSetQueueFp(taos_queue, FProcessItem, FProcessItems);
2020-03-15 05:44:07 +00:00
void *taosAllocateQitem(int size);
2021-10-29 09:11:15 +00:00
void taosFreeQitem(void *pItem);
int taosWriteQitem(taos_queue, void *pItem);
int taosReadQitem(taos_queue, void **pItem);
2020-03-07 14:57:25 +00:00
taos_qall taosAllocateQall();
void taosFreeQall(taos_qall);
int taosReadAllQitems(taos_queue, taos_qall);
2021-10-29 09:11:15 +00:00
int taosGetQitem(taos_qall, void **pItem);
2020-03-07 14:57:25 +00:00
void taosResetQitems(taos_qall);
taos_qset taosOpenQset();
void taosCloseQset();
2020-05-20 06:02:47 +00:00
void taosQsetThreadResume(taos_qset param);
2020-03-15 05:44:07 +00:00
int taosAddIntoQset(taos_qset, taos_queue, void *ahandle);
2020-03-07 14:57:25 +00:00
void taosRemoveFromQset(taos_qset, taos_queue);
int taosGetQueueNumber(taos_qset);
2021-11-01 11:49:44 +00:00
int taosReadQitemFromQset(taos_qset, void **pItem, void **ahandle, FProcessItem *);
int taosReadAllQitemsFromQset(taos_qset, taos_qall, void **ahandle, FProcessItems *);
2020-03-07 14:57:25 +00:00
int taosGetQueueItemsNumber(taos_queue param);
int taosGetQsetItemsNumber(taos_qset param);
2020-02-25 07:26:29 +00:00
#ifdef __cplusplus
}
#endif
2021-10-04 12:42:53 +00:00
#endif /*_TD_UTIL_QUEUE_H*/
2020-03-07 14:57:25 +00:00