tworker.h 2.4 KB
Newer Older
S
TD-2393  
Shengliang Guan 已提交
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
Shengliang Guan 已提交
16 17
#ifndef _TD_UTIL_WORKER_H_
#define _TD_UTIL_WORKER_H_
S
Shengliang Guan 已提交
18 19
#include "tqueue.h"

S
TD-2393  
Shengliang Guan 已提交
20 21 22 23
#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
24 25 26 27 28 29 30
typedef struct SQWorkerPool SQWorkerPool;
typedef struct SWWorkerPool SWWorkerPool;

typedef struct SQWorker {
  int32_t       id;      // worker ID
  pthread_t     thread;  // thread
  SQWorkerPool *pool;
S
Shengliang Guan 已提交
31
} SQWorker, SFWorker;
32

S
Shengliang Guan 已提交
33 34 35 36
typedef struct SQWorkerPool {
  int32_t         max;  // max number of workers
  int32_t         min;  // min number of workers
  int32_t         num;  // current number of workers
S
Shengliang Guan 已提交
37 38 39
  STaosQset      *qset;
  const char     *name;
  SQWorker       *workers;
S
Shengliang Guan 已提交
40
  pthread_mutex_t mutex;
S
Shengliang Guan 已提交
41
} SQWorkerPool, SFWorkerPool;
S
TD-2393  
Shengliang Guan 已提交
42

S
Shengliang Guan 已提交
43
typedef struct SWWorker {
44 45
  int32_t       id;      // worker id
  pthread_t     thread;  // thread
S
Shengliang Guan 已提交
46 47
  STaosQall    *qall;
  STaosQset    *qset;  // queue set
S
Shengliang Guan 已提交
48 49
  SWWorkerPool *pool;
} SWWorker;
50

S
Shengliang Guan 已提交
51
typedef struct SWWorkerPool {
S
Shengliang Guan 已提交
52 53
  int32_t         max;     // max number of workers
  int32_t         nextId;  // from 0 to max-1, cyclic
S
Shengliang Guan 已提交
54 55
  const char     *name;
  SWWorker       *workers;
S
Shengliang Guan 已提交
56
  pthread_mutex_t mutex;
S
Shengliang Guan 已提交
57
} SWWorkerPool;
58

S
Shengliang Guan 已提交
59 60
int32_t     tQWorkerInit(SQWorkerPool *pool);
void        tQWorkerCleanup(SQWorkerPool *pool);
S
Shengliang Guan 已提交
61
STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp);
S
Shengliang Guan 已提交
62
void        tQWorkerFreeQueue(SQWorkerPool *pool, STaosQueue *queue);
63

S
Shengliang Guan 已提交
64 65 66 67 68
int32_t     tFWorkerInit(SFWorkerPool *pool);
void        tFWorkerCleanup(SFWorkerPool *pool);
STaosQueue *tFWorkerAllocQueue(SFWorkerPool *pool, void *ahandle, FItem fp);
void        tFWorkerFreeQueue(SFWorkerPool *pool, STaosQueue *queue);

S
Shengliang Guan 已提交
69 70
int32_t     tWWorkerInit(SWWorkerPool *pool);
void        tWWorkerCleanup(SWWorkerPool *pool);
S
Shengliang Guan 已提交
71
STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp);
S
Shengliang Guan 已提交
72
void        tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue);
S
TD-2393  
Shengliang Guan 已提交
73 74 75 76 77

#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
78
#endif /*_TD_UTIL_WORKER_H_*/