TDengine/include/util/tworker.h

72 lines
2.1 KiB
C
Raw Normal View History

2020-12-09 06:12:50 +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-11 02:43:25 +00:00
#ifndef _TD_UTIL_WORKER_H
#define _TD_UTIL_WORKER_H
2020-12-09 06:12:50 +00:00
2021-10-20 01:06:08 +00:00
#include "tqueue.h"
2020-12-09 06:12:50 +00:00
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SWorker {
2021-10-04 12:42:53 +00:00
int32_t id; // worker ID
pthread_t thread; // thread
2021-10-04 12:42:53 +00:00
struct SWorkerPool *pool;
2020-12-09 06:12:50 +00:00
} SWorker;
typedef struct SWorkerPool {
2021-10-04 12:42:53 +00:00
int32_t max; // max number of workers
int32_t min; // min number of workers
int32_t num; // current number of workers
taos_qset qset;
2021-10-29 09:11:15 +00:00
const char *name;
SWorker *workers;
2020-12-09 06:12:50 +00:00
pthread_mutex_t mutex;
} SWorkerPool;
2021-10-29 09:11:15 +00:00
typedef struct SMWorker {
int32_t id; // worker id
pthread_t thread; // thread
taos_qall qall;
taos_qset qset; // queue set
struct SMWorkerPool *pool;
} SMWorker;
2021-10-29 09:11:15 +00:00
typedef struct SMWorkerPool {
int32_t max; // max number of workers
int32_t nextId; // from 0 to max-1, cyclic
const char *name;
SMWorker *workers;
pthread_mutex_t mutex;
} SMWorkerPool;
int32_t tWorkerInit(SWorkerPool *pool);
void tWorkerCleanup(SWorkerPool *pool);
2021-11-01 11:49:44 +00:00
taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessItem fp);
void tWorkerFreeQueue(SWorkerPool *pool, taos_queue queue);
2021-10-29 09:11:15 +00:00
int32_t tMWorkerInit(SMWorkerPool *pool);
void tMWorkerCleanup(SMWorkerPool *pool);
2021-11-01 11:49:44 +00:00
taos_queue tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessItems fp);
2021-10-29 09:11:15 +00:00
void tMWorkerFreeQueue(SMWorkerPool *pool, taos_queue queue);
2020-12-09 06:12:50 +00:00
#ifdef __cplusplus
}
#endif
2021-10-11 02:43:25 +00:00
#endif /*_TD_UTIL_WORKER_H*/