tworker.h 2.2 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
TD-2393  
Shengliang Guan 已提交
18

S
Shengliang Guan 已提交
19 20
#include "tqueue.h"

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

25 26 27
typedef struct SWorkerPool  SWorkerPool;
typedef struct SMWorkerPool SMWorkerPool;

28
typedef struct SWorker {
29 30 31
  int32_t      id;      // worker ID
  pthread_t    thread;  // thread
  SWorkerPool *pool;
S
TD-2393  
Shengliang Guan 已提交
32 33 34
} SWorker;

typedef struct SWorkerPool {
35 36 37
  int32_t         max;  // max number of workers
  int32_t         min;  // min number of workers
  int32_t         num;  // current number of workers
38
  taos_qset       qset;
S
Shengliang Guan 已提交
39 40
  const char     *name;
  SWorker        *workers;
S
TD-2393  
Shengliang Guan 已提交
41 42 43
  pthread_mutex_t mutex;
} SWorkerPool;

S
Shengliang Guan 已提交
44
typedef struct SMWorker {
45 46 47 48 49
  int32_t       id;      // worker id
  pthread_t     thread;  // thread
  taos_qall     qall;
  taos_qset     qset;  // queue set
  SMWorkerPool *pool;
S
Shengliang Guan 已提交
50
} SMWorker;
51

S
Shengliang Guan 已提交
52 53 54 55 56 57 58
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;
59 60 61

int32_t    tWorkerInit(SWorkerPool *pool);
void       tWorkerCleanup(SWorkerPool *pool);
S
Shengliang Guan 已提交
62
taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessItem fp);
63 64
void       tWorkerFreeQueue(SWorkerPool *pool, taos_queue queue);

S
Shengliang Guan 已提交
65 66
int32_t    tMWorkerInit(SMWorkerPool *pool);
void       tMWorkerCleanup(SMWorkerPool *pool);
S
Shengliang Guan 已提交
67
taos_queue tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessItems fp);
S
Shengliang Guan 已提交
68
void       tMWorkerFreeQueue(SMWorkerPool *pool, taos_queue queue);
S
TD-2393  
Shengliang Guan 已提交
69 70 71 72 73

#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
74
#endif /*_TD_UTIL_WORKER_H*/