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
  STaosQset      *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
  int32_t       id;      // worker id
  pthread_t     thread;  // thread
47 48
  STaosQall    *qall;
  STaosQset    *qset;  // queue set
49
  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 62 63
int32_t     tWorkerInit(SWorkerPool *pool);
void        tWorkerCleanup(SWorkerPool *pool);
STaosQueue *tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessItem fp);
void        tWorkerFreeQueue(SWorkerPool *pool, STaosQueue *queue);
64

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

#ifdef __cplusplus
}
#endif

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