[TD-13759]<fix>: redefine thread api.
This commit is contained in:
parent
caf1e0e860
commit
79057240bd
|
@ -127,7 +127,7 @@ typedef struct SWal {
|
|||
int64_t lastRollSeq;
|
||||
// ctl
|
||||
int64_t refId;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
// path
|
||||
char path[WAL_PATH_LEN];
|
||||
// reusable write head
|
||||
|
|
|
@ -27,7 +27,7 @@ typedef struct {
|
|||
int32_t numOfFree;
|
||||
int32_t freeSlot;
|
||||
bool *freeList;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} id_pool_t;
|
||||
|
||||
void *taosInitIdPool(int32_t maxId);
|
||||
|
|
|
@ -57,7 +57,7 @@ typedef struct SSkipListNode {
|
|||
* @date 2017/11/12
|
||||
* the simple version of skip list.
|
||||
*
|
||||
* for multi-thread safe purpose, we employ pthread_rwlock_t to guarantee to generate
|
||||
* for multi-thread safe purpose, we employ TdThreadRwlock to guarantee to generate
|
||||
* deterministic result. Later, we will remove the lock in SkipList to further enhance the performance.
|
||||
* In this case, one should use the concurrent skip list (by using michael-scott algorithm) instead of
|
||||
* this simple version in a multi-thread environment, to achieve higher performance of read/write operations.
|
||||
|
@ -106,7 +106,7 @@ typedef struct SSkipList {
|
|||
uint32_t seed;
|
||||
__compar_fn_t comparFn;
|
||||
__sl_key_fn_t keyFn;
|
||||
pthread_rwlock_t *lock;
|
||||
TdThreadRwlock *lock;
|
||||
uint16_t len;
|
||||
uint8_t maxLevel;
|
||||
uint8_t flags;
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param);
|
||||
bool taosDestoryThread(pthread_t* pthread);
|
||||
bool taosThreadRunning(pthread_t* pthread);
|
||||
TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param);
|
||||
bool taosDestoryThread(TdThread* pthread);
|
||||
bool taosThreadRunning(TdThread* pthread);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ typedef struct SWWorkerPool SWWorkerPool;
|
|||
|
||||
typedef struct SQWorker {
|
||||
int32_t id; // worker ID
|
||||
pthread_t thread; // thread
|
||||
TdThread thread; // thread
|
||||
SQWorkerPool *pool;
|
||||
} SQWorker, SFWorker;
|
||||
|
||||
|
@ -38,12 +38,12 @@ typedef struct SQWorkerPool {
|
|||
STaosQset *qset;
|
||||
const char *name;
|
||||
SQWorker *workers;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} SQWorkerPool, SFWorkerPool;
|
||||
|
||||
typedef struct SWWorker {
|
||||
int32_t id; // worker id
|
||||
pthread_t thread; // thread
|
||||
TdThread thread; // thread
|
||||
STaosQall *qall;
|
||||
STaosQset *qset; // queue set
|
||||
SWWorkerPool *pool;
|
||||
|
@ -54,7 +54,7 @@ typedef struct SWWorkerPool {
|
|||
int32_t nextId; // from 0 to max-1, cyclic
|
||||
const char *name;
|
||||
SWWorker *workers;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} SWWorkerPool;
|
||||
|
||||
int32_t tQWorkerInit(SQWorkerPool *pool);
|
||||
|
|
|
@ -77,8 +77,8 @@ typedef struct {
|
|||
int8_t inited;
|
||||
// ctl
|
||||
int8_t threadStop;
|
||||
pthread_t thread;
|
||||
pthread_mutex_t lock; // used when app init and cleanup
|
||||
TdThread thread;
|
||||
TdThreadMutex lock; // used when app init and cleanup
|
||||
SArray* appHbMgrs; // SArray<SAppHbMgr*> one for each cluster
|
||||
FHbReqHandle reqHandle[HEARTBEAT_TYPE_MAX];
|
||||
FHbRspHandle rspHandle[HEARTBEAT_TYPE_MAX];
|
||||
|
@ -125,7 +125,7 @@ typedef struct SAppInfo {
|
|||
int32_t pid;
|
||||
int32_t numOfThreads;
|
||||
SHashObj* pInstMap;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} SAppInfo;
|
||||
|
||||
typedef struct STscObj {
|
||||
|
@ -137,7 +137,7 @@ typedef struct STscObj {
|
|||
uint32_t connId;
|
||||
int32_t connType;
|
||||
uint64_t id; // ref ID returned by taosAddRef
|
||||
pthread_mutex_t mutex; // used to protect the operation on db
|
||||
TdThreadMutex mutex; // used to protect the operation on db
|
||||
int32_t numOfReqs; // number of sqlObj bound to this connection
|
||||
SAppInstInfo* pAppInfo;
|
||||
} STscObj;
|
||||
|
|
|
@ -33,7 +33,7 @@ SAppInfo appInfo;
|
|||
int32_t clientReqRefPool = -1;
|
||||
int32_t clientConnRefPool = -1;
|
||||
|
||||
static pthread_once_t tscinit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
|
||||
volatile int32_t tscInitRes = 0;
|
||||
|
||||
static void registerRequest(SRequestObj *pRequest) {
|
||||
|
@ -114,7 +114,7 @@ void destroyTscObj(void *pObj) {
|
|||
hbDeregisterConn(pTscObj->pAppInfo->pAppHbMgr, connKey);
|
||||
atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
tscDebug("connObj 0x%" PRIx64 " destroyed, totalConn:%" PRId64, pTscObj->id, pTscObj->pAppInfo->numOfConns);
|
||||
pthread_mutex_destroy(&pTscObj->mutex);
|
||||
taosThreadMutexDestroy(&pTscObj->mutex);
|
||||
tfree(pTscObj);
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ void *createTscObj(const char *user, const char *auth, const char *db, SAppInstI
|
|||
tstrncpy(pObj->db, db, tListLen(pObj->db));
|
||||
}
|
||||
|
||||
pthread_mutex_init(&pObj->mutex, NULL);
|
||||
taosThreadMutexInit(&pObj->mutex, NULL);
|
||||
pObj->id = taosAddRef(clientConnRefPool, pObj);
|
||||
|
||||
tscDebug("connObj created, 0x%" PRIx64, pObj->id);
|
||||
|
@ -242,7 +242,7 @@ void taos_init_imp(void) {
|
|||
|
||||
// transDestroyBuffer(&conn->readBuf);
|
||||
taosGetAppName(appInfo.appName, NULL);
|
||||
pthread_mutex_init(&appInfo.mutex, NULL);
|
||||
taosThreadMutexInit(&appInfo.mutex, NULL);
|
||||
|
||||
appInfo.pid = taosGetPId();
|
||||
appInfo.startTime = taosGetTimestampMs();
|
||||
|
@ -251,7 +251,7 @@ void taos_init_imp(void) {
|
|||
}
|
||||
|
||||
int taos_init() {
|
||||
pthread_once(&tscinit, taos_init_imp);
|
||||
taosThreadOnce(&tscinit, taos_init_imp);
|
||||
return tscInitRes;
|
||||
}
|
||||
|
||||
|
@ -507,9 +507,9 @@ static setConfRet taos_set_config_imp(const char *config){
|
|||
}
|
||||
|
||||
setConfRet taos_set_config(const char *config){
|
||||
pthread_mutex_lock(&setConfMutex);
|
||||
taosThreadMutexLock(&setConfMutex);
|
||||
setConfRet ret = taos_set_config_imp(config);
|
||||
pthread_mutex_unlock(&setConfMutex);
|
||||
taosThreadMutexUnlock(&setConfMutex);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -372,7 +372,7 @@ static void *hbThreadFunc(void *param) {
|
|||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&clientHbMgr.lock);
|
||||
taosThreadMutexLock(&clientHbMgr.lock);
|
||||
|
||||
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
|
@ -423,7 +423,7 @@ static void *hbThreadFunc(void *param) {
|
|||
atomic_add_fetch_32(&pAppHbMgr->reportCnt, 1);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&clientHbMgr.lock);
|
||||
taosThreadMutexUnlock(&clientHbMgr.lock);
|
||||
|
||||
taosMsleep(HEARTBEAT_INTERVAL);
|
||||
}
|
||||
|
@ -431,15 +431,15 @@ static void *hbThreadFunc(void *param) {
|
|||
}
|
||||
|
||||
static int32_t hbCreateThread() {
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
// if (pthread_create(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
|
||||
// if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
// return -1;
|
||||
// }
|
||||
// pthread_attr_destroy(&thAttr);
|
||||
// taosThreadAttrDestroy(&thAttr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -492,15 +492,15 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&clientHbMgr.lock);
|
||||
taosThreadMutexLock(&clientHbMgr.lock);
|
||||
taosArrayPush(clientHbMgr.appHbMgrs, &pAppHbMgr);
|
||||
pthread_mutex_unlock(&clientHbMgr.lock);
|
||||
taosThreadMutexUnlock(&clientHbMgr.lock);
|
||||
|
||||
return pAppHbMgr;
|
||||
}
|
||||
|
||||
void appHbMgrCleanup(void) {
|
||||
pthread_mutex_lock(&clientHbMgr.lock);
|
||||
taosThreadMutexLock(&clientHbMgr.lock);
|
||||
|
||||
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
|
@ -511,7 +511,7 @@ void appHbMgrCleanup(void) {
|
|||
pTarget->connInfo = NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&clientHbMgr.lock);
|
||||
taosThreadMutexUnlock(&clientHbMgr.lock);
|
||||
}
|
||||
|
||||
int hbMgrInit() {
|
||||
|
@ -520,7 +520,7 @@ int hbMgrInit() {
|
|||
if (old == 1) return 0;
|
||||
|
||||
clientHbMgr.appHbMgrs = taosArrayInit(0, sizeof(void *));
|
||||
pthread_mutex_init(&clientHbMgr.lock, NULL);
|
||||
taosThreadMutexInit(&clientHbMgr.lock, NULL);
|
||||
|
||||
// init handle funcs
|
||||
hbMgrInitHandle();
|
||||
|
@ -539,10 +539,10 @@ void hbMgrCleanUp() {
|
|||
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
|
||||
if (old == 0) return;
|
||||
|
||||
pthread_mutex_lock(&clientHbMgr.lock);
|
||||
taosThreadMutexLock(&clientHbMgr.lock);
|
||||
appHbMgrCleanup();
|
||||
taosArrayDestroy(clientHbMgr.appHbMgrs);
|
||||
pthread_mutex_unlock(&clientHbMgr.lock);
|
||||
taosThreadMutexUnlock(&clientHbMgr.lock);
|
||||
|
||||
clientHbMgr.appHbMgrs = NULL;
|
||||
#endif
|
||||
|
|
|
@ -95,7 +95,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
|
|||
char* key = getClusterKey(user, secretEncrypt, ip, port);
|
||||
SAppInstInfo** pInst = NULL;
|
||||
|
||||
pthread_mutex_lock(&appInfo.mutex);
|
||||
taosThreadMutexLock(&appInfo.mutex);
|
||||
|
||||
pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
||||
SAppInstInfo* p = NULL;
|
||||
|
@ -109,7 +109,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
|
|||
pInst = &p;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&appInfo.mutex);
|
||||
taosThreadMutexUnlock(&appInfo.mutex);
|
||||
|
||||
tfree(key);
|
||||
return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst);
|
||||
|
@ -591,21 +591,21 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t
|
|||
|
||||
char* getDbOfConnection(STscObj* pObj) {
|
||||
char* p = NULL;
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
taosThreadMutexLock(&pObj->mutex);
|
||||
size_t len = strlen(pObj->db);
|
||||
if (len > 0) {
|
||||
p = strndup(pObj->db, tListLen(pObj->db));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pObj->mutex);
|
||||
taosThreadMutexUnlock(&pObj->mutex);
|
||||
return p;
|
||||
}
|
||||
|
||||
void setConnectionDB(STscObj* pTscObj, const char* db) {
|
||||
assert(db != NULL && pTscObj != NULL);
|
||||
pthread_mutex_lock(&pTscObj->mutex);
|
||||
taosThreadMutexLock(&pTscObj->mutex);
|
||||
tstrncpy(pTscObj->db, db, tListLen(pTscObj->db));
|
||||
pthread_mutex_unlock(&pTscObj->mutex);
|
||||
taosThreadMutexUnlock(&pTscObj->mutex);
|
||||
}
|
||||
|
||||
void setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp) {
|
||||
|
|
|
@ -56,7 +56,7 @@ typedef struct {
|
|||
char *file;
|
||||
SHashObj *dnodeHash;
|
||||
SArray *pDnodeEps;
|
||||
pthread_t *threadId;
|
||||
TdThread *threadId;
|
||||
SRWLatch latch;
|
||||
SDnodeWorker mgmtWorker;
|
||||
SDnodeWorker statusWorker;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndBnode.h"
|
||||
#include "dndMnode.h"
|
||||
|
@ -553,7 +554,7 @@ static void *dnodeThreadRoutine(void *param) {
|
|||
setThreadName("dnode-hb");
|
||||
|
||||
while (true) {
|
||||
pthread_testcancel();
|
||||
taosThreadTestCancel();
|
||||
taosMsleep(200);
|
||||
if (dndGetStat(pDnode) != DND_STAT_RUNNING || pMgmt->dropped) {
|
||||
continue;
|
||||
|
|
|
@ -50,7 +50,7 @@ typedef struct {
|
|||
int32_t opened;
|
||||
int32_t failed;
|
||||
int32_t threadIndex;
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
SDnode *pDnode;
|
||||
SWrapperCfg *pCfgs;
|
||||
} SVnodeThread;
|
||||
|
@ -450,20 +450,20 @@ static int32_t dndOpenVnodes(SDnode *pDnode) {
|
|||
SVnodeThread *pThread = &threads[t];
|
||||
if (pThread->vnodeNum == 0) continue;
|
||||
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (pthread_create(&pThread->thread, &thAttr, dnodeOpenVnodeFunc, pThread) != 0) {
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pThread->thread, &thAttr, dnodeOpenVnodeFunc, pThread) != 0) {
|
||||
dError("thread:%d, failed to create thread to open vnode, reason:%s", pThread->threadIndex, strerror(errno));
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
}
|
||||
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
SVnodeThread *pThread = &threads[t];
|
||||
if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) {
|
||||
pthread_join(pThread->thread, NULL);
|
||||
taosThreadJoin(pThread->thread, NULL);
|
||||
}
|
||||
free(pThread->pCfgs);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class TestServer {
|
|||
|
||||
private:
|
||||
SDnode* pDnode;
|
||||
pthread_t* threadId;
|
||||
TdThread* threadId;
|
||||
char path[PATH_MAX];
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
char firstEp[TSDB_EP_LEN];
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
void* serverLoop(void* param) {
|
||||
while (1) {
|
||||
taosMsleep(100);
|
||||
pthread_testcancel();
|
||||
taosThreadTestCancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef _TD_TSDB_DEF_H_
|
||||
#define _TD_TSDB_DEF_H_
|
||||
|
||||
#include "tsdbDBDef.h"
|
||||
#include "tmallocator.h"
|
||||
#include "meta.h"
|
||||
#include "tcompression.h"
|
||||
|
@ -27,7 +28,6 @@
|
|||
#include "ttime.h"
|
||||
|
||||
#include "tsdb.h"
|
||||
#include "tsdbDBDef.h"
|
||||
#include "tsdbCommit.h"
|
||||
#include "tsdbFS.h"
|
||||
#include "tsdbFile.h"
|
||||
|
@ -46,7 +46,7 @@ extern "C" {
|
|||
struct STsdb {
|
||||
int32_t vgId;
|
||||
bool repoLocked;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
char * path;
|
||||
STsdbCfg config;
|
||||
STsdbMemTable * mem;
|
||||
|
|
|
@ -64,7 +64,7 @@ typedef struct {
|
|||
*/
|
||||
|
||||
typedef struct {
|
||||
pthread_rwlock_t lock;
|
||||
TdThreadRwlock lock;
|
||||
|
||||
SFSStatus *cstatus; // current status
|
||||
SHashObj * metaCache; // meta cache
|
||||
|
@ -108,7 +108,7 @@ SDFileSet *tsdbFSIterNext(SFSIter *pIter);
|
|||
int tsdbLoadMetaCache(STsdb *pRepo, bool recoverMeta);
|
||||
|
||||
static FORCE_INLINE int tsdbRLockFS(STsdbFS *pFs) {
|
||||
int code = pthread_rwlock_rdlock(&(pFs->lock));
|
||||
int code = taosThreadRwlockRdlock(&(pFs->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
|
@ -117,7 +117,7 @@ static FORCE_INLINE int tsdbRLockFS(STsdbFS *pFs) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int tsdbWLockFS(STsdbFS *pFs) {
|
||||
int code = pthread_rwlock_wrlock(&(pFs->lock));
|
||||
int code = taosThreadRwlockWrlock(&(pFs->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
|
@ -126,7 +126,7 @@ static FORCE_INLINE int tsdbWLockFS(STsdbFS *pFs) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) {
|
||||
int code = pthread_rwlock_unlock(&(pFs->lock));
|
||||
int code = taosThreadRwlockUnlock(&(pFs->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
|
|
|
@ -20,7 +20,7 @@ typedef struct SSmaStat SSmaStat;
|
|||
typedef struct SSmaEnv SSmaEnv;
|
||||
|
||||
struct SSmaEnv {
|
||||
pthread_rwlock_t lock;
|
||||
TdThreadRwlock lock;
|
||||
SDiskID did;
|
||||
TDBEnv dbEnv; // TODO: If it's better to put it in smaIndex level?
|
||||
char * path; // relative path
|
||||
|
@ -51,7 +51,7 @@ static FORCE_INLINE int32_t tsdbEncodeTSmaKey(tb_uid_t tableUid, col_id_t colId,
|
|||
}
|
||||
|
||||
static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
|
||||
int code = pthread_rwlock_rdlock(&(pEnv->lock));
|
||||
int code = taosThreadRwlockRdlock(&(pEnv->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
|
@ -60,7 +60,7 @@ static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
|
||||
int code = pthread_rwlock_wrlock(&(pEnv->lock));
|
||||
int code = taosThreadRwlockWrlock(&(pEnv->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
|
@ -69,7 +69,7 @@ static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int tsdbUnLockSma(SSmaEnv *pEnv) {
|
||||
int code = pthread_rwlock_unlock(&(pEnv->lock));
|
||||
int code = taosThreadRwlockUnlock(&(pEnv->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
|
|
|
@ -48,9 +48,9 @@ typedef struct SVnodeMgr {
|
|||
// For commit
|
||||
bool stop;
|
||||
uint16_t nthreads;
|
||||
pthread_t* threads;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t hasTask;
|
||||
TdThread* threads;
|
||||
TdThreadMutex mutex;
|
||||
TdThreadCond hasTask;
|
||||
TD_DLIST(SVnodeTask) queue;
|
||||
// For vnode Mgmt
|
||||
SDnode* pDnode;
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef struct {
|
|||
|
||||
struct SMetaDB {
|
||||
#if IMPL_WITH_LOCK
|
||||
pthread_rwlock_t rwlock;
|
||||
TdThreadRwlock rwlock;
|
||||
#endif
|
||||
// DB
|
||||
DB *pTbDB;
|
||||
|
@ -317,7 +317,7 @@ static SMetaDB *metaNewDB() {
|
|||
}
|
||||
|
||||
#if IMPL_WITH_LOCK
|
||||
pthread_rwlock_init(&pDB->rwlock, NULL);
|
||||
taosThreadRwlockInit(&pDB->rwlock, NULL);
|
||||
#endif
|
||||
|
||||
return pDB;
|
||||
|
@ -326,7 +326,7 @@ static SMetaDB *metaNewDB() {
|
|||
static void metaFreeDB(SMetaDB *pDB) {
|
||||
if (pDB) {
|
||||
#if IMPL_WITH_LOCK
|
||||
pthread_rwlock_destroy(&pDB->rwlock);
|
||||
taosThreadRwlockDestroy(&pDB->rwlock);
|
||||
#endif
|
||||
free(pDB);
|
||||
}
|
||||
|
@ -965,18 +965,18 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
|
|||
|
||||
static void metaDBWLock(SMetaDB *pDB) {
|
||||
#if IMPL_WITH_LOCK
|
||||
pthread_rwlock_wrlock(&(pDB->rwlock));
|
||||
taosThreadRwlockWrlock(&(pDB->rwlock));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void metaDBRLock(SMetaDB *pDB) {
|
||||
#if IMPL_WITH_LOCK
|
||||
pthread_rwlock_rdlock(&(pDB->rwlock));
|
||||
taosThreadRwlockRdlock(&(pDB->rwlock));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void metaDBULock(SMetaDB *pDB) {
|
||||
#if IMPL_WITH_LOCK
|
||||
pthread_rwlock_unlock(&(pDB->rwlock));
|
||||
taosThreadRwlockUnlock(&(pDB->rwlock));
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
*/
|
||||
|
||||
#include <regex.h>
|
||||
#include "os.h"
|
||||
#include "tsdbDef.h"
|
||||
#include "os.h"
|
||||
|
||||
typedef enum { TSDB_TXN_TEMP_FILE = 0, TSDB_TXN_CURR_FILE } TSDB_TXN_FILE_T;
|
||||
static const char *tsdbTxnFname[] = {"current.t", "current"};
|
||||
|
@ -203,7 +203,7 @@ STsdbFS *tsdbNewFS(const STsdbCfg *pCfg) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int code = pthread_rwlock_init(&(pfs->lock), NULL);
|
||||
int code = taosThreadRwlockInit(&(pfs->lock), NULL);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
free(pfs);
|
||||
|
@ -241,7 +241,7 @@ void *tsdbFreeFS(STsdbFS *pfs) {
|
|||
taosHashCleanup(pfs->metaCache);
|
||||
pfs->metaCache = NULL;
|
||||
pfs->cstatus = tsdbFreeFSStatus(pfs->cstatus);
|
||||
pthread_rwlock_destroy(&(pfs->lock));
|
||||
taosThreadRwlockDestroy(&(pfs->lock));
|
||||
free(pfs);
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ static void tsdbCloseImpl(STsdb *pTsdb) {
|
|||
}
|
||||
|
||||
int tsdbLockRepo(STsdb *pTsdb) {
|
||||
int code = pthread_mutex_lock(&pTsdb->mutex);
|
||||
int code = taosThreadMutexLock(&pTsdb->mutex);
|
||||
if (code != 0) {
|
||||
tsdbError("vgId:%d failed to lock tsdb since %s", REPO_ID(pTsdb), strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -123,7 +123,7 @@ int tsdbLockRepo(STsdb *pTsdb) {
|
|||
int tsdbUnlockRepo(STsdb *pTsdb) {
|
||||
ASSERT(IS_REPO_LOCKED(pTsdb));
|
||||
pTsdb->repoLocked = false;
|
||||
int code = pthread_mutex_unlock(&pTsdb->mutex);
|
||||
int code = taosThreadMutexUnlock(&pTsdb->mutex);
|
||||
if (code != 0) {
|
||||
tsdbError("vgId:%d failed to unlock tsdb since %s", REPO_ID(pTsdb), strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -298,7 +298,7 @@ STsdbCfg *tsdbGetCfg(const STsdbRepo *repo) {
|
|||
}
|
||||
|
||||
int tsdbLockRepo(STsdbRepo *pRepo) {
|
||||
int code = pthread_mutex_lock(&pRepo->mutex);
|
||||
int code = taosThreadMutexLock(&pRepo->mutex);
|
||||
if (code != 0) {
|
||||
tsdbError("vgId:%d failed to lock tsdb since %s", REPO_ID(pRepo), strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -311,7 +311,7 @@ int tsdbLockRepo(STsdbRepo *pRepo) {
|
|||
int tsdbUnlockRepo(STsdbRepo *pRepo) {
|
||||
ASSERT(IS_REPO_LOCKED(pRepo));
|
||||
pRepo->repoLocked = false;
|
||||
int code = pthread_mutex_unlock(&pRepo->mutex);
|
||||
int code = taosThreadMutexUnlock(&pRepo->mutex);
|
||||
if (code != 0) {
|
||||
tsdbError("vgId:%d failed to unlock tsdb since %s", REPO_ID(pRepo), strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -388,7 +388,7 @@ int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg) {
|
|||
tsdbError("vgId:%d no config changed", REPO_ID(repo));
|
||||
}
|
||||
|
||||
int code = pthread_mutex_lock(&repo->save_mutex);
|
||||
int code = taosThreadMutexLock(&repo->save_mutex);
|
||||
if (code != 0) {
|
||||
tsdbError("vgId:%d failed to lock tsdb save config mutex since %s", REPO_ID(repo), strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -416,7 +416,7 @@ int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg) {
|
|||
|
||||
repo->config_changed = true;
|
||||
|
||||
pthread_mutex_unlock(&repo->save_mutex);
|
||||
taosThreadMutexUnlock(&repo->save_mutex);
|
||||
|
||||
// schedule a commit msg and wait for the new config applied
|
||||
tsdbSyncCommitConfig(repo);
|
||||
|
@ -690,14 +690,14 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) {
|
|||
pRepo->repoLocked = false;
|
||||
pRepo->pthread = NULL;
|
||||
|
||||
int code = pthread_mutex_init(&(pRepo->mutex), NULL);
|
||||
int code = taosThreadMutexInit(&(pRepo->mutex), NULL);
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
tsdbFreeRepo(pRepo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
code = pthread_mutex_init(&(pRepo->save_mutex), NULL);
|
||||
code = taosThreadMutexInit(&(pRepo->save_mutex), NULL);
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
tsdbFreeRepo(pRepo);
|
||||
|
@ -747,7 +747,7 @@ static void tsdbFreeRepo(STsdbRepo *pRepo) {
|
|||
// tsdbFreeMemTable(pRepo->mem);
|
||||
// tsdbFreeMemTable(pRepo->imem);
|
||||
tsem_destroy(&(pRepo->readyToCommit));
|
||||
pthread_mutex_destroy(&pRepo->mutex);
|
||||
taosThreadMutexDestroy(&pRepo->mutex);
|
||||
free(pRepo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -541,7 +541,7 @@ int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
|
|||
}
|
||||
}
|
||||
if (addNew) {
|
||||
int code = pthread_cond_signal(&pBufPool->poolNotEmpty);
|
||||
int code = taosThreadCondSignal(&pBufPool->poolNotEmpty);
|
||||
if (code != 0) {
|
||||
if (tsdbUnlockRepo(pRepo) < 0) return -1;
|
||||
tsdbError("vgId:%d failed to signal pool not empty since %s", REPO_ID(pRepo), strerror(code));
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tsdbDef.h"
|
||||
#include <tdatablock.h>
|
||||
#include "os.h"
|
||||
#include "talgo.h"
|
||||
|
@ -20,7 +21,6 @@
|
|||
#include "tdataformat.h"
|
||||
#include "texception.h"
|
||||
#include "tsdb.h"
|
||||
#include "tsdbDef.h"
|
||||
#include "tsdbFS.h"
|
||||
#include "tsdbLog.h"
|
||||
#include "tsdbReadImpl.h"
|
||||
|
|
|
@ -124,7 +124,7 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int code = pthread_rwlock_init(&(pEnv->lock), NULL);
|
||||
int code = taosThreadRwlockInit(&(pEnv->lock), NULL);
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
free(pEnv);
|
||||
|
@ -181,7 +181,7 @@ void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
|
|||
tsdbDestroySmaState(pSmaEnv->pStat);
|
||||
tfree(pSmaEnv->pStat);
|
||||
tfree(pSmaEnv->path);
|
||||
pthread_rwlock_destroy(&(pSmaEnv->lock));
|
||||
taosThreadRwlockDestroy(&(pSmaEnv->lock));
|
||||
tsdbCloseBDBEnv(pSmaEnv->dbEnv);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#define VNODE_BUF_POOL_SHARDS 3
|
||||
|
||||
struct SVBufPool {
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t hasFree;
|
||||
TdThreadMutex mutex;
|
||||
TdThreadCond hasFree;
|
||||
TD_DLIST(SVMemAllocator) free;
|
||||
TD_DLIST(SVMemAllocator) incycle;
|
||||
SVMemAllocator *inuse;
|
||||
|
|
|
@ -31,17 +31,17 @@ int vnodeInit(const SVnodeOpt *pOption) {
|
|||
// Start commit handers
|
||||
if (pOption->nthreads > 0) {
|
||||
vnodeMgr.nthreads = pOption->nthreads;
|
||||
vnodeMgr.threads = (pthread_t*)calloc(pOption->nthreads, sizeof(pthread_t));
|
||||
vnodeMgr.threads = (TdThread*)calloc(pOption->nthreads, sizeof(TdThread));
|
||||
if (vnodeMgr.threads == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_init(&(vnodeMgr.mutex), NULL);
|
||||
pthread_cond_init(&(vnodeMgr.hasTask), NULL);
|
||||
taosThreadMutexInit(&(vnodeMgr.mutex), NULL);
|
||||
taosThreadCondInit(&(vnodeMgr.hasTask), NULL);
|
||||
TD_DLIST_INIT(&(vnodeMgr.queue));
|
||||
|
||||
for (uint16_t i = 0; i < pOption->nthreads; i++) {
|
||||
pthread_create(&(vnodeMgr.threads[i]), NULL, loop, NULL);
|
||||
taosThreadCreate(&(vnodeMgr.threads[i]), NULL, loop, NULL);
|
||||
// pthread_setname_np(vnodeMgr.threads[i], "VND Commit Thread");
|
||||
}
|
||||
} else {
|
||||
|
@ -63,28 +63,28 @@ void vnodeCleanup() {
|
|||
}
|
||||
|
||||
// Stop commit handler
|
||||
pthread_mutex_lock(&(vnodeMgr.mutex));
|
||||
taosThreadMutexLock(&(vnodeMgr.mutex));
|
||||
vnodeMgr.stop = true;
|
||||
pthread_cond_broadcast(&(vnodeMgr.hasTask));
|
||||
pthread_mutex_unlock(&(vnodeMgr.mutex));
|
||||
taosThreadCondBroadcast(&(vnodeMgr.hasTask));
|
||||
taosThreadMutexUnlock(&(vnodeMgr.mutex));
|
||||
|
||||
for (uint16_t i = 0; i < vnodeMgr.nthreads; i++) {
|
||||
pthread_join(vnodeMgr.threads[i], NULL);
|
||||
taosThreadJoin(vnodeMgr.threads[i], NULL);
|
||||
}
|
||||
|
||||
tfree(vnodeMgr.threads);
|
||||
pthread_cond_destroy(&(vnodeMgr.hasTask));
|
||||
pthread_mutex_destroy(&(vnodeMgr.mutex));
|
||||
taosThreadCondDestroy(&(vnodeMgr.hasTask));
|
||||
taosThreadMutexDestroy(&(vnodeMgr.mutex));
|
||||
}
|
||||
|
||||
int vnodeScheduleTask(SVnodeTask* pTask) {
|
||||
pthread_mutex_lock(&(vnodeMgr.mutex));
|
||||
taosThreadMutexLock(&(vnodeMgr.mutex));
|
||||
|
||||
TD_DLIST_APPEND(&(vnodeMgr.queue), pTask);
|
||||
|
||||
pthread_cond_signal(&(vnodeMgr.hasTask));
|
||||
taosThreadCondSignal(&(vnodeMgr.hasTask));
|
||||
|
||||
pthread_mutex_unlock(&(vnodeMgr.mutex));
|
||||
taosThreadMutexUnlock(&(vnodeMgr.mutex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -107,15 +107,15 @@ static void* loop(void* arg) {
|
|||
|
||||
SVnodeTask* pTask;
|
||||
for (;;) {
|
||||
pthread_mutex_lock(&(vnodeMgr.mutex));
|
||||
taosThreadMutexLock(&(vnodeMgr.mutex));
|
||||
for (;;) {
|
||||
pTask = TD_DLIST_HEAD(&(vnodeMgr.queue));
|
||||
if (pTask == NULL) {
|
||||
if (vnodeMgr.stop) {
|
||||
pthread_mutex_unlock(&(vnodeMgr.mutex));
|
||||
taosThreadMutexUnlock(&(vnodeMgr.mutex));
|
||||
return NULL;
|
||||
} else {
|
||||
pthread_cond_wait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex));
|
||||
taosThreadCondWait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex));
|
||||
}
|
||||
} else {
|
||||
TD_DLIST_POP(&(vnodeMgr.queue), pTask);
|
||||
|
@ -123,7 +123,7 @@ static void* loop(void* arg) {
|
|||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(vnodeMgr.mutex));
|
||||
taosThreadMutexUnlock(&(vnodeMgr.mutex));
|
||||
|
||||
(*(pTask->execute))(pTask->arg);
|
||||
free(pTask);
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <tsdbDef.h>
|
||||
#include <taoserror.h>
|
||||
#include <tglobal.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <metaDef.h>
|
||||
#include <tmsg.h>
|
||||
#include <tsdbDef.h>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
|
|
|
@ -176,7 +176,7 @@ typedef struct SCatalogMgmt {
|
|||
SCtgQNode *tail;
|
||||
tsem_t sem;
|
||||
uint64_t qRemainNum;
|
||||
pthread_t updateThread;
|
||||
TdThread updateThread;
|
||||
SHashObj *pCluster; //key: clusterId, value: SCatalog*
|
||||
SCatalogStat stat;
|
||||
SCatalogCfg cfg;
|
||||
|
|
|
@ -2070,16 +2070,16 @@ void* ctgUpdateThreadFunc(void* param) {
|
|||
|
||||
|
||||
int32_t ctgStartUpdateThread() {
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&gCtgMgmt.updateThread, &thAttr, ctgUpdateThreadFunc, NULL) != 0) {
|
||||
if (taosThreadCreate(&gCtgMgmt.updateThread, &thAttr, ctgUpdateThreadFunc, NULL) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
CTG_ERR_RET(terrno);
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -2094,14 +2094,14 @@ TEST(multiThread, getSetRmSameDbVgroup) {
|
|||
strcpy(n.dbname, "db1");
|
||||
strcpy(n.tname, ctgTestTablename);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t thread1, thread2;
|
||||
pthread_create(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg);
|
||||
TdThread thread1, thread2;
|
||||
taosThreadCreate(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg);
|
||||
|
||||
taosSsleep(1);
|
||||
pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
|
||||
taosThreadCreate(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
|
||||
|
||||
while (true) {
|
||||
if (ctgTestDeadLoop) {
|
||||
|
@ -2146,14 +2146,14 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
|
|||
strcpy(n.dbname, "db1");
|
||||
strcpy(n.tname, ctgTestTablename);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t thread1, thread2;
|
||||
pthread_create(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg);
|
||||
TdThread thread1, thread2;
|
||||
taosThreadCreate(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg);
|
||||
|
||||
taosSsleep(1);
|
||||
pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
|
||||
taosThreadCreate(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
|
||||
|
||||
while (true) {
|
||||
if (ctgTestDeadLoop) {
|
||||
|
@ -2198,13 +2198,13 @@ TEST(multiThread, ctableMeta) {
|
|||
strcpy(n.dbname, "db1");
|
||||
strcpy(n.tname, ctgTestTablename);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t thread1, thread2;
|
||||
pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
|
||||
TdThread thread1, thread2;
|
||||
taosThreadCreate(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
|
||||
taosSsleep(1);
|
||||
pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
|
||||
taosThreadCreate(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
|
||||
|
||||
while (true) {
|
||||
if (ctgTestDeadLoop) {
|
||||
|
|
|
@ -29,7 +29,7 @@ struct SDataSinkHandle;
|
|||
|
||||
typedef struct SDataSinkManager {
|
||||
SDataSinkMgtCfg cfg;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} SDataSinkManager;
|
||||
|
||||
typedef int32_t (*FPutDataBlock)(struct SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue);
|
||||
|
|
|
@ -356,7 +356,7 @@ typedef struct SQInfo {
|
|||
STaskAttr query;
|
||||
void* pBuf; // allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables;
|
||||
|
||||
pthread_mutex_t lock; // used to synchronize the rsp/query threads
|
||||
TdThreadMutex lock; // used to synchronize the rsp/query threads
|
||||
tsem_t ready;
|
||||
int32_t dataReady; // denote if query result is ready or not
|
||||
void* rspContext; // response context
|
||||
|
|
|
@ -43,7 +43,7 @@ typedef struct SDataDispatchHandle {
|
|||
int32_t status;
|
||||
bool queryEnd;
|
||||
uint64_t useconds;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} SDataDispatchHandle;
|
||||
|
||||
static bool needCompress(const SSDataBlock* pData, const SDataBlockDescNode* pSchema) {
|
||||
|
@ -126,19 +126,19 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput,
|
|||
}
|
||||
|
||||
static int32_t updateStatus(SDataDispatchHandle* pDispatcher) {
|
||||
pthread_mutex_lock(&pDispatcher->mutex);
|
||||
taosThreadMutexLock(&pDispatcher->mutex);
|
||||
int32_t blockNums = taosQueueSize(pDispatcher->pDataBlocks);
|
||||
int32_t status = (0 == blockNums ? DS_BUF_EMPTY :
|
||||
(blockNums < pDispatcher->pManager->cfg.maxDataBlockNumPerQuery ? DS_BUF_LOW : DS_BUF_FULL));
|
||||
pDispatcher->status = status;
|
||||
pthread_mutex_unlock(&pDispatcher->mutex);
|
||||
taosThreadMutexUnlock(&pDispatcher->mutex);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int32_t getStatus(SDataDispatchHandle* pDispatcher) {
|
||||
pthread_mutex_lock(&pDispatcher->mutex);
|
||||
taosThreadMutexLock(&pDispatcher->mutex);
|
||||
int32_t status = pDispatcher->status;
|
||||
pthread_mutex_unlock(&pDispatcher->mutex);
|
||||
taosThreadMutexUnlock(&pDispatcher->mutex);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -156,10 +156,10 @@ static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput,
|
|||
|
||||
static void endPut(struct SDataSinkHandle* pHandle, uint64_t useconds) {
|
||||
SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
|
||||
pthread_mutex_lock(&pDispatcher->mutex);
|
||||
taosThreadMutexLock(&pDispatcher->mutex);
|
||||
pDispatcher->queryEnd = true;
|
||||
pDispatcher->useconds = useconds;
|
||||
pthread_mutex_unlock(&pDispatcher->mutex);
|
||||
taosThreadMutexUnlock(&pDispatcher->mutex);
|
||||
}
|
||||
|
||||
static void getDataLength(SDataSinkHandle* pHandle, int32_t* pLen, bool* pQueryEnd) {
|
||||
|
@ -191,11 +191,11 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
|
|||
pOutput->compressed = pEntry->compressed;
|
||||
tfree(pDispatcher->nextOutput.pData); // todo persistent
|
||||
pOutput->bufStatus = updateStatus(pDispatcher);
|
||||
pthread_mutex_lock(&pDispatcher->mutex);
|
||||
taosThreadMutexLock(&pDispatcher->mutex);
|
||||
pOutput->queryEnd = pDispatcher->queryEnd;
|
||||
pOutput->useconds = pDispatcher->useconds;
|
||||
pOutput->precision = pDispatcher->pSchema->precision;
|
||||
pthread_mutex_unlock(&pDispatcher->mutex);
|
||||
taosThreadMutexUnlock(&pDispatcher->mutex);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) {
|
|||
taosFreeQitem(pBuf);
|
||||
}
|
||||
taosCloseQueue(pDispatcher->pDataBlocks);
|
||||
pthread_mutex_destroy(&pDispatcher->mutex);
|
||||
taosThreadMutexDestroy(&pDispatcher->mutex);
|
||||
}
|
||||
|
||||
int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle) {
|
||||
|
@ -228,7 +228,7 @@ int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pD
|
|||
dispatcher->status = DS_BUF_EMPTY;
|
||||
dispatcher->queryEnd = false;
|
||||
dispatcher->pDataBlocks = taosOpenQueue();
|
||||
pthread_mutex_init(&dispatcher->mutex, NULL);
|
||||
taosThreadMutexInit(&dispatcher->mutex, NULL);
|
||||
if (NULL == dispatcher->pDataBlocks) {
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
|
|
|
@ -22,7 +22,7 @@ static SDataSinkManager gDataSinkManager = {0};
|
|||
|
||||
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg *cfg) {
|
||||
gDataSinkManager.cfg = *cfg;
|
||||
pthread_mutex_init(&gDataSinkManager.mutex, NULL);
|
||||
taosThreadMutexInit(&gDataSinkManager.mutex, NULL);
|
||||
return 0; // to avoid compiler eror
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "query.h"
|
||||
|
||||
typedef struct STaskMgmt {
|
||||
pthread_mutex_t lock;
|
||||
TdThreadMutex lock;
|
||||
SCacheObj *qinfoPool; // query handle pool
|
||||
int32_t vgId;
|
||||
bool closed;
|
||||
|
|
|
@ -70,7 +70,7 @@ typedef struct {
|
|||
SList *scriptEnvs; //
|
||||
int32_t mSize; // pool limit
|
||||
int32_t cSize; // current available size
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} ScriptEnvPool;
|
||||
|
||||
ScriptCtx* createScriptCtx(char *str, int8_t resType, int16_t resBytes);
|
||||
|
|
|
@ -26,7 +26,7 @@ typedef struct SFuncMgtService {
|
|||
} SFuncMgtService;
|
||||
|
||||
static SFuncMgtService gFunMgtService;
|
||||
static pthread_once_t functionHashTableInit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadOnce functionHashTableInit = PTHREAD_ONCE_INIT;
|
||||
static int32_t initFunctionCode = 0;
|
||||
|
||||
static void doInitFunctionHashTable() {
|
||||
|
@ -45,7 +45,7 @@ static void doInitFunctionHashTable() {
|
|||
}
|
||||
|
||||
int32_t fmFuncMgtInit() {
|
||||
pthread_once(&functionHashTableInit, doInitFunctionHashTable);
|
||||
taosThreadOnce(&functionHashTableInit, doInitFunctionHashTable);
|
||||
return initFunctionCode;
|
||||
}
|
||||
|
||||
|
|
|
@ -333,7 +333,7 @@ void destroyLuaEnv(lua_State *lua) {
|
|||
int32_t scriptEnvPoolInit() {
|
||||
const int size = 10; // configure or not
|
||||
pool = malloc(sizeof(ScriptEnvPool));
|
||||
pthread_mutex_init(&pool->mutex, NULL);
|
||||
taosThreadMutexInit(&pool->mutex, NULL);
|
||||
|
||||
pool->scriptEnvs = tdListNew(sizeof(ScriptEnv *));
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
@ -359,7 +359,7 @@ void scriptEnvPoolCleanup() {
|
|||
listNodeFree(pNode);
|
||||
}
|
||||
tdListFree(pool->scriptEnvs);
|
||||
pthread_mutex_destroy(&pool->mutex);
|
||||
taosThreadMutexDestroy(&pool->mutex);
|
||||
free(pool);
|
||||
}
|
||||
|
||||
|
@ -372,9 +372,9 @@ void destroyScriptEnv(ScriptEnv *pEnv) {
|
|||
ScriptEnv* getScriptEnvFromPool() {
|
||||
ScriptEnv *pEnv = NULL;
|
||||
|
||||
pthread_mutex_lock(&pool->mutex);
|
||||
taosThreadMutexLock(&pool->mutex);
|
||||
if (pool->cSize <= 0) {
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
return NULL;
|
||||
}
|
||||
SListNode *pNode = tdListPopHead(pool->scriptEnvs);
|
||||
|
@ -384,7 +384,7 @@ ScriptEnv* getScriptEnvFromPool() {
|
|||
}
|
||||
|
||||
pool->cSize--;
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
return pEnv;
|
||||
}
|
||||
|
||||
|
@ -392,11 +392,11 @@ void addScriptEnvToPool(ScriptEnv *pEnv) {
|
|||
if (pEnv == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_mutex_lock(&pool->mutex);
|
||||
taosThreadMutexLock(&pool->mutex);
|
||||
lua_settop(pEnv->lua_state, 0);
|
||||
tdListAppend(pool->scriptEnvs, (void *)(&pEnv));
|
||||
pool->cSize++;
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
}
|
||||
|
||||
bool hasBaseFuncDefinedInScript(lua_State *lua, const char *funcPrefix, int32_t len) {
|
||||
|
|
|
@ -58,7 +58,7 @@ struct SIndex {
|
|||
char* path;
|
||||
|
||||
SIndexStat stat;
|
||||
pthread_mutex_t mtx;
|
||||
TdThreadMutex mtx;
|
||||
};
|
||||
|
||||
struct SIndexOpts {
|
||||
|
|
|
@ -43,8 +43,8 @@ typedef struct IndexCache {
|
|||
int8_t type;
|
||||
uint64_t suid;
|
||||
|
||||
pthread_mutex_t mtx;
|
||||
pthread_cond_t finished;
|
||||
TdThreadMutex mtx;
|
||||
TdThreadCond finished;
|
||||
} IndexCache;
|
||||
|
||||
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
|
||||
|
|
|
@ -260,7 +260,7 @@ typedef struct Fst {
|
|||
FstMeta* meta;
|
||||
FstSlice* data; //
|
||||
FstNode* root; //
|
||||
pthread_mutex_t mtx;
|
||||
TdThreadMutex mtx;
|
||||
} Fst;
|
||||
|
||||
// refactor simple function
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef struct SIdxColInfo {
|
|||
int cVersion;
|
||||
} SIdxColInfo;
|
||||
|
||||
static pthread_once_t isInit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadOnce isInit = PTHREAD_ONCE_INIT;
|
||||
// static void indexInit();
|
||||
static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* term, SArray** result);
|
||||
|
||||
|
@ -61,7 +61,7 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* icache, Iterat
|
|||
// int32_t indexSerialKey(ICacheKey* key, char* buf);
|
||||
|
||||
int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
||||
pthread_once(&isInit, indexInit);
|
||||
taosThreadOnce(&isInit, indexInit);
|
||||
SIndex* sIdx = calloc(1, sizeof(SIndex));
|
||||
if (sIdx == NULL) {
|
||||
return -1;
|
||||
|
@ -82,7 +82,7 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
|||
sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
sIdx->cVersion = 1;
|
||||
sIdx->path = tstrdup(path);
|
||||
pthread_mutex_init(&sIdx->mtx, NULL);
|
||||
taosThreadMutexInit(&sIdx->mtx, NULL);
|
||||
*index = sIdx;
|
||||
return 0;
|
||||
#endif
|
||||
|
@ -112,7 +112,7 @@ void indexClose(SIndex* sIdx) {
|
|||
iter = taosHashIterate(sIdx->colObj, iter);
|
||||
}
|
||||
taosHashCleanup(sIdx->colObj);
|
||||
pthread_mutex_destroy(&sIdx->mtx);
|
||||
taosThreadMutexDestroy(&sIdx->mtx);
|
||||
indexTFileDestroy(sIdx->tindex);
|
||||
#endif
|
||||
free(sIdx->path);
|
||||
|
@ -140,7 +140,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
|
|||
#ifdef USE_INVERTED_INDEX
|
||||
|
||||
// TODO(yihao): reduce the lock range
|
||||
pthread_mutex_lock(&index->mtx);
|
||||
taosThreadMutexLock(&index->mtx);
|
||||
for (int i = 0; i < taosArrayGetSize(fVals); i++) {
|
||||
SIndexTerm* p = taosArrayGetP(fVals, i);
|
||||
|
||||
|
@ -154,7 +154,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
|
|||
taosHashPut(index->colObj, buf, sz, &pCache, sizeof(void*));
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&index->mtx);
|
||||
taosThreadMutexUnlock(&index->mtx);
|
||||
|
||||
for (int i = 0; i < taosArrayGetSize(fVals); i++) {
|
||||
SIndexTerm* p = taosArrayGetP(fVals, i);
|
||||
|
@ -333,10 +333,10 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
|
|||
.suid = term->suid, .colName = term->colName, .nColName = strlen(term->colName), .colType = term->colType};
|
||||
int32_t sz = indexSerialCacheKey(&key, buf);
|
||||
|
||||
pthread_mutex_lock(&sIdx->mtx);
|
||||
taosThreadMutexLock(&sIdx->mtx);
|
||||
IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz);
|
||||
cache = (pCache == NULL) ? NULL : *pCache;
|
||||
pthread_mutex_unlock(&sIdx->mtx);
|
||||
taosThreadMutexUnlock(&sIdx->mtx);
|
||||
|
||||
*result = taosArrayInit(4, sizeof(uint64_t));
|
||||
// TODO: iterator mem and tidex
|
||||
|
@ -564,10 +564,10 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
|
|||
TFileHeader* header = &reader->header;
|
||||
ICacheKey key = {.suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName)};
|
||||
|
||||
pthread_mutex_lock(&sIdx->mtx);
|
||||
taosThreadMutexLock(&sIdx->mtx);
|
||||
IndexTFile* ifile = (IndexTFile*)sIdx->tindex;
|
||||
tfileCachePut(ifile->cache, &key, reader);
|
||||
pthread_mutex_unlock(&sIdx->mtx);
|
||||
taosThreadMutexUnlock(&sIdx->mtx);
|
||||
return ret;
|
||||
END:
|
||||
if (tw != NULL) {
|
||||
|
|
|
@ -54,8 +54,8 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
|
|||
cache->suid = suid;
|
||||
cache->occupiedMem = 0;
|
||||
|
||||
pthread_mutex_init(&cache->mtx, NULL);
|
||||
pthread_cond_init(&cache->finished, NULL);
|
||||
taosThreadMutexInit(&cache->mtx, NULL);
|
||||
taosThreadCondInit(&cache->finished, NULL);
|
||||
|
||||
indexCacheRef(cache);
|
||||
return cache;
|
||||
|
@ -63,10 +63,10 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
|
|||
void indexCacheDebug(IndexCache* cache) {
|
||||
MemTable* tbl = NULL;
|
||||
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
taosThreadMutexLock(&cache->mtx);
|
||||
tbl = cache->mem;
|
||||
indexMemRef(tbl);
|
||||
pthread_mutex_unlock(&cache->mtx);
|
||||
taosThreadMutexUnlock(&cache->mtx);
|
||||
|
||||
{
|
||||
SSkipList* slt = tbl->mem;
|
||||
|
@ -85,10 +85,10 @@ void indexCacheDebug(IndexCache* cache) {
|
|||
}
|
||||
|
||||
{
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
taosThreadMutexLock(&cache->mtx);
|
||||
tbl = cache->imm;
|
||||
indexMemRef(tbl);
|
||||
pthread_mutex_unlock(&cache->mtx);
|
||||
taosThreadMutexUnlock(&cache->mtx);
|
||||
if (tbl != NULL) {
|
||||
SSkipList* slt = tbl->mem;
|
||||
SSkipListIterator* iter = tSkipListCreateIter(slt);
|
||||
|
@ -126,13 +126,13 @@ void indexCacheDestroyImm(IndexCache* cache) {
|
|||
}
|
||||
|
||||
MemTable* tbl = NULL;
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
taosThreadMutexLock(&cache->mtx);
|
||||
|
||||
tbl = cache->imm;
|
||||
cache->imm = NULL; // or throw int bg thread
|
||||
pthread_cond_broadcast(&cache->finished);
|
||||
taosThreadCondBroadcast(&cache->finished);
|
||||
|
||||
pthread_mutex_unlock(&cache->mtx);
|
||||
taosThreadMutexUnlock(&cache->mtx);
|
||||
|
||||
indexMemUnRef(tbl);
|
||||
indexMemUnRef(tbl);
|
||||
|
@ -146,8 +146,8 @@ void indexCacheDestroy(void* cache) {
|
|||
indexMemUnRef(pCache->imm);
|
||||
free(pCache->colName);
|
||||
|
||||
pthread_mutex_destroy(&pCache->mtx);
|
||||
pthread_cond_destroy(&pCache->finished);
|
||||
taosThreadMutexDestroy(&pCache->mtx);
|
||||
taosThreadCondDestroy(&pCache->finished);
|
||||
|
||||
free(pCache);
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
taosThreadMutexLock(&cache->mtx);
|
||||
|
||||
indexMemRef(cache->imm);
|
||||
|
||||
|
@ -169,7 +169,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
|
|||
iiter->next = indexCacheIteratorNext;
|
||||
iiter->getValue = indexCacheIteratorGetValue;
|
||||
|
||||
pthread_mutex_unlock(&cache->mtx);
|
||||
taosThreadMutexUnlock(&cache->mtx);
|
||||
|
||||
return iiter;
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
|
|||
break;
|
||||
} else if (cache->imm != NULL) {
|
||||
// TODO: wake up by condition variable
|
||||
pthread_cond_wait(&cache->finished, &cache->mtx);
|
||||
taosThreadCondWait(&cache->finished, &cache->mtx);
|
||||
} else {
|
||||
indexCacheRef(cache);
|
||||
cache->imm = cache->mem;
|
||||
|
@ -240,7 +240,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
|
|||
// ugly code, refactor later
|
||||
int64_t estimate = sizeof(ct) + strlen(ct->colVal);
|
||||
|
||||
pthread_mutex_lock(&pCache->mtx);
|
||||
taosThreadMutexLock(&pCache->mtx);
|
||||
pCache->occupiedMem += estimate;
|
||||
indexCacheMakeRoomForWrite(pCache);
|
||||
MemTable* tbl = pCache->mem;
|
||||
|
@ -248,7 +248,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
|
|||
tSkipListPut(tbl->mem, (char*)ct);
|
||||
indexMemUnRef(tbl);
|
||||
|
||||
pthread_mutex_unlock(&pCache->mtx);
|
||||
taosThreadMutexUnlock(&pCache->mtx);
|
||||
|
||||
indexCacheUnRef(pCache);
|
||||
return 0;
|
||||
|
@ -299,12 +299,12 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result
|
|||
IndexCache* pCache = cache;
|
||||
|
||||
MemTable *mem = NULL, *imm = NULL;
|
||||
pthread_mutex_lock(&pCache->mtx);
|
||||
taosThreadMutexLock(&pCache->mtx);
|
||||
mem = pCache->mem;
|
||||
imm = pCache->imm;
|
||||
indexMemRef(mem);
|
||||
indexMemRef(imm);
|
||||
pthread_mutex_unlock(&pCache->mtx);
|
||||
taosThreadMutexUnlock(&pCache->mtx);
|
||||
|
||||
SIndexTerm* term = query->term;
|
||||
EIndexQueryType qtype = query->qType;
|
||||
|
|
|
@ -1023,7 +1023,7 @@ Fst* fstCreate(FstSlice* slice) {
|
|||
*s = fstSliceCopy(slice, 0, FST_SLICE_LEN(slice) - 1);
|
||||
fst->data = s;
|
||||
|
||||
pthread_mutex_init(&fst->mtx, NULL);
|
||||
taosThreadMutexInit(&fst->mtx, NULL);
|
||||
return fst;
|
||||
|
||||
FST_CREAT_FAILED:
|
||||
|
@ -1037,14 +1037,14 @@ void fstDestroy(Fst* fst) {
|
|||
free(fst->meta);
|
||||
fstSliceDestroy(fst->data);
|
||||
free(fst->data);
|
||||
pthread_mutex_destroy(&fst->mtx);
|
||||
taosThreadMutexDestroy(&fst->mtx);
|
||||
}
|
||||
free(fst);
|
||||
}
|
||||
|
||||
bool fstGet(Fst* fst, FstSlice* b, Output* out) {
|
||||
// dec lock range
|
||||
// pthread_mutex_lock(&fst->mtx);
|
||||
// taosThreadMutexLock(&fst->mtx);
|
||||
FstNode* root = fstGetRoot(fst);
|
||||
Output tOut = 0;
|
||||
int32_t len;
|
||||
|
@ -1057,7 +1057,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
|
|||
uint8_t inp = data[i];
|
||||
Output res = 0;
|
||||
if (false == fstNodeFindInput(root, inp, &res)) {
|
||||
// pthread_mutex_unlock(&fst->mtx);
|
||||
// taosThreadMutexUnlock(&fst->mtx);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1068,7 +1068,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
|
|||
taosArrayPush(nodes, &root);
|
||||
}
|
||||
if (!FST_NODE_IS_FINAL(root)) {
|
||||
// pthread_mutex_unlock(&fst->mtx);
|
||||
// taosThreadMutexUnlock(&fst->mtx);
|
||||
return false;
|
||||
} else {
|
||||
tOut = tOut + FST_NODE_FINAL_OUTPUT(root);
|
||||
|
@ -1080,7 +1080,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
|
|||
}
|
||||
taosArrayDestroy(nodes);
|
||||
// fst->root = NULL;
|
||||
// pthread_mutex_unlock(&fst->mtx);
|
||||
// taosThreadMutexUnlock(&fst->mtx);
|
||||
*out = tOut;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ typedef struct SMonInfo {
|
|||
} SMonInfo;
|
||||
|
||||
typedef struct {
|
||||
pthread_mutex_t lock;
|
||||
TdThreadMutex lock;
|
||||
SArray *logs; // array of SMonLogItem
|
||||
int32_t maxLogs;
|
||||
const char *server;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
static SMonitor tsMonitor = {0};
|
||||
|
||||
void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
|
||||
pthread_mutex_lock(&tsMonitor.lock);
|
||||
taosThreadMutexLock(&tsMonitor.lock);
|
||||
int32_t size = taosArrayGetSize(tsMonitor.logs);
|
||||
if (size < tsMonitor.maxLogs) {
|
||||
SMonLogItem item = {.ts = ts, .level = level};
|
||||
|
@ -32,7 +32,7 @@ void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
|
|||
tstrncpy(pItem->content, content, MON_LOG_LEN);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&tsMonitor.lock);
|
||||
taosThreadMutexUnlock(&tsMonitor.lock);
|
||||
}
|
||||
|
||||
int32_t monInit(const SMonCfg *pCfg) {
|
||||
|
@ -48,7 +48,7 @@ int32_t monInit(const SMonCfg *pCfg) {
|
|||
tsMonitor.comp = pCfg->comp;
|
||||
tsLogFp = monRecordLog;
|
||||
tsMonitor.state.time = taosGetTimestampMs();
|
||||
pthread_mutex_init(&tsMonitor.lock, NULL);
|
||||
taosThreadMutexInit(&tsMonitor.lock, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ void monCleanup() {
|
|||
tsLogFp = NULL;
|
||||
taosArrayDestroy(tsMonitor.logs);
|
||||
tsMonitor.logs = NULL;
|
||||
pthread_mutex_destroy(&tsMonitor.lock);
|
||||
taosThreadMutexDestroy(&tsMonitor.lock);
|
||||
}
|
||||
|
||||
SMonInfo *monCreateMonitorInfo() {
|
||||
|
@ -66,10 +66,10 @@ SMonInfo *monCreateMonitorInfo() {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&tsMonitor.lock);
|
||||
taosThreadMutexLock(&tsMonitor.lock);
|
||||
pMonitor->logs = taosArrayDup(tsMonitor.logs);
|
||||
taosArrayClear(tsMonitor.logs);
|
||||
pthread_mutex_unlock(&tsMonitor.lock);
|
||||
taosThreadMutexUnlock(&tsMonitor.lock);
|
||||
|
||||
pMonitor->pJson = tjsonCreateObject();
|
||||
if (pMonitor->pJson == NULL || pMonitor->logs == NULL) {
|
||||
|
|
|
@ -266,10 +266,10 @@ static void doInitKeywordsTable(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static pthread_once_t keywordsHashTableInit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadOnce keywordsHashTableInit = PTHREAD_ONCE_INIT;
|
||||
|
||||
static int32_t tKeywordCode(const char* z, int n) {
|
||||
pthread_once(&keywordsHashTableInit, doInitKeywordsTable);
|
||||
taosThreadOnce(&keywordsHashTableInit, doInitKeywordsTable);
|
||||
|
||||
char key[512] = {0};
|
||||
if (n > tListLen(key)) { // too long token, can not be any other token type
|
||||
|
|
|
@ -1030,15 +1030,15 @@ TEST(seqTest, multithreadRand) {
|
|||
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t t1,t2,t3,t4,t5;
|
||||
pthread_create(&(t1), &thattr, queryThread, mgmt);
|
||||
pthread_create(&(t2), &thattr, readyThread, NULL);
|
||||
pthread_create(&(t3), &thattr, fetchThread, NULL);
|
||||
pthread_create(&(t4), &thattr, dropThread, NULL);
|
||||
pthread_create(&(t5), &thattr, statusThread, NULL);
|
||||
TdThread t1,t2,t3,t4,t5;
|
||||
taosThreadCreate(&(t1), &thattr, queryThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, readyThread, NULL);
|
||||
taosThreadCreate(&(t3), &thattr, fetchThread, NULL);
|
||||
taosThreadCreate(&(t4), &thattr, dropThread, NULL);
|
||||
taosThreadCreate(&(t5), &thattr, statusThread, NULL);
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
@ -1089,13 +1089,13 @@ TEST(rcTest, shortExecshortDelay) {
|
|||
tsem_init(&qwtTestQuerySem, 0, 0);
|
||||
tsem_init(&qwtTestFetchSem, 0, 0);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t t1,t2,t3,t4,t5;
|
||||
pthread_create(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
pthread_create(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
pthread_create(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
TdThread t1,t2,t3,t4,t5;
|
||||
taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
@ -1170,13 +1170,13 @@ TEST(rcTest, longExecshortDelay) {
|
|||
tsem_init(&qwtTestQuerySem, 0, 0);
|
||||
tsem_init(&qwtTestFetchSem, 0, 0);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t t1,t2,t3,t4,t5;
|
||||
pthread_create(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
pthread_create(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
pthread_create(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
TdThread t1,t2,t3,t4,t5;
|
||||
taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
@ -1253,13 +1253,13 @@ TEST(rcTest, shortExeclongDelay) {
|
|||
tsem_init(&qwtTestQuerySem, 0, 0);
|
||||
tsem_init(&qwtTestFetchSem, 0, 0);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t t1,t2,t3,t4,t5;
|
||||
pthread_create(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
pthread_create(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
pthread_create(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
TdThread t1,t2,t3,t4,t5;
|
||||
taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
@ -1332,13 +1332,13 @@ TEST(rcTest, dropTest) {
|
|||
tsem_init(&qwtTestQuerySem, 0, 0);
|
||||
tsem_init(&qwtTestFetchSem, 0, 0);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t t1,t2,t3,t4,t5;
|
||||
pthread_create(&(t1), &thattr, clientThread, mgmt);
|
||||
pthread_create(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
pthread_create(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
TdThread t1,t2,t3,t4,t5;
|
||||
taosThreadCreate(&(t1), &thattr, clientThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
|
|
@ -684,11 +684,11 @@ TEST(queryTest, normalCase) {
|
|||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t thread1;
|
||||
pthread_create(&(thread1), &thattr, schtCreateFetchRspThread, &job);
|
||||
TdThread thread1;
|
||||
taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job);
|
||||
|
||||
void *data = NULL;
|
||||
code = schedulerFetchRows(job, &data);
|
||||
|
@ -780,11 +780,11 @@ TEST(queryTest, flowCtrlCase) {
|
|||
}
|
||||
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t thread1;
|
||||
pthread_create(&(thread1), &thattr, schtCreateFetchRspThread, &job);
|
||||
TdThread thread1;
|
||||
taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job);
|
||||
|
||||
void *data = NULL;
|
||||
code = schedulerFetchRows(job, &data);
|
||||
|
@ -834,11 +834,11 @@ TEST(insertTest, normalCase) {
|
|||
schtSetPlanToString();
|
||||
schtSetAsyncSendMsgToServer();
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t thread1;
|
||||
pthread_create(&(thread1), &thattr, schtSendRsp, &insertJobRefId);
|
||||
TdThread thread1;
|
||||
taosThreadCreate(&(thread1), &thattr, schtSendRsp, &insertJobRefId);
|
||||
|
||||
SQueryResult res = {0};
|
||||
code = schedulerExecJob(mockPointer, qnodeList, &dag, &insertJobRefId, "insert into tb values(now,1)", &res);
|
||||
|
@ -851,13 +851,13 @@ TEST(insertTest, normalCase) {
|
|||
}
|
||||
|
||||
TEST(multiThread, forceFree) {
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
pthread_t thread1, thread2, thread3;
|
||||
pthread_create(&(thread1), &thattr, schtRunJobThread, NULL);
|
||||
pthread_create(&(thread2), &thattr, schtFreeJobThread, NULL);
|
||||
pthread_create(&(thread3), &thattr, schtFetchRspThread, NULL);
|
||||
TdThread thread1, thread2, thread3;
|
||||
taosThreadCreate(&(thread1), &thattr, schtRunJobThread, NULL);
|
||||
taosThreadCreate(&(thread2), &thattr, schtFreeJobThread, NULL);
|
||||
taosThreadCreate(&(thread3), &thattr, schtFetchRspThread, NULL);
|
||||
|
||||
while (true) {
|
||||
if (schtTestDeadLoop) {
|
||||
|
|
|
@ -35,7 +35,7 @@ extern "C" {
|
|||
typedef struct SSyncIO {
|
||||
STaosQueue *pMsgQ;
|
||||
STaosQset * pQset;
|
||||
pthread_t consumerTid;
|
||||
TdThread consumerTid;
|
||||
|
||||
void * serverRpc;
|
||||
void * clientRpc;
|
||||
|
|
|
@ -211,7 +211,7 @@ static int32_t syncIOStartInternal(SSyncIO *io) {
|
|||
|
||||
// start consumer thread
|
||||
{
|
||||
if (pthread_create(&io->consumerTid, NULL, syncIOConsumerFunc, io) != 0) {
|
||||
if (taosThreadCreate(&io->consumerTid, NULL, syncIOConsumerFunc, io) != 0) {
|
||||
sError("failed to create sync consumer thread since %s", strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
@ -228,7 +228,7 @@ static int32_t syncIOStartInternal(SSyncIO *io) {
|
|||
static int32_t syncIOStopInternal(SSyncIO *io) {
|
||||
int32_t ret = 0;
|
||||
atomic_store_8(&io->isStart, 0);
|
||||
pthread_join(io->consumerTid, NULL);
|
||||
taosThreadJoin(io->consumerTid, NULL);
|
||||
taosTmrCleanUp(io->timerMgr);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
struct SPCache {
|
||||
int pageSize;
|
||||
int cacheSize;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
int nFree;
|
||||
SPage *pFree;
|
||||
int nPage;
|
||||
|
@ -118,13 +118,13 @@ void tdbPCacheRelease(SPage *pPage) {
|
|||
}
|
||||
}
|
||||
|
||||
static void tdbPCacheInitLock(SPCache *pCache) { pthread_mutex_init(&(pCache->mutex), NULL); }
|
||||
static void tdbPCacheInitLock(SPCache *pCache) { taosThreadMutexInit(&(pCache->mutex), NULL); }
|
||||
|
||||
static void tdbPCacheClearLock(SPCache *pCache) { pthread_mutex_destroy(&(pCache->mutex)); }
|
||||
static void tdbPCacheClearLock(SPCache *pCache) { taosThreadMutexDestroy(&(pCache->mutex)); }
|
||||
|
||||
static void tdbPCacheLock(SPCache *pCache) { pthread_mutex_lock(&(pCache->mutex)); }
|
||||
static void tdbPCacheLock(SPCache *pCache) { taosThreadMutexLock(&(pCache->mutex)); }
|
||||
|
||||
static void tdbPCacheUnlock(SPCache *pCache) { pthread_mutex_unlock(&(pCache->mutex)); }
|
||||
static void tdbPCacheUnlock(SPCache *pCache) { taosThreadMutexUnlock(&(pCache->mutex)); }
|
||||
|
||||
static bool tdbPCacheLocked(SPCache *pCache) {
|
||||
assert(0);
|
||||
|
|
|
@ -53,7 +53,7 @@ typedef struct __attribute__((__packed__)) {
|
|||
} SPageFtr;
|
||||
|
||||
struct SPage {
|
||||
pthread_spinlock_t lock;
|
||||
TdThreadSpinlock lock;
|
||||
u8 *pData;
|
||||
int pageSize;
|
||||
SPageMethods *pPageMethods;
|
||||
|
@ -101,10 +101,10 @@ struct SPage {
|
|||
#define P_LOCK_BUSY 1
|
||||
#define P_LOCK_FAIL -1
|
||||
|
||||
#define TDB_INIT_PAGE_LOCK(pPage) pthread_spin_init(&((pPage)->lock), 0)
|
||||
#define TDB_DESTROY_PAGE_LOCK(pPage) pthread_spin_destroy(&((pPage)->lock))
|
||||
#define TDB_LOCK_PAGE(pPage) pthread_spin_lock(&((pPage)->lock))
|
||||
#define TDB_UNLOCK_PAGE(pPage) pthread_spin_unlock(&((pPage)->lock))
|
||||
#define TDB_INIT_PAGE_LOCK(pPage) taosThreadSpinInit(&((pPage)->lock), 0)
|
||||
#define TDB_DESTROY_PAGE_LOCK(pPage) taosThreadSpinDestroy(&((pPage)->lock))
|
||||
#define TDB_LOCK_PAGE(pPage) taosThreadSpinLock(&((pPage)->lock))
|
||||
#define TDB_UNLOCK_PAGE(pPage) taosThreadSpinUnlock(&((pPage)->lock))
|
||||
#define TDB_TRY_LOCK_PAGE(pPage) \
|
||||
({ \
|
||||
int ret; \
|
||||
|
|
|
@ -41,7 +41,7 @@ typedef struct {
|
|||
} STfsDisk;
|
||||
|
||||
typedef struct {
|
||||
pthread_spinlock_t lock;
|
||||
TdThreadSpinlock lock;
|
||||
int32_t level;
|
||||
int32_t nextid; // next disk id to allocate
|
||||
int32_t ndisk; // # of disks mounted to this tier
|
||||
|
@ -64,7 +64,7 @@ typedef struct STfsDir {
|
|||
} STfsDir;
|
||||
|
||||
typedef struct STfs {
|
||||
pthread_spinlock_t lock;
|
||||
TdThreadSpinlock lock;
|
||||
SDiskSize size;
|
||||
int32_t nlevel;
|
||||
STfsTier tiers[TFS_MAX_TIERS];
|
||||
|
@ -82,11 +82,11 @@ void tfsUpdateTierSize(STfsTier *pTier);
|
|||
int32_t tfsAllocDiskOnTier(STfsTier *pTier);
|
||||
void tfsPosNextId(STfsTier *pTier);
|
||||
|
||||
#define tfsLockTier(pTier) pthread_spin_lock(&(pTier)->lock)
|
||||
#define tfsUnLockTier(pTier) pthread_spin_unlock(&(pTier)->lock)
|
||||
#define tfsLockTier(pTier) taosThreadSpinLock(&(pTier)->lock)
|
||||
#define tfsUnLockTier(pTier) taosThreadSpinUnlock(&(pTier)->lock)
|
||||
|
||||
#define tfsLock(pTfs) pthread_spin_lock(&(pTfs)->lock)
|
||||
#define tfsUnLock(pTfs) pthread_spin_unlock(&(pTfs)->lock)
|
||||
#define tfsLock(pTfs) taosThreadSpinLock(&(pTfs)->lock)
|
||||
#define tfsUnLock(pTfs) taosThreadSpinUnlock(&(pTfs)->lock)
|
||||
|
||||
#define TFS_TIER_AT(pTfs, level) (&(pTfs)->tiers[level])
|
||||
#define TFS_DISK_AT(pTfs, did) ((pTfs)->tiers[(did).level].disks[(did).id])
|
||||
|
|
|
@ -36,7 +36,7 @@ STfs *tfsOpen(SDiskCfg *pCfg, int32_t ndisk) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (pthread_spin_init(&pTfs->lock, 0) != 0) {
|
||||
if (taosThreadSpinInit(&pTfs->lock, 0) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tfsClose(pTfs);
|
||||
return NULL;
|
||||
|
@ -85,7 +85,7 @@ void tfsClose(STfs *pTfs) {
|
|||
}
|
||||
|
||||
taosHashCleanup(pTfs->hash);
|
||||
pthread_spin_destroy(&pTfs->lock);
|
||||
taosThreadSpinDestroy(&pTfs->lock);
|
||||
free(pTfs);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
int32_t tfsInitTier(STfsTier *pTier, int32_t level) {
|
||||
memset(pTier, 0, sizeof(STfsTier));
|
||||
|
||||
if (pthread_spin_init(&pTier->lock, 0) != 0) {
|
||||
if (taosThreadSpinInit(&pTier->lock, 0) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ void tfsDestroyTier(STfsTier *pTier) {
|
|||
}
|
||||
|
||||
pTier->ndisk = 0;
|
||||
pthread_spin_destroy(&pTier->lock);
|
||||
taosThreadSpinDestroy(&pTier->lock);
|
||||
}
|
||||
|
||||
STfsDisk *tfsMountDiskToTier(STfsTier *pTier, SDiskCfg *pCfg) {
|
||||
|
|
|
@ -230,7 +230,7 @@ typedef void (*AsyncCB)(uv_async_t* handle);
|
|||
typedef struct {
|
||||
void* pThrd;
|
||||
queue qmsg;
|
||||
pthread_mutex_t mtx; // protect qmsg;
|
||||
TdThreadMutex mtx; // protect qmsg;
|
||||
} SAsyncItem;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -70,7 +70,7 @@ typedef struct {
|
|||
void* tmrCtrl; // handle to timer
|
||||
SHashObj* hash; // handle returned by hash utility
|
||||
void* tcphandle; // returned handle from TCP initialization
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} SRpcInfo;
|
||||
|
||||
#endif // USE_LIBUV
|
||||
|
|
|
@ -39,7 +39,7 @@ typedef struct {
|
|||
int total;
|
||||
int * count;
|
||||
int64_t keepTimer;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
void (*cleanFp)(void *);
|
||||
void * tmrCtrl;
|
||||
void * pTimer;
|
||||
|
@ -85,7 +85,7 @@ void *rpcOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl,
|
|||
pCache->lockedBy = calloc(sizeof(int64_t), maxSessions);
|
||||
taosTmrReset(rpcCleanConnCache, (int32_t)(pCache->keepTimer * 2), pCache, pCache->tmrCtrl, &pCache->pTimer);
|
||||
|
||||
pthread_mutex_init(&pCache->mutex, NULL);
|
||||
taosThreadMutexInit(&pCache->mutex, NULL);
|
||||
|
||||
return pCache;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ void rpcCloseConnCache(void *handle) {
|
|||
pCache = (SConnCache *)handle;
|
||||
if (pCache == NULL || pCache->maxSessions == 0) return;
|
||||
|
||||
pthread_mutex_lock(&pCache->mutex);
|
||||
taosThreadMutexLock(&pCache->mutex);
|
||||
|
||||
taosTmrStopA(&(pCache->pTimer));
|
||||
|
||||
|
@ -106,9 +106,9 @@ void rpcCloseConnCache(void *handle) {
|
|||
tfree(pCache->count);
|
||||
tfree(pCache->lockedBy);
|
||||
|
||||
pthread_mutex_unlock(&pCache->mutex);
|
||||
taosThreadMutexUnlock(&pCache->mutex);
|
||||
|
||||
pthread_mutex_destroy(&pCache->mutex);
|
||||
taosThreadMutexDestroy(&pCache->mutex);
|
||||
|
||||
memset(pCache, 0, sizeof(SConnCache));
|
||||
free(pCache);
|
||||
|
@ -220,7 +220,7 @@ static void rpcCleanConnCache(void *handle, void *tmrId) {
|
|||
if (pCache == NULL || pCache->maxSessions == 0) return;
|
||||
if (pCache->pTimer != tmrId) return;
|
||||
|
||||
pthread_mutex_lock(&pCache->mutex);
|
||||
taosThreadMutexLock(&pCache->mutex);
|
||||
uint64_t time = taosGetTimestampMs();
|
||||
|
||||
for (hash = 0; hash < pCache->maxSessions; ++hash) {
|
||||
|
@ -232,7 +232,7 @@ static void rpcCleanConnCache(void *handle, void *tmrId) {
|
|||
|
||||
// tTrace("timer, total connections in cache:%d", pCache->total);
|
||||
taosTmrReset(rpcCleanConnCache, (int32_t)(pCache->keepTimer * 2), pCache, pCache->tmrCtrl, &pCache->pTimer);
|
||||
pthread_mutex_unlock(&pCache->mutex);
|
||||
taosThreadMutexUnlock(&pCache->mutex);
|
||||
}
|
||||
|
||||
static void rpcRemoveExpiredNodes(SConnCache *pCache, SConnHash *pNode, int hash, uint64_t time) {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "lz4.h"
|
||||
#include "transportInt.h"
|
||||
#include "os.h"
|
||||
#include "rpcCache.h"
|
||||
#include "rpcHead.h"
|
||||
|
@ -27,13 +28,12 @@
|
|||
#include "tmd5.h"
|
||||
#include "tmempool.h"
|
||||
#include "tmsg.h"
|
||||
#include "transportInt.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
|
||||
static pthread_once_t tsRpcInitOnce = PTHREAD_ONCE_INIT;
|
||||
static TdThreadOnce tsRpcInitOnce = PTHREAD_ONCE_INIT;
|
||||
|
||||
int tsRpcMaxUdpSize = 15000; // bytes
|
||||
int tsProgressTimer = 100;
|
||||
|
@ -72,7 +72,7 @@ typedef struct {
|
|||
void * tcphandle; // returned handle from TCP initialization
|
||||
void * udphandle; // returned handle from UDP initialization
|
||||
void * pCache; // connection cache
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
struct SRpcConn *connList; // connection list
|
||||
} SRpcInfo;
|
||||
|
||||
|
@ -143,7 +143,7 @@ typedef struct SRpcConn {
|
|||
static int tsRpcRefId = -1;
|
||||
static int32_t tsRpcNum = 0;
|
||||
|
||||
// static pthread_once_t tsRpcInit = PTHREAD_ONCE_INIT;
|
||||
// static TdThreadOnce tsRpcInit = PTHREAD_ONCE_INIT;
|
||||
|
||||
// server:0 client:1 tcp:2 udp:0
|
||||
#define RPC_CONN_UDPS 0
|
||||
|
@ -223,7 +223,7 @@ static void rpcInitImp(void) {
|
|||
}
|
||||
|
||||
int32_t rpcInit() {
|
||||
pthread_once(&tsRpcInitOnce, rpcInitImp);
|
||||
taosThreadOnce(&tsRpcInitOnce, rpcInitImp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ void rpcCleanup(void) {
|
|||
void *rpcOpen(const SRpcInit *pInit) {
|
||||
SRpcInfo *pRpc;
|
||||
|
||||
// pthread_once(&tsRpcInit, rpcInit);
|
||||
// taosThreadOnce(&tsRpcInit, rpcInit);
|
||||
|
||||
pRpc = (SRpcInfo *)calloc(1, sizeof(SRpcInfo));
|
||||
if (pRpc == NULL) return NULL;
|
||||
|
@ -307,7 +307,7 @@ void *rpcOpen(const SRpcInit *pInit) {
|
|||
}
|
||||
}
|
||||
|
||||
pthread_mutex_init(&pRpc->mutex, NULL);
|
||||
taosThreadMutexInit(&pRpc->mutex, NULL);
|
||||
|
||||
pRpc->tcphandle = (*taosInitConn[pRpc->connType | RPC_CONN_TCP])(0, pRpc->localPort, pRpc->label, pRpc->numOfThreads,
|
||||
rpcProcessMsgFromPeer, pRpc);
|
||||
|
@ -1672,7 +1672,7 @@ static void rpcDecRef(SRpcInfo *pRpc) {
|
|||
taosIdPoolCleanUp(pRpc->idPool);
|
||||
|
||||
tfree(pRpc->connList);
|
||||
pthread_mutex_destroy(&pRpc->mutex);
|
||||
taosThreadMutexDestroy(&pRpc->mutex);
|
||||
tDebug("%s rpc resources are released", pRpc->label);
|
||||
tfree(pRpc);
|
||||
|
||||
|
|
|
@ -35,9 +35,9 @@ typedef struct SFdObj {
|
|||
} SFdObj;
|
||||
|
||||
typedef struct SThreadObj {
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
SFdObj * pHead;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
uint32_t ip;
|
||||
bool stop;
|
||||
TdEpollPtr pEpoll;
|
||||
|
@ -65,7 +65,7 @@ typedef struct {
|
|||
int numOfThreads;
|
||||
void * shandle;
|
||||
SThreadObj **pThreadObj;
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
} SServerObj;
|
||||
|
||||
static void * taosProcessTcpData(void *param);
|
||||
|
@ -101,9 +101,9 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
}
|
||||
|
||||
int code = 0;
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
// initialize parameters in case it may encounter error later
|
||||
for (int i = 0; i < numOfThreads; ++i) {
|
||||
|
@ -129,7 +129,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
// initialize mutex, thread, fd which may fail
|
||||
for (int i = 0; i < numOfThreads; ++i) {
|
||||
pThreadObj = pServerObj->pThreadObj[i];
|
||||
code = pthread_mutex_init(&(pThreadObj->mutex), NULL);
|
||||
code = taosThreadMutexInit(&(pThreadObj->mutex), NULL);
|
||||
if (code < 0) {
|
||||
tError("%s failed to init TCP process data mutex(%s)", label, strerror(errno));
|
||||
break;
|
||||
|
@ -142,7 +142,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
break;
|
||||
}
|
||||
|
||||
code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj));
|
||||
code = taosThreadCreate(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj));
|
||||
if (code != 0) {
|
||||
tError("%s failed to create TCP process data thread(%s)", label, strerror(errno));
|
||||
break;
|
||||
|
@ -155,7 +155,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
if (pServerObj->pSocketServer == NULL) code = -1;
|
||||
|
||||
if (code == 0) {
|
||||
code = pthread_create(&pServerObj->thread, &thattr, taosAcceptTcpConnection, (void *)pServerObj);
|
||||
code = taosThreadCreate(&pServerObj->thread, &thattr, taosAcceptTcpConnection, (void *)pServerObj);
|
||||
if (code != 0) {
|
||||
tError("%s failed to create TCP accept thread(%s)", label, strerror(code));
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
tDebug("%s TCP server is initialized, ip:0x%x port:%hu numOfThreads:%d", label, ip, port, numOfThreads);
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thattr);
|
||||
taosThreadAttrDestroy(&thattr);
|
||||
return (void *)pServerObj;
|
||||
}
|
||||
|
||||
|
@ -178,16 +178,16 @@ static void taosStopTcpThread(SThreadObj *pThreadObj) {
|
|||
return;
|
||||
}
|
||||
// save thread into local variable and signal thread to stop
|
||||
pthread_t thread = pThreadObj->thread;
|
||||
TdThread thread = pThreadObj->thread;
|
||||
if (!taosCheckPthreadValid(thread)) {
|
||||
return;
|
||||
}
|
||||
pThreadObj->stop = true;
|
||||
if (taosComparePthread(thread, pthread_self())) {
|
||||
pthread_detach(pthread_self());
|
||||
if (taosComparePthread(thread, taosThreadSelf())) {
|
||||
pthread_detach(taosThreadSelf());
|
||||
return;
|
||||
}
|
||||
pthread_join(thread, NULL);
|
||||
taosThreadJoin(thread, NULL);
|
||||
}
|
||||
|
||||
void taosStopTcpServer(void *handle) {
|
||||
|
@ -200,10 +200,10 @@ void taosStopTcpServer(void *handle) {
|
|||
taosShutDownSocketServerRD(pServerObj->pSocketServer);
|
||||
}
|
||||
if (taosCheckPthreadValid(pServerObj->thread)) {
|
||||
if (taosComparePthread(pServerObj->thread, pthread_self())) {
|
||||
pthread_detach(pthread_self());
|
||||
if (taosComparePthread(pServerObj->thread, taosThreadSelf())) {
|
||||
pthread_detach(taosThreadSelf());
|
||||
} else {
|
||||
pthread_join(pServerObj->thread, NULL);
|
||||
taosThreadJoin(pServerObj->thread, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,9 +307,9 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
}
|
||||
|
||||
int code = 0;
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
for (int i = 0; i < numOfThreads; ++i) {
|
||||
SThreadObj *pThreadObj = (SThreadObj *)calloc(1, sizeof(SThreadObj));
|
||||
|
@ -318,7 +318,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
for (int j = 0; j < i; ++j) free(pClientObj->pThreadObj[j]);
|
||||
free(pClientObj);
|
||||
pthread_attr_destroy(&thattr);
|
||||
taosThreadAttrDestroy(&thattr);
|
||||
return NULL;
|
||||
}
|
||||
pClientObj->pThreadObj[i] = pThreadObj;
|
||||
|
@ -333,7 +333,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
// initialize mutex, thread, fd which may fail
|
||||
for (int i = 0; i < numOfThreads; ++i) {
|
||||
SThreadObj *pThreadObj = pClientObj->pThreadObj[i];
|
||||
code = pthread_mutex_init(&(pThreadObj->mutex), NULL);
|
||||
code = taosThreadMutexInit(&(pThreadObj->mutex), NULL);
|
||||
if (code < 0) {
|
||||
tError("%s failed to init TCP process data mutex(%s)", label, strerror(errno));
|
||||
break;
|
||||
|
@ -346,7 +346,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
break;
|
||||
}
|
||||
|
||||
code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj));
|
||||
code = taosThreadCreate(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj));
|
||||
if (code != 0) {
|
||||
tError("%s failed to create TCP process data thread(%s)", label, strerror(errno));
|
||||
break;
|
||||
|
@ -578,7 +578,7 @@ static void *taosProcessTcpData(void *param) {
|
|||
taosReportBrokenLink(pFdObj);
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&(pThreadObj->mutex));
|
||||
taosThreadMutexDestroy(&(pThreadObj->mutex));
|
||||
tDebug("%s TCP thread exits ...", pThreadObj->label);
|
||||
tfree(pThreadObj);
|
||||
|
||||
|
@ -607,12 +607,12 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, TdSocketPtr pSocket) {
|
|||
}
|
||||
|
||||
// notify the data process, add into the FdObj list
|
||||
pthread_mutex_lock(&(pThreadObj->mutex));
|
||||
taosThreadMutexLock(&(pThreadObj->mutex));
|
||||
pFdObj->next = pThreadObj->pHead;
|
||||
if (pThreadObj->pHead) (pThreadObj->pHead)->prev = pFdObj;
|
||||
pThreadObj->pHead = pFdObj;
|
||||
pThreadObj->numOfFds++;
|
||||
pthread_mutex_unlock(&(pThreadObj->mutex));
|
||||
taosThreadMutexUnlock(&(pThreadObj->mutex));
|
||||
|
||||
return pFdObj;
|
||||
}
|
||||
|
@ -622,10 +622,10 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
|
|||
if (pFdObj->signature != pFdObj) return;
|
||||
|
||||
SThreadObj *pThreadObj = pFdObj->pThreadObj;
|
||||
pthread_mutex_lock(&pThreadObj->mutex);
|
||||
taosThreadMutexLock(&pThreadObj->mutex);
|
||||
|
||||
if (pFdObj->signature == NULL) {
|
||||
pthread_mutex_unlock(&pThreadObj->mutex);
|
||||
taosThreadMutexUnlock(&pThreadObj->mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -648,7 +648,7 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
|
|||
(pFdObj->next)->prev = pFdObj->prev;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pThreadObj->mutex);
|
||||
taosThreadMutexUnlock(&pThreadObj->mutex);
|
||||
|
||||
tDebug("%s %p TCP connection is closed, FD:%p numOfFds:%d", pThreadObj->label, pFdObj->thandle, pFdObj, pThreadObj->numOfFds);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ typedef struct {
|
|||
uint16_t port; // peer port
|
||||
uint16_t localPort; // local port
|
||||
char label[TSDB_LABEL_LEN]; // copy from udpConnSet;
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
void *hash;
|
||||
void *shandle; // handle passed by upper layer during server initialization
|
||||
void *pSet;
|
||||
|
@ -77,9 +77,9 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
|
|||
pSet->threads = threads;
|
||||
tstrncpy(pSet->label, label, sizeof(pSet->label));
|
||||
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
int i;
|
||||
uint16_t ownPort;
|
||||
|
@ -111,14 +111,14 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
|
|||
pConn->index = i;
|
||||
pConn->pSet = pSet;
|
||||
|
||||
int code = pthread_create(&pConn->thread, &thAttr, taosRecvUdpData, pConn);
|
||||
int code = taosThreadCreate(&pConn->thread, &thAttr, taosRecvUdpData, pConn);
|
||||
if (code != 0) {
|
||||
tError("%s failed to create thread to process UDP data(%s)", label, strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
||||
if (i != threads) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
@ -146,7 +146,7 @@ void taosStopUdpConnection(void *handle) {
|
|||
for (int i = 0; i < pSet->threads; ++i) {
|
||||
pConn = pSet->udpConn + i;
|
||||
if (taosCheckPthreadValid(pConn->thread)) {
|
||||
pthread_join(pConn->thread, NULL);
|
||||
taosThreadJoin(pConn->thread, NULL);
|
||||
}
|
||||
tfree(pConn->buffer);
|
||||
// tTrace("%s UDP thread is closed, index:%d", pConn->label, i);
|
||||
|
|
|
@ -14,10 +14,13 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#ifdef USE_UV
|
||||
#include <uv.h>
|
||||
#endif
|
||||
#include "zlib.h"
|
||||
#include "thttp.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
#include "zlib.h"
|
||||
|
||||
static int32_t taosBuildHttpHeader(const char* server, int32_t contLen, char* pHead, int32_t headLen,
|
||||
EHttpCompFlag flag) {
|
||||
|
@ -111,7 +114,6 @@ _OVER:
|
|||
}
|
||||
|
||||
#ifdef USE_UV
|
||||
#include <uv.h>
|
||||
static void clientConnCb(uv_connect_t* req, int32_t status) {
|
||||
if (status < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(status);
|
||||
|
|
|
@ -56,7 +56,7 @@ typedef struct SCliMsg {
|
|||
} SCliMsg;
|
||||
|
||||
typedef struct SCliThrdObj {
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
uv_loop_t* loop;
|
||||
SAsyncPool* asyncPool;
|
||||
uv_timer_t timer;
|
||||
|
@ -64,7 +64,7 @@ typedef struct SCliThrdObj {
|
|||
|
||||
// msg queue
|
||||
queue msg;
|
||||
pthread_mutex_t msgMtx;
|
||||
TdThreadMutex msgMtx;
|
||||
|
||||
uint64_t nextTimeout; // next timeout
|
||||
void* pTransInst; //
|
||||
|
@ -668,9 +668,9 @@ static void cliAsyncCb(uv_async_t* handle) {
|
|||
|
||||
// batch process to avoid to lock/unlock frequently
|
||||
queue wq;
|
||||
pthread_mutex_lock(&item->mtx);
|
||||
taosThreadMutexLock(&item->mtx);
|
||||
QUEUE_MOVE(&item->qmsg, &wq);
|
||||
pthread_mutex_unlock(&item->mtx);
|
||||
taosThreadMutexUnlock(&item->mtx);
|
||||
|
||||
int count = 0;
|
||||
while (!QUEUE_IS_EMPTY(&wq)) {
|
||||
|
@ -710,7 +710,7 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
||||
pThrd->pTransInst = shandle;
|
||||
|
||||
int err = pthread_create(&pThrd->thread, NULL, cliWorkThread, (void*)(pThrd));
|
||||
int err = taosThreadCreate(&pThrd->thread, NULL, cliWorkThread, (void*)(pThrd));
|
||||
if (err == 0) {
|
||||
tDebug("success to create tranport-cli thread %d", i);
|
||||
}
|
||||
|
@ -739,7 +739,7 @@ static SCliThrdObj* createThrdObj() {
|
|||
SCliThrdObj* pThrd = (SCliThrdObj*)calloc(1, sizeof(SCliThrdObj));
|
||||
|
||||
QUEUE_INIT(&pThrd->msg);
|
||||
pthread_mutex_init(&pThrd->msgMtx, NULL);
|
||||
taosThreadMutexInit(&pThrd->msgMtx, NULL);
|
||||
|
||||
pThrd->loop = (uv_loop_t*)malloc(sizeof(uv_loop_t));
|
||||
uv_loop_init(pThrd->loop);
|
||||
|
@ -759,8 +759,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd) {
|
|||
return;
|
||||
}
|
||||
uv_stop(pThrd->loop);
|
||||
pthread_join(pThrd->thread, NULL);
|
||||
pthread_mutex_destroy(&pThrd->msgMtx);
|
||||
taosThreadJoin(pThrd->thread, NULL);
|
||||
taosThreadMutexDestroy(&pThrd->msgMtx);
|
||||
transDestroyAsyncPool(pThrd->asyncPool);
|
||||
|
||||
uv_timer_stop(&pThrd->timer);
|
||||
|
|
|
@ -186,7 +186,7 @@ SAsyncPool* transCreateAsyncPool(uv_loop_t* loop, int sz, void* arg, AsyncCB cb)
|
|||
SAsyncItem* item = calloc(1, sizeof(SAsyncItem));
|
||||
item->pThrd = arg;
|
||||
QUEUE_INIT(&item->qmsg);
|
||||
pthread_mutex_init(&item->mtx, NULL);
|
||||
taosThreadMutexInit(&item->mtx, NULL);
|
||||
|
||||
async->data = item;
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ void transDestroyAsyncPool(SAsyncPool* pool) {
|
|||
uv_async_t* async = &(pool->asyncs[i]);
|
||||
|
||||
SAsyncItem* item = async->data;
|
||||
pthread_mutex_destroy(&item->mtx);
|
||||
taosThreadMutexDestroy(&item->mtx);
|
||||
free(item);
|
||||
}
|
||||
free(pool->asyncs);
|
||||
|
@ -214,9 +214,9 @@ int transSendAsync(SAsyncPool* pool, queue* q) {
|
|||
SAsyncItem* item = async->data;
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
pthread_mutex_lock(&item->mtx);
|
||||
taosThreadMutexLock(&item->mtx);
|
||||
QUEUE_PUSH(&item->qmsg, q);
|
||||
pthread_mutex_unlock(&item->mtx);
|
||||
taosThreadMutexUnlock(&item->mtx);
|
||||
int64_t el = taosGetTimestampUs() - st;
|
||||
if (el > 50) {
|
||||
// tInfo("lock and unlock cost: %d", (int)el);
|
||||
|
|
|
@ -62,13 +62,13 @@ typedef struct SSrvMsg {
|
|||
} SSrvMsg;
|
||||
|
||||
typedef struct SWorkThrdObj {
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
uv_pipe_t* pipe;
|
||||
uv_os_fd_t fd;
|
||||
uv_loop_t* loop;
|
||||
SAsyncPool* asyncPool;
|
||||
queue msg;
|
||||
pthread_mutex_t msgMtx;
|
||||
TdThreadMutex msgMtx;
|
||||
|
||||
queue conn;
|
||||
void* pTransInst;
|
||||
|
@ -76,7 +76,7 @@ typedef struct SWorkThrdObj {
|
|||
} SWorkThrdObj;
|
||||
|
||||
typedef struct SServerObj {
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
uv_tcp_t server;
|
||||
uv_loop_t* loop;
|
||||
|
||||
|
@ -476,9 +476,9 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
|
|||
queue wq;
|
||||
|
||||
// batch process to avoid to lock/unlock frequently
|
||||
pthread_mutex_lock(&item->mtx);
|
||||
taosThreadMutexLock(&item->mtx);
|
||||
QUEUE_MOVE(&item->qmsg, &wq);
|
||||
pthread_mutex_unlock(&item->mtx);
|
||||
taosThreadMutexUnlock(&item->mtx);
|
||||
|
||||
while (!QUEUE_IS_EMPTY(&wq)) {
|
||||
queue* head = QUEUE_HEAD(&wq);
|
||||
|
@ -622,7 +622,7 @@ static bool addHandleToWorkloop(void* arg) {
|
|||
pThrd->pipe->data = pThrd;
|
||||
|
||||
QUEUE_INIT(&pThrd->msg);
|
||||
pthread_mutex_init(&pThrd->msgMtx, NULL);
|
||||
taosThreadMutexInit(&pThrd->msgMtx, NULL);
|
||||
|
||||
// conn set
|
||||
QUEUE_INIT(&pThrd->conn);
|
||||
|
@ -771,7 +771,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
if (false == addHandleToWorkloop(thrd)) {
|
||||
goto End;
|
||||
}
|
||||
int err = pthread_create(&(thrd->thread), NULL, workerThread, (void*)(thrd));
|
||||
int err = taosThreadCreate(&(thrd->thread), NULL, workerThread, (void*)(thrd));
|
||||
if (err == 0) {
|
||||
tDebug("sucess to create worker-thread %d", i);
|
||||
// printf("thread %d create\n", i);
|
||||
|
@ -783,7 +783,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
if (false == addHandleToAcceptloop(srv)) {
|
||||
goto End;
|
||||
}
|
||||
int err = pthread_create(&srv->thread, NULL, acceptThread, (void*)srv);
|
||||
int err = taosThreadCreate(&srv->thread, NULL, acceptThread, (void*)srv);
|
||||
if (err == 0) {
|
||||
tDebug("success to create accept-thread");
|
||||
} else {
|
||||
|
@ -850,7 +850,7 @@ void destroyWorkThrd(SWorkThrdObj* pThrd) {
|
|||
if (pThrd == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_join(pThrd->thread, NULL);
|
||||
taosThreadJoin(pThrd->thread, NULL);
|
||||
free(pThrd->loop);
|
||||
transDestroyAsyncPool(pThrd->asyncPool);
|
||||
free(pThrd);
|
||||
|
@ -872,7 +872,7 @@ void transCloseServer(void* arg) {
|
|||
|
||||
tDebug("send quit msg to accept thread");
|
||||
uv_async_send(srv->pAcceptAsync);
|
||||
pthread_join(srv->thread, NULL);
|
||||
taosThreadJoin(srv->thread, NULL);
|
||||
|
||||
free(srv->pThreadObj);
|
||||
free(srv->pAcceptAsync);
|
||||
|
|
|
@ -30,7 +30,7 @@ typedef struct {
|
|||
int msgSize;
|
||||
tsem_t rspSem;
|
||||
tsem_t * pOverSem;
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
void * pRpc;
|
||||
} SInfo;
|
||||
static void processResponse(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
|
@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
|
|||
char secret[20] = "mypassword";
|
||||
struct timeval systemTime;
|
||||
int64_t startTime, endTime;
|
||||
pthread_attr_t thattr;
|
||||
TdThreadAttr thattr;
|
||||
|
||||
// server info
|
||||
epSet.inUse = 0;
|
||||
|
@ -186,8 +186,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads);
|
||||
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
for (int i = 0; i < appThreads; ++i) {
|
||||
pInfo->index = i;
|
||||
|
@ -196,7 +196,7 @@ int main(int argc, char *argv[]) {
|
|||
pInfo->msgSize = msgSize;
|
||||
tsem_init(&pInfo->rspSem, 0, 0);
|
||||
pInfo->pRpc = pRpc;
|
||||
pthread_create(&pInfo->thread, &thattr, sendRequest, pInfo);
|
||||
taosThreadCreate(&pInfo->thread, &thattr, sendRequest, pInfo);
|
||||
pInfo++;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ typedef struct {
|
|||
int msgSize;
|
||||
tsem_t rspSem;
|
||||
tsem_t *pOverSem;
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
void *pRpc;
|
||||
} SInfo;
|
||||
|
||||
|
@ -80,7 +80,7 @@ int main(int argc, char *argv[]) {
|
|||
char secret[TSDB_KEY_LEN] = "mypassword";
|
||||
struct timeval systemTime;
|
||||
int64_t startTime, endTime;
|
||||
pthread_attr_t thattr;
|
||||
TdThreadAttr thattr;
|
||||
|
||||
// server info
|
||||
epSet.numOfEps = 1;
|
||||
|
@ -163,8 +163,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo)*appThreads);
|
||||
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
for (int i=0; i<appThreads; ++i) {
|
||||
pInfo->index = i;
|
||||
|
@ -173,7 +173,7 @@ int main(int argc, char *argv[]) {
|
|||
pInfo->msgSize = msgSize;
|
||||
tsem_init(&pInfo->rspSem, 0, 0);
|
||||
pInfo->pRpc = pRpc;
|
||||
pthread_create(&pInfo->thread, &thattr, sendRequest, pInfo);
|
||||
taosThreadCreate(&pInfo->thread, &thattr, sendRequest, pInfo);
|
||||
pInfo++;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ typedef struct {
|
|||
int msgSize;
|
||||
tsem_t rspSem;
|
||||
tsem_t * pOverSem;
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
void * pRpc;
|
||||
} SInfo;
|
||||
static void processResponse(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
|
@ -105,7 +105,7 @@ int main(int argc, char *argv[]) {
|
|||
char secret[20] = "mypassword";
|
||||
struct timeval systemTime;
|
||||
int64_t startTime, endTime;
|
||||
pthread_attr_t thattr;
|
||||
TdThreadAttr thattr;
|
||||
|
||||
// server info
|
||||
epSet.inUse = 0;
|
||||
|
@ -186,8 +186,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads);
|
||||
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
for (int i = 0; i < appThreads; ++i) {
|
||||
pInfo->index = i;
|
||||
|
@ -196,7 +196,7 @@ int main(int argc, char *argv[]) {
|
|||
pInfo->msgSize = msgSize;
|
||||
tsem_init(&pInfo->rspSem, 0, 0);
|
||||
pInfo->pRpc = pRpc;
|
||||
pthread_create(&pInfo->thread, &thattr, sendRequest, pInfo);
|
||||
taosThreadCreate(&pInfo->thread, &thattr, sendRequest, pInfo);
|
||||
pInfo++;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ typedef struct {
|
|||
int8_t inited;
|
||||
uint32_t seq;
|
||||
int32_t refSetId;
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
} SWalMgmt;
|
||||
|
||||
static SWalMgmt tsWal = {0, .seq = 1};
|
||||
|
@ -101,7 +101,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
|
|||
pWal->writeHead.head.headVer = WAL_HEAD_VER;
|
||||
pWal->writeHead.magic = WAL_MAGIC;
|
||||
|
||||
if (pthread_mutex_init(&pWal->mutex, NULL) < 0) {
|
||||
if (taosThreadMutexInit(&pWal->mutex, NULL) < 0) {
|
||||
taosArrayDestroy(pWal->fileInfoSet);
|
||||
free(pWal);
|
||||
return NULL;
|
||||
|
@ -109,7 +109,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
|
|||
|
||||
pWal->refId = taosAddRef(tsWal.refSetId, pWal);
|
||||
if (pWal->refId < 0) {
|
||||
pthread_mutex_destroy(&pWal->mutex);
|
||||
taosThreadMutexDestroy(&pWal->mutex);
|
||||
taosArrayDestroy(pWal->fileInfoSet);
|
||||
free(pWal);
|
||||
return NULL;
|
||||
|
@ -119,7 +119,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
|
|||
|
||||
if (walCheckAndRepairMeta(pWal) < 0) {
|
||||
taosRemoveRef(tsWal.refSetId, pWal->refId);
|
||||
pthread_mutex_destroy(&pWal->mutex);
|
||||
taosThreadMutexDestroy(&pWal->mutex);
|
||||
taosArrayDestroy(pWal->fileInfoSet);
|
||||
free(pWal);
|
||||
return NULL;
|
||||
|
@ -156,7 +156,7 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
|
|||
}
|
||||
|
||||
void walClose(SWal *pWal) {
|
||||
pthread_mutex_lock(&pWal->mutex);
|
||||
taosThreadMutexLock(&pWal->mutex);
|
||||
taosCloseFile(&pWal->pWriteLogTFile);
|
||||
pWal->pWriteLogTFile = NULL;
|
||||
taosCloseFile(&pWal->pWriteIdxTFile);
|
||||
|
@ -164,7 +164,7 @@ void walClose(SWal *pWal) {
|
|||
walSaveMeta(pWal);
|
||||
taosArrayDestroy(pWal->fileInfoSet);
|
||||
pWal->fileInfoSet = NULL;
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
|
||||
taosRemoveRef(tsWal.refSetId, pWal->refId);
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ static void walFreeObj(void *wal) {
|
|||
SWal *pWal = wal;
|
||||
wDebug("vgId:%d, wal:%p is freed", pWal->cfg.vgId, pWal);
|
||||
|
||||
pthread_mutex_destroy(&pWal->mutex);
|
||||
taosThreadMutexDestroy(&pWal->mutex);
|
||||
tfree(pWal);
|
||||
}
|
||||
|
||||
|
@ -223,17 +223,17 @@ static void *walThreadFunc(void *param) {
|
|||
}
|
||||
|
||||
static int32_t walCreateThread() {
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&tsWal.thread, &thAttr, walThreadFunc, NULL) != 0) {
|
||||
if (taosThreadCreate(&tsWal.thread, &thAttr, walThreadFunc, NULL) != 0) {
|
||||
wError("failed to create wal thread since %s", strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
wDebug("wal thread is launched, thread:0x%08" PRIx64, taosGetPthreadId(tsWal.thread));
|
||||
|
||||
return 0;
|
||||
|
@ -243,7 +243,7 @@ static void walStopThread() {
|
|||
atomic_store_8(&tsWal.stop, 1);
|
||||
|
||||
if (taosCheckPthreadValid(tsWal.thread)) {
|
||||
pthread_join(tsWal.thread, NULL);
|
||||
taosThreadJoin(tsWal.thread, NULL);
|
||||
}
|
||||
|
||||
wDebug("wal thread is stopped");
|
||||
|
|
|
@ -38,7 +38,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
terrno = TSDB_CODE_WAL_INVALID_VER;
|
||||
return -1;
|
||||
}
|
||||
pthread_mutex_lock(&pWal->mutex);
|
||||
taosThreadMutexLock(&pWal->mutex);
|
||||
|
||||
// find correct file
|
||||
if (ver < walGetLastFileFirstVer(pWal)) {
|
||||
|
@ -65,20 +65,20 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
|
||||
// TODO:change to deserialize function
|
||||
if (pIdxTFile == NULL) {
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
return -1;
|
||||
}
|
||||
int64_t idxOff = walGetVerIdxOffset(pWal, ver);
|
||||
code = taosLSeekFile(pIdxTFile, idxOff, SEEK_SET);
|
||||
if (code < 0) {
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
return -1;
|
||||
}
|
||||
// read idx file and get log file pos
|
||||
// TODO:change to deserialize function
|
||||
SWalIdxEntry entry;
|
||||
if (taosReadFile(pIdxTFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) {
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
return -1;
|
||||
}
|
||||
ASSERT(entry.ver == ver);
|
||||
|
@ -87,13 +87,13 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
TdFilePtr pLogTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ);
|
||||
if (pLogTFile == NULL) {
|
||||
// TODO
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
return -1;
|
||||
}
|
||||
code = taosLSeekFile(pLogTFile, entry.offset, SEEK_SET);
|
||||
if (code < 0) {
|
||||
// TODO
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
return -1;
|
||||
}
|
||||
// validate offset
|
||||
|
@ -127,7 +127,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->fileSize = entry.offset;
|
||||
|
||||
// unlock
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -283,7 +283,7 @@ int64_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in
|
|||
|
||||
ASSERT(pWal->writeCur >= 0);
|
||||
|
||||
pthread_mutex_lock(&pWal->mutex);
|
||||
taosThreadMutexLock(&pWal->mutex);
|
||||
|
||||
if (pWal->pWriteIdxTFile == NULL || pWal->pWriteLogTFile == NULL) {
|
||||
walSetWrite(pWal);
|
||||
|
@ -327,7 +327,7 @@ int64_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in
|
|||
walGetCurFileInfo(pWal)->lastVer = index;
|
||||
walGetCurFileInfo(pWal)->fileSize += sizeof(SWalHead) + bodyLen;
|
||||
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ typedef int32_t SocketFd;
|
|||
typedef int32_t FileFd;
|
||||
|
||||
typedef struct TdFile {
|
||||
pthread_rwlock_t rwlock;
|
||||
TdThreadRwlock rwlock;
|
||||
int refId;
|
||||
FileFd fd;
|
||||
FILE *fp;
|
||||
|
@ -275,7 +275,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
|
|||
return NULL;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_init(&(pFile->rwlock), NULL);
|
||||
taosThreadRwlockInit(&(pFile->rwlock), NULL);
|
||||
#endif
|
||||
pFile->fd = fd;
|
||||
pFile->fp = fp;
|
||||
|
@ -292,7 +292,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
|
|||
return 0;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_wrlock(&((*ppFile)->rwlock));
|
||||
taosThreadRwlockWrlock(&((*ppFile)->rwlock));
|
||||
#endif
|
||||
if (ppFile == NULL || *ppFile == NULL || (*ppFile)->fd == -1) {
|
||||
return 0;
|
||||
|
@ -309,8 +309,8 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
|
|||
}
|
||||
(*ppFile)->refId = 0;
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_unlock(&((*ppFile)->rwlock));
|
||||
pthread_rwlock_destroy(&((*ppFile)->rwlock));
|
||||
taosThreadRwlockUnlock(&((*ppFile)->rwlock));
|
||||
taosThreadRwlockDestroy(&((*ppFile)->rwlock));
|
||||
#endif
|
||||
free(*ppFile);
|
||||
*ppFile = NULL;
|
||||
|
@ -323,7 +323,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
|||
return 0;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_rdlock(&(pFile->rwlock));
|
||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
#endif
|
||||
assert(pFile->fd >= 0);
|
||||
int64_t leftbytes = count;
|
||||
|
@ -337,13 +337,13 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
|||
continue;
|
||||
} else {
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_unlock(&(pFile->rwlock));
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
} else if (readbytes == 0) {
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_unlock(&(pFile->rwlock));
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return (int64_t)(count - leftbytes);
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
|||
}
|
||||
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_unlock(&(pFile->rwlock));
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
@ -363,12 +363,12 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
|||
return 0;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_rdlock(&(pFile->rwlock));
|
||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
#endif
|
||||
assert(pFile->fd >= 0);
|
||||
int64_t ret = pread(pFile->fd, buf, count, offset);
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_unlock(&(pFile->rwlock));
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
@ -378,7 +378,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
|||
return 0;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_wrlock(&(pFile->rwlock));
|
||||
taosThreadRwlockWrlock(&(pFile->rwlock));
|
||||
#endif
|
||||
assert(pFile->fd >= 0);
|
||||
|
||||
|
@ -393,7 +393,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
|||
continue;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_unlock(&(pFile->rwlock));
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
|||
}
|
||||
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_unlock(&(pFile->rwlock));
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
@ -412,12 +412,12 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
|
|||
return 0;
|
||||
}
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_rdlock(&(pFile->rwlock));
|
||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||
#endif
|
||||
assert(pFile->fd >= 0);
|
||||
int64_t ret = lseek(pFile->fd, (long)offset, whence);
|
||||
#if FILE_WITH_LOCK
|
||||
pthread_rwlock_unlock(&(pFile->rwlock));
|
||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ typedef SocketFd EpollFd;
|
|||
|
||||
typedef struct TdSocketServer {
|
||||
#if SOCKET_WITH_LOCK
|
||||
pthread_rwlock_t rwlock;
|
||||
TdThreadRwlock rwlock;
|
||||
#endif
|
||||
int refId;
|
||||
SocketFd fd;
|
||||
|
@ -60,7 +60,7 @@ typedef struct TdSocketServer {
|
|||
|
||||
typedef struct TdSocket {
|
||||
#if SOCKET_WITH_LOCK
|
||||
pthread_rwlock_t rwlock;
|
||||
TdThreadRwlock rwlock;
|
||||
#endif
|
||||
int refId;
|
||||
SocketFd fd;
|
||||
|
@ -68,7 +68,7 @@ typedef struct TdSocket {
|
|||
|
||||
typedef struct TdEpoll {
|
||||
#if SOCKET_WITH_LOCK
|
||||
pthread_rwlock_t rwlock;
|
||||
TdThreadRwlock rwlock;
|
||||
#endif
|
||||
int refId;
|
||||
EpollFd fd;
|
||||
|
@ -775,7 +775,7 @@ void taosBlockSIGPIPE() {
|
|||
sigset_t signal_mask;
|
||||
sigemptyset(&signal_mask);
|
||||
sigaddset(&signal_mask, SIGPIPE);
|
||||
int32_t rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
|
||||
int32_t rc = taosThreadSigmask(SIG_BLOCK, &signal_mask, NULL);
|
||||
if (rc != 0) {
|
||||
// printf("failed to block SIGPIPE");
|
||||
}
|
||||
|
@ -893,7 +893,7 @@ void taosSetMaskSIGPIPE() {
|
|||
sigset_t signal_mask;
|
||||
sigemptyset(&signal_mask);
|
||||
sigaddset(&signal_mask, SIGPIPE);
|
||||
int32_t rc = pthread_sigmask(SIG_SETMASK, &signal_mask, NULL);
|
||||
int32_t rc = taosThreadSigmask(SIG_SETMASK, &signal_mask, NULL);
|
||||
if (rc != 0) {
|
||||
// printf("failed to setmask SIGPIPE");
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ static MMRESULT timerId;
|
|||
|
||||
static void (*timer_callback)(int);
|
||||
static int timer_ms = 0;
|
||||
static pthread_t timer_thread;
|
||||
static TdThread timer_thread;
|
||||
static int timer_kq = -1;
|
||||
static volatile int timer_stop = 0;
|
||||
|
||||
|
@ -83,7 +83,7 @@ static void taosDeleteTimer(void *tharg) {
|
|||
timer_delete(*pTimer);
|
||||
}
|
||||
|
||||
static pthread_t timerThread;
|
||||
static TdThread timerThread;
|
||||
static timer_t timerId;
|
||||
static volatile bool stopTimer = false;
|
||||
static void * taosProcessAlarmSignal(void *tharg) {
|
||||
|
@ -112,7 +112,7 @@ static void * taosProcessAlarmSignal(void *tharg) {
|
|||
// printf("Failed to create timer");
|
||||
}
|
||||
|
||||
pthread_cleanup_push(taosDeleteTimer, &timerId);
|
||||
taosThreadCleanupPush(taosDeleteTimer, &timerId);
|
||||
|
||||
struct itimerspec ts;
|
||||
ts.it_value.tv_sec = 0;
|
||||
|
@ -136,7 +136,7 @@ static void * taosProcessAlarmSignal(void *tharg) {
|
|||
callback(0);
|
||||
}
|
||||
|
||||
pthread_cleanup_pop(1);
|
||||
taosThreadCleanupPop(1);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ int taosInitTimer(void (*callback)(int), int ms) {
|
|||
abort();
|
||||
}
|
||||
|
||||
r = pthread_create(&timer_thread, NULL, timer_routine, NULL);
|
||||
r = taosThreadCreate(&timer_thread, NULL, timer_routine, NULL);
|
||||
if (r) {
|
||||
fprintf(stderr, "==%s[%d]%s()==failed to create timer thread\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__);
|
||||
// since no caller of this func checks the return value for the moment
|
||||
|
@ -174,10 +174,10 @@ int taosInitTimer(void (*callback)(int), int ms) {
|
|||
return 0;
|
||||
#else
|
||||
stopTimer = false;
|
||||
pthread_attr_t tattr;
|
||||
pthread_attr_init(&tattr);
|
||||
int code = pthread_create(&timerThread, &tattr, taosProcessAlarmSignal, callback);
|
||||
pthread_attr_destroy(&tattr);
|
||||
TdThreadAttr tattr;
|
||||
taosThreadAttrInit(&tattr);
|
||||
int code = taosThreadCreate(&timerThread, &tattr, taosProcessAlarmSignal, callback);
|
||||
taosThreadAttrDestroy(&tattr);
|
||||
if (code != 0) {
|
||||
// printf("failed to create timer thread");
|
||||
return -1;
|
||||
|
@ -195,7 +195,7 @@ void taosUninitTimer() {
|
|||
#elif defined(_TD_DARWIN_64)
|
||||
int r = 0;
|
||||
timer_stop = 1;
|
||||
r = pthread_join(timer_thread, NULL);
|
||||
r = taosThreadJoin(timer_thread, NULL);
|
||||
if (r) {
|
||||
fprintf(stderr, "==%s[%d]%s()==failed to join timer thread\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__);
|
||||
// since no caller of this func checks the return value for the moment
|
||||
|
@ -207,7 +207,7 @@ void taosUninitTimer() {
|
|||
stopTimer = true;
|
||||
|
||||
// printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread));
|
||||
pthread_join(timerThread, NULL);
|
||||
taosThreadJoin(timerThread, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#define CACHE_MAX_CAPACITY 1024*1024*16
|
||||
#define CACHE_DEFAULT_CAPACITY 1024*4
|
||||
|
||||
static pthread_t cacheRefreshWorker = {0};
|
||||
static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT;
|
||||
static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER;
|
||||
static TdThread cacheRefreshWorker = {0};
|
||||
static TdThreadOnce cacheThreadInit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadMutex guard = PTHREAD_MUTEX_INITIALIZER;
|
||||
static SArray *pCacheArrayList = NULL;
|
||||
static bool stopRefreshWorker = false;
|
||||
static bool refreshWorkerNormalStopped = false;
|
||||
|
@ -90,13 +90,13 @@ struct SCacheObj {
|
|||
STrashElem *pTrash;
|
||||
|
||||
uint8_t deleting; // set the deleting flag to stop refreshing ASAP.
|
||||
pthread_t refreshWorker;
|
||||
TdThread refreshWorker;
|
||||
bool extendLifespan; // auto extend life span when one item is accessed.
|
||||
int64_t checkTick; // tick used to record the check times of the refresh threads
|
||||
#if defined(LINUX)
|
||||
pthread_rwlock_t lock;
|
||||
TdThreadRwlock lock;
|
||||
#else
|
||||
pthread_mutex_t lock;
|
||||
TdThreadMutex lock;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -109,33 +109,33 @@ typedef struct SCacheObjTravSup {
|
|||
|
||||
static FORCE_INLINE void __trashcan_wr_lock(SCacheObj *pCacheObj) {
|
||||
#if defined(LINUX)
|
||||
pthread_rwlock_wrlock(&pCacheObj->lock);
|
||||
taosThreadRwlockWrlock(&pCacheObj->lock);
|
||||
#else
|
||||
pthread_mutex_lock(&pCacheObj->lock);
|
||||
taosThreadMutexLock(&pCacheObj->lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
static FORCE_INLINE void __trashcan_unlock(SCacheObj *pCacheObj) {
|
||||
#if defined(LINUX)
|
||||
pthread_rwlock_unlock(&pCacheObj->lock);
|
||||
taosThreadRwlockUnlock(&pCacheObj->lock);
|
||||
#else
|
||||
pthread_mutex_unlock(&pCacheObj->lock);
|
||||
taosThreadMutexUnlock(&pCacheObj->lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t __trashcan_lock_init(SCacheObj *pCacheObj) {
|
||||
#if defined(LINUX)
|
||||
return pthread_rwlock_init(&pCacheObj->lock, NULL);
|
||||
return taosThreadRwlockInit(&pCacheObj->lock, NULL);
|
||||
#else
|
||||
return pthread_mutex_init(&pCacheObj->lock, NULL);
|
||||
return taosThreadMutexInit(&pCacheObj->lock, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static FORCE_INLINE void __trashcan_lock_destroy(SCacheObj *pCacheObj) {
|
||||
#if defined(LINUX)
|
||||
pthread_rwlock_destroy(&pCacheObj->lock);
|
||||
taosThreadRwlockDestroy(&pCacheObj->lock);
|
||||
#else
|
||||
pthread_mutex_destroy(&pCacheObj->lock);
|
||||
taosThreadMutexDestroy(&pCacheObj->lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -154,20 +154,20 @@ static void *taosCacheTimedRefresh(void *handle);
|
|||
static void doInitRefreshThread(void) {
|
||||
pCacheArrayList = taosArrayInit(4, POINTER_BYTES);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
pthread_create(&cacheRefreshWorker, &thattr, taosCacheTimedRefresh, NULL);
|
||||
pthread_attr_destroy(&thattr);
|
||||
taosThreadCreate(&cacheRefreshWorker, &thattr, taosCacheTimedRefresh, NULL);
|
||||
taosThreadAttrDestroy(&thattr);
|
||||
}
|
||||
|
||||
pthread_t doRegisterCacheObj(SCacheObj *pCacheObj) {
|
||||
pthread_once(&cacheThreadInit, doInitRefreshThread);
|
||||
TdThread doRegisterCacheObj(SCacheObj *pCacheObj) {
|
||||
taosThreadOnce(&cacheThreadInit, doInitRefreshThread);
|
||||
|
||||
pthread_mutex_lock(&guard);
|
||||
taosThreadMutexLock(&guard);
|
||||
taosArrayPush(pCacheArrayList, &pCacheObj);
|
||||
pthread_mutex_unlock(&guard);
|
||||
taosThreadMutexUnlock(&guard);
|
||||
|
||||
return cacheRefreshWorker;
|
||||
}
|
||||
|
@ -836,19 +836,19 @@ void *taosCacheTimedRefresh(void *handle) {
|
|||
goto _end;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&guard);
|
||||
taosThreadMutexLock(&guard);
|
||||
size_t size = taosArrayGetSize(pCacheArrayList);
|
||||
pthread_mutex_unlock(&guard);
|
||||
taosThreadMutexUnlock(&guard);
|
||||
|
||||
count += 1;
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
pthread_mutex_lock(&guard);
|
||||
taosThreadMutexLock(&guard);
|
||||
SCacheObj *pCacheObj = taosArrayGetP(pCacheArrayList, i);
|
||||
|
||||
if (pCacheObj == NULL) {
|
||||
uError("object is destroyed. ignore and try next");
|
||||
pthread_mutex_unlock(&guard);
|
||||
taosThreadMutexUnlock(&guard);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -860,11 +860,11 @@ void *taosCacheTimedRefresh(void *handle) {
|
|||
uDebug("%s is destroying, remove it from refresh list, remain cache obj:%" PRIzu, pCacheObj->name, size);
|
||||
pCacheObj->deleting = 0; // reset the deleting flag to enable pCacheObj to continue releasing resources.
|
||||
|
||||
pthread_mutex_unlock(&guard);
|
||||
taosThreadMutexUnlock(&guard);
|
||||
continue;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&guard);
|
||||
taosThreadMutexUnlock(&guard);
|
||||
|
||||
if ((count % pCacheObj->checkTick) != 0) {
|
||||
continue;
|
||||
|
@ -892,7 +892,7 @@ _end:
|
|||
taosArrayDestroy(pCacheArrayList);
|
||||
|
||||
pCacheArrayList = NULL;
|
||||
pthread_mutex_destroy(&guard);
|
||||
taosThreadMutexDestroy(&guard);
|
||||
refreshWorkerNormalStopped = true;
|
||||
|
||||
uDebug("cache refresh thread quits");
|
||||
|
|
|
@ -455,14 +455,14 @@ static int32_t taosCompareTaosError(const void* a, const void* b) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static pthread_once_t tsErrorInit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadOnce tsErrorInit = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void tsSortError(void) {
|
||||
qsort(errors, sizeof(errors) / sizeof(errors[0]), sizeof(errors[0]), taosCompareTaosError);
|
||||
}
|
||||
|
||||
const char* tstrerror(int32_t err) {
|
||||
pthread_once(&tsErrorInit, tsSortError);
|
||||
taosThreadOnce(&tsErrorInit, tsSortError);
|
||||
|
||||
// this is a system errno
|
||||
if ((err & 0x00ff0000) == 0x00ff0000) {
|
||||
|
|
|
@ -31,7 +31,7 @@ void *taosInitIdPool(int32_t maxId) {
|
|||
pIdPool->numOfFree = maxId;
|
||||
pIdPool->freeSlot = 0;
|
||||
|
||||
pthread_mutex_init(&pIdPool->mutex, NULL);
|
||||
taosThreadMutexInit(&pIdPool->mutex, NULL);
|
||||
|
||||
uDebug("pool:%p is setup, maxId:%d", pIdPool, pIdPool->maxId);
|
||||
|
||||
|
@ -42,7 +42,7 @@ int32_t taosAllocateId(id_pool_t *pIdPool) {
|
|||
if (pIdPool == NULL) return -1;
|
||||
|
||||
int32_t slot = -1;
|
||||
pthread_mutex_lock(&pIdPool->mutex);
|
||||
taosThreadMutexLock(&pIdPool->mutex);
|
||||
|
||||
if (pIdPool->numOfFree > 0) {
|
||||
for (int32_t i = 0; i < pIdPool->maxId; ++i) {
|
||||
|
@ -56,14 +56,14 @@ int32_t taosAllocateId(id_pool_t *pIdPool) {
|
|||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pIdPool->mutex);
|
||||
taosThreadMutexUnlock(&pIdPool->mutex);
|
||||
return slot + 1;
|
||||
}
|
||||
|
||||
void taosFreeId(id_pool_t *pIdPool, int32_t id) {
|
||||
if (pIdPool == NULL) return;
|
||||
|
||||
pthread_mutex_lock(&pIdPool->mutex);
|
||||
taosThreadMutexLock(&pIdPool->mutex);
|
||||
|
||||
int32_t slot = (id - 1) % pIdPool->maxId;
|
||||
if (pIdPool->freeList[slot]) {
|
||||
|
@ -71,7 +71,7 @@ void taosFreeId(id_pool_t *pIdPool, int32_t id) {
|
|||
pIdPool->numOfFree++;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pIdPool->mutex);
|
||||
taosThreadMutexUnlock(&pIdPool->mutex);
|
||||
}
|
||||
|
||||
void taosIdPoolCleanUp(id_pool_t *pIdPool) {
|
||||
|
@ -81,7 +81,7 @@ void taosIdPoolCleanUp(id_pool_t *pIdPool) {
|
|||
|
||||
if (pIdPool->freeList) free(pIdPool->freeList);
|
||||
|
||||
pthread_mutex_destroy(&pIdPool->mutex);
|
||||
taosThreadMutexDestroy(&pIdPool->mutex);
|
||||
|
||||
memset(pIdPool, 0, sizeof(id_pool_t));
|
||||
|
||||
|
@ -89,16 +89,16 @@ void taosIdPoolCleanUp(id_pool_t *pIdPool) {
|
|||
}
|
||||
|
||||
int32_t taosIdPoolNumOfUsed(id_pool_t *pIdPool) {
|
||||
pthread_mutex_lock(&pIdPool->mutex);
|
||||
taosThreadMutexLock(&pIdPool->mutex);
|
||||
int32_t ret = pIdPool->maxId - pIdPool->numOfFree;
|
||||
pthread_mutex_unlock(&pIdPool->mutex);
|
||||
taosThreadMutexUnlock(&pIdPool->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool taosIdPoolMarkStatus(id_pool_t *pIdPool, int32_t id) {
|
||||
bool ret = false;
|
||||
pthread_mutex_lock(&pIdPool->mutex);
|
||||
taosThreadMutexLock(&pIdPool->mutex);
|
||||
|
||||
int32_t slot = (id - 1) % pIdPool->maxId;
|
||||
if (!pIdPool->freeList[slot]) {
|
||||
|
@ -109,7 +109,7 @@ bool taosIdPoolMarkStatus(id_pool_t *pIdPool, int32_t id) {
|
|||
ret = false;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pIdPool->mutex);
|
||||
taosThreadMutexUnlock(&pIdPool->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&pIdPool->mutex);
|
||||
taosThreadMutexLock(&pIdPool->mutex);
|
||||
|
||||
memcpy(idList, pIdPool->freeList, sizeof(bool) * pIdPool->maxId);
|
||||
pIdPool->numOfFree += (maxId - pIdPool->maxId);
|
||||
|
@ -133,15 +133,15 @@ int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) {
|
|||
pIdPool->freeList = idList;
|
||||
free(oldIdList);
|
||||
|
||||
pthread_mutex_unlock(&pIdPool->mutex);
|
||||
taosThreadMutexUnlock(&pIdPool->mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosIdPoolMaxSize(id_pool_t *pIdPool) {
|
||||
pthread_mutex_lock(&pIdPool->mutex);
|
||||
taosThreadMutexLock(&pIdPool->mutex);
|
||||
int32_t ret = pIdPool->maxId;
|
||||
pthread_mutex_unlock(&pIdPool->mutex);
|
||||
taosThreadMutexUnlock(&pIdPool->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -45,8 +45,8 @@ typedef struct {
|
|||
int32_t minBuffSize;
|
||||
TdFilePtr pFile;
|
||||
int32_t stop;
|
||||
pthread_t asyncThread;
|
||||
pthread_mutex_t buffMutex;
|
||||
TdThread asyncThread;
|
||||
TdThreadMutex buffMutex;
|
||||
tsem_t buffNotEmpty;
|
||||
} SLogBuff;
|
||||
|
||||
|
@ -59,7 +59,7 @@ typedef struct {
|
|||
pid_t pid;
|
||||
char logName[LOG_FILE_NAME_LEN];
|
||||
SLogBuff *logHandle;
|
||||
pthread_mutex_t logMutex;
|
||||
TdThreadMutex logMutex;
|
||||
} SLogObj;
|
||||
|
||||
static int8_t tsLogInited = 0;
|
||||
|
@ -107,12 +107,12 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum)
|
|||
static int32_t taosCompressFile(char *srcFileName, char *destFileName);
|
||||
|
||||
static int32_t taosStartLog() {
|
||||
pthread_attr_t threadAttr;
|
||||
pthread_attr_init(&threadAttr);
|
||||
if (pthread_create(&(tsLogObj.logHandle->asyncThread), &threadAttr, taosAsyncOutputLog, tsLogObj.logHandle) != 0) {
|
||||
TdThreadAttr threadAttr;
|
||||
taosThreadAttrInit(&threadAttr);
|
||||
if (taosThreadCreate(&(tsLogObj.logHandle->asyncThread), &threadAttr, taosAsyncOutputLog, tsLogObj.logHandle) != 0) {
|
||||
return -1;
|
||||
}
|
||||
pthread_attr_destroy(&threadAttr);
|
||||
taosThreadAttrDestroy(&threadAttr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ static void taosStopLog() {
|
|||
void taosCloseLog() {
|
||||
taosStopLog();
|
||||
if (taosCheckPthreadValid(tsLogObj.logHandle->asyncThread)) {
|
||||
pthread_join(tsLogObj.logHandle->asyncThread, NULL);
|
||||
taosThreadJoin(tsLogObj.logHandle->asyncThread, NULL);
|
||||
}
|
||||
// In case that other threads still use log resources causing invalid write in valgrind
|
||||
// we comment two lines below.
|
||||
|
@ -223,22 +223,22 @@ static void *taosThreadToOpenNewFile(void *param) {
|
|||
}
|
||||
|
||||
static int32_t taosOpenNewLogFile() {
|
||||
pthread_mutex_lock(&tsLogObj.logMutex);
|
||||
taosThreadMutexLock(&tsLogObj.logMutex);
|
||||
|
||||
if (tsLogObj.lines > tsLogObj.maxLines && tsLogObj.openInProgress == 0) {
|
||||
tsLogObj.openInProgress = 1;
|
||||
|
||||
uInfo("open new log file ......");
|
||||
pthread_t thread;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
TdThread thread;
|
||||
TdThreadAttr attr;
|
||||
taosThreadAttrInit(&attr);
|
||||
taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_DETACHED);
|
||||
|
||||
pthread_create(&thread, &attr, taosThreadToOpenNewFile, NULL);
|
||||
pthread_attr_destroy(&attr);
|
||||
taosThreadCreate(&thread, &attr, taosThreadToOpenNewFile, NULL);
|
||||
taosThreadAttrDestroy(&attr);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsLogObj.logMutex);
|
||||
taosThreadMutexUnlock(&tsLogObj.logMutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
|
|||
|
||||
char fileName[LOG_FILE_NAME_LEN + 50] = "\0";
|
||||
sprintf(fileName, "%s.%d", tsLogObj.logName, tsLogObj.flag);
|
||||
pthread_mutex_init(&tsLogObj.logMutex, NULL);
|
||||
taosThreadMutexInit(&tsLogObj.logMutex, NULL);
|
||||
|
||||
taosUmaskFile(0);
|
||||
tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CTEATE | TD_FILE_WRITE);
|
||||
|
@ -517,7 +517,7 @@ static SLogBuff *taosLogBuffNew(int32_t bufSize) {
|
|||
tLogBuff->minBuffSize = bufSize / 10;
|
||||
tLogBuff->stop = 0;
|
||||
|
||||
if (pthread_mutex_init(&LOG_BUF_MUTEX(tLogBuff), NULL) < 0) goto _err;
|
||||
if (taosThreadMutexInit(&LOG_BUF_MUTEX(tLogBuff), NULL) < 0) goto _err;
|
||||
// tsem_init(&(tLogBuff->buffNotEmpty), 0, 0);
|
||||
|
||||
return tLogBuff;
|
||||
|
@ -552,7 +552,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
|
|||
|
||||
if (tLogBuff == NULL || tLogBuff->stop) return -1;
|
||||
|
||||
pthread_mutex_lock(&LOG_BUF_MUTEX(tLogBuff));
|
||||
taosThreadMutexLock(&LOG_BUF_MUTEX(tLogBuff));
|
||||
start = LOG_BUF_START(tLogBuff);
|
||||
end = LOG_BUF_END(tLogBuff);
|
||||
|
||||
|
@ -566,7 +566,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
|
|||
if (remainSize <= msgLen || ((lostLine > 0) && (remainSize <= (msgLen + tmpBufLen)))) {
|
||||
lostLine++;
|
||||
tsAsyncLogLostLines++;
|
||||
pthread_mutex_unlock(&LOG_BUF_MUTEX(tLogBuff));
|
||||
taosThreadMutexUnlock(&LOG_BUF_MUTEX(tLogBuff));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -587,7 +587,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
|
|||
}
|
||||
*/
|
||||
|
||||
pthread_mutex_unlock(&LOG_BUF_MUTEX(tLogBuff));
|
||||
taosThreadMutexUnlock(&LOG_BUF_MUTEX(tLogBuff));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ typedef struct {
|
|||
int32_t blockSize; /* block size in bytes */
|
||||
int32_t *freeList; /* the index list */
|
||||
char *pool; /* the actual mem block */
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} pool_t;
|
||||
|
||||
mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) {
|
||||
|
@ -58,7 +58,7 @@ mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_init(&(pool_p->mutex), NULL);
|
||||
taosThreadMutexInit(&(pool_p->mutex), NULL);
|
||||
|
||||
memset(pool_p->pool, 0, (size_t)(blockSize * numOfBlock));
|
||||
for (i = 0; i < pool_p->numOfBlock; ++i) pool_p->freeList[i] = i;
|
||||
|
@ -73,7 +73,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
|
|||
char *pos = NULL;
|
||||
pool_t *pool_p = (pool_t *)handle;
|
||||
|
||||
pthread_mutex_lock(&(pool_p->mutex));
|
||||
taosThreadMutexLock(&(pool_p->mutex));
|
||||
|
||||
if (pool_p->numOfFree > 0) {
|
||||
pos = pool_p->pool + pool_p->blockSize * (pool_p->freeList[pool_p->first]);
|
||||
|
@ -82,7 +82,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
|
|||
pool_p->numOfFree--;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(pool_p->mutex));
|
||||
taosThreadMutexUnlock(&(pool_p->mutex));
|
||||
|
||||
if (pos == NULL) uDebug("mempool: out of memory");
|
||||
return pos;
|
||||
|
@ -108,18 +108,18 @@ void taosMemPoolFree(mpool_h handle, char *pMem) {
|
|||
|
||||
memset(pMem, 0, (size_t)pool_p->blockSize);
|
||||
|
||||
pthread_mutex_lock(&pool_p->mutex);
|
||||
taosThreadMutexLock(&pool_p->mutex);
|
||||
|
||||
pool_p->freeList[(pool_p->first + pool_p->numOfFree) % pool_p->numOfBlock] = index;
|
||||
pool_p->numOfFree++;
|
||||
|
||||
pthread_mutex_unlock(&pool_p->mutex);
|
||||
taosThreadMutexUnlock(&pool_p->mutex);
|
||||
}
|
||||
|
||||
void taosMemPoolCleanUp(mpool_h handle) {
|
||||
pool_t *pool_p = (pool_t *)handle;
|
||||
|
||||
pthread_mutex_destroy(&pool_p->mutex);
|
||||
taosThreadMutexDestroy(&pool_p->mutex);
|
||||
if (pool_p->pool) free(pool_p->pool);
|
||||
if (pool_p->freeList) free(pool_p->freeList);
|
||||
memset(pool_p, 0, sizeof(*pool_p));
|
||||
|
|
|
@ -37,13 +37,13 @@ typedef struct STaosQueue {
|
|||
void *ahandle; // for queue set
|
||||
FItem itemFp;
|
||||
FItems itemsFp;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
} STaosQueue;
|
||||
|
||||
typedef struct STaosQset {
|
||||
STaosQueue *head;
|
||||
STaosQueue *current;
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
int32_t numOfQueues;
|
||||
int32_t numOfItems;
|
||||
tsem_t sem;
|
||||
|
@ -63,7 +63,7 @@ STaosQueue *taosOpenQueue() {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&queue->mutex, NULL) != 0) {
|
||||
if (taosThreadMutexInit(&queue->mutex, NULL) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -84,11 +84,11 @@ void taosCloseQueue(STaosQueue *queue) {
|
|||
STaosQnode *pTemp;
|
||||
STaosQset *qset;
|
||||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
STaosQnode *pNode = queue->head;
|
||||
queue->head = NULL;
|
||||
qset = queue->qset;
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
|
||||
if (queue->qset) {
|
||||
taosRemoveFromQset(qset, queue);
|
||||
|
@ -100,7 +100,7 @@ void taosCloseQueue(STaosQueue *queue) {
|
|||
free(pTemp);
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&queue->mutex);
|
||||
taosThreadMutexDestroy(&queue->mutex);
|
||||
free(queue);
|
||||
|
||||
uDebug("queue:%p is closed", queue);
|
||||
|
@ -110,19 +110,19 @@ bool taosQueueEmpty(STaosQueue *queue) {
|
|||
if (queue == NULL) return true;
|
||||
|
||||
bool empty = false;
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
if (queue->head == NULL && queue->tail == NULL) {
|
||||
empty = true;
|
||||
}
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
|
||||
return empty;
|
||||
}
|
||||
|
||||
int32_t taosQueueSize(STaosQueue *queue) {
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
int32_t numOfItems = queue->numOfItems;
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
return numOfItems;
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
|
|||
STaosQnode *pNode = (STaosQnode *)(((char *)pItem) - sizeof(STaosQnode));
|
||||
pNode->next = NULL;
|
||||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
|
||||
if (queue->tail) {
|
||||
queue->tail->next = pNode;
|
||||
|
@ -165,7 +165,7 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
|
|||
if (queue->qset) atomic_add_fetch_32(&queue->qset->numOfItems, 1);
|
||||
uTrace("item:%p is put into queue:%p, items:%d", pItem, queue, queue->numOfItems);
|
||||
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
|
||||
if (queue->qset) tsem_post(&queue->qset->sem);
|
||||
|
||||
|
@ -176,7 +176,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
|
|||
STaosQnode *pNode = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
|
||||
if (queue->head) {
|
||||
pNode = queue->head;
|
||||
|
@ -189,7 +189,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
|
|||
uTrace("item:%p is read out from queue:%p, items:%d", *ppItem, queue, queue->numOfItems);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
|
|||
int32_t code = 0;
|
||||
bool empty;
|
||||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
|
||||
empty = queue->head == NULL;
|
||||
if (!empty) {
|
||||
|
@ -219,7 +219,7 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
|
|||
if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
|
||||
// if source queue is empty, we set destination qall to empty too.
|
||||
if (empty) {
|
||||
|
@ -255,7 +255,7 @@ STaosQset *taosOpenQset() {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_init(&qset->mutex, NULL);
|
||||
taosThreadMutexInit(&qset->mutex, NULL);
|
||||
tsem_init(&qset->sem, 0, 0);
|
||||
|
||||
uDebug("qset:%p is opened", qset);
|
||||
|
@ -266,7 +266,7 @@ void taosCloseQset(STaosQset *qset) {
|
|||
if (qset == NULL) return;
|
||||
|
||||
// remove all the queues from qset
|
||||
pthread_mutex_lock(&qset->mutex);
|
||||
taosThreadMutexLock(&qset->mutex);
|
||||
while (qset->head) {
|
||||
STaosQueue *queue = qset->head;
|
||||
qset->head = qset->head->next;
|
||||
|
@ -274,9 +274,9 @@ void taosCloseQset(STaosQset *qset) {
|
|||
queue->qset = NULL;
|
||||
queue->next = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&qset->mutex);
|
||||
taosThreadMutexUnlock(&qset->mutex);
|
||||
|
||||
pthread_mutex_destroy(&qset->mutex);
|
||||
taosThreadMutexDestroy(&qset->mutex);
|
||||
tsem_destroy(&qset->sem);
|
||||
free(qset);
|
||||
uDebug("qset:%p is closed", qset);
|
||||
|
@ -293,19 +293,19 @@ void taosQsetThreadResume(STaosQset *qset) {
|
|||
int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) {
|
||||
if (queue->qset) return -1;
|
||||
|
||||
pthread_mutex_lock(&qset->mutex);
|
||||
taosThreadMutexLock(&qset->mutex);
|
||||
|
||||
queue->next = qset->head;
|
||||
queue->ahandle = ahandle;
|
||||
qset->head = queue;
|
||||
qset->numOfQueues++;
|
||||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
atomic_add_fetch_32(&qset->numOfItems, queue->numOfItems);
|
||||
queue->qset = qset;
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
|
||||
pthread_mutex_unlock(&qset->mutex);
|
||||
taosThreadMutexUnlock(&qset->mutex);
|
||||
|
||||
uTrace("queue:%p is added into qset:%p", queue, qset);
|
||||
return 0;
|
||||
|
@ -314,7 +314,7 @@ int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) {
|
|||
void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) {
|
||||
STaosQueue *tqueue = NULL;
|
||||
|
||||
pthread_mutex_lock(&qset->mutex);
|
||||
taosThreadMutexLock(&qset->mutex);
|
||||
|
||||
if (qset->head) {
|
||||
if (qset->head == queue) {
|
||||
|
@ -339,15 +339,15 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) {
|
|||
if (qset->current == queue) qset->current = tqueue->next;
|
||||
qset->numOfQueues--;
|
||||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
atomic_sub_fetch_32(&qset->numOfItems, queue->numOfItems);
|
||||
queue->qset = NULL;
|
||||
queue->next = NULL;
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&qset->mutex);
|
||||
taosThreadMutexUnlock(&qset->mutex);
|
||||
|
||||
uDebug("queue:%p is removed from qset:%p", queue, qset);
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FI
|
|||
|
||||
tsem_wait(&qset->sem);
|
||||
|
||||
pthread_mutex_lock(&qset->mutex);
|
||||
taosThreadMutexLock(&qset->mutex);
|
||||
|
||||
for (int32_t i = 0; i < qset->numOfQueues; ++i) {
|
||||
if (qset->current == NULL) qset->current = qset->head;
|
||||
|
@ -369,7 +369,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FI
|
|||
if (queue == NULL) break;
|
||||
if (queue->head == NULL) continue;
|
||||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
|
||||
if (queue->head) {
|
||||
pNode = queue->head;
|
||||
|
@ -385,11 +385,11 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FI
|
|||
uTrace("item:%p is read out from queue:%p, items:%d", *ppItem, queue, queue->numOfItems);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
if (pNode) break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&qset->mutex);
|
||||
taosThreadMutexUnlock(&qset->mutex);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
|
|||
int32_t code = 0;
|
||||
|
||||
tsem_wait(&qset->sem);
|
||||
pthread_mutex_lock(&qset->mutex);
|
||||
taosThreadMutexLock(&qset->mutex);
|
||||
|
||||
for (int32_t i = 0; i < qset->numOfQueues; ++i) {
|
||||
if (qset->current == NULL) qset->current = qset->head;
|
||||
|
@ -408,7 +408,7 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
|
|||
if (queue == NULL) break;
|
||||
if (queue->head == NULL) continue;
|
||||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
|
||||
if (queue->head) {
|
||||
qall->current = queue->head;
|
||||
|
@ -428,12 +428,12 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
|
|||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
|
||||
if (code != 0) break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&qset->mutex);
|
||||
taosThreadMutexUnlock(&qset->mutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -443,7 +443,7 @@ int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **aha
|
|||
|
||||
tsem_wait(&qset->sem);
|
||||
|
||||
pthread_mutex_lock(&qset->mutex);
|
||||
taosThreadMutexLock(&qset->mutex);
|
||||
|
||||
for (int32_t i = 0; i < qset->numOfQueues; ++i) {
|
||||
if (qset->current == NULL) qset->current = qset->head;
|
||||
|
@ -456,7 +456,7 @@ int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **aha
|
|||
continue;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
|
||||
if (queue->head) {
|
||||
pNode = queue->head;
|
||||
|
@ -475,11 +475,11 @@ int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **aha
|
|||
uTrace("item:%p is read out from queue:%p, items:%d", *ppItem, queue, queue->numOfItems);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
if (pNode) break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&qset->mutex);
|
||||
taosThreadMutexUnlock(&qset->mutex);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -488,21 +488,21 @@ void taosResetQsetThread(STaosQset *qset, void *pItem) {
|
|||
if (pItem == NULL) return;
|
||||
STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode));
|
||||
|
||||
pthread_mutex_lock(&qset->mutex);
|
||||
taosThreadMutexLock(&qset->mutex);
|
||||
pNode->queue->threadId = -1;
|
||||
for (int32_t i = 0; i < pNode->queue->numOfItems; ++i) {
|
||||
tsem_post(&qset->sem);
|
||||
}
|
||||
pthread_mutex_unlock(&qset->mutex);
|
||||
taosThreadMutexUnlock(&qset->mutex);
|
||||
}
|
||||
|
||||
int32_t taosGetQueueItemsNumber(STaosQueue *queue) {
|
||||
if (!queue) return 0;
|
||||
|
||||
int32_t num;
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
taosThreadMutexLock(&queue->mutex);
|
||||
num = queue->numOfItems;
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
return num;
|
||||
}
|
||||
|
||||
|
@ -510,8 +510,8 @@ int32_t taosGetQsetItemsNumber(STaosQset *qset) {
|
|||
if (!qset) return 0;
|
||||
|
||||
int32_t num = 0;
|
||||
pthread_mutex_lock(&qset->mutex);
|
||||
taosThreadMutexLock(&qset->mutex);
|
||||
num = qset->numOfItems;
|
||||
pthread_mutex_unlock(&qset->mutex);
|
||||
taosThreadMutexUnlock(&qset->mutex);
|
||||
return num;
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ typedef struct {
|
|||
} SRefSet;
|
||||
|
||||
static SRefSet tsRefSetList[TSDB_REF_OBJECTS];
|
||||
static pthread_once_t tsRefModuleInit = PTHREAD_ONCE_INIT;
|
||||
static pthread_mutex_t tsRefMutex;
|
||||
static TdThreadOnce tsRefModuleInit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadMutex tsRefMutex;
|
||||
static int32_t tsRefSetNum = 0;
|
||||
static int32_t tsNextId = 0;
|
||||
|
||||
|
@ -63,7 +63,7 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) {
|
|||
int64_t *lockedBy;
|
||||
int32_t i, rsetId;
|
||||
|
||||
pthread_once(&tsRefModuleInit, taosInitRefModule);
|
||||
taosThreadOnce(&tsRefModuleInit, taosInitRefModule);
|
||||
|
||||
nodeList = calloc(sizeof(SRefNode *), (size_t)max);
|
||||
if (nodeList == NULL) {
|
||||
|
@ -78,7 +78,7 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&tsRefMutex);
|
||||
taosThreadMutexLock(&tsRefMutex);
|
||||
|
||||
for (i = 0; i < TSDB_REF_OBJECTS; ++i) {
|
||||
tsNextId = (tsNextId + 1) % TSDB_REF_OBJECTS;
|
||||
|
@ -107,7 +107,7 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) {
|
|||
uTrace("run out of Ref ID, maximum:%d refSetNum:%d", TSDB_REF_OBJECTS, tsRefSetNum);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsRefMutex);
|
||||
taosThreadMutexUnlock(&tsRefMutex);
|
||||
|
||||
return rsetId;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ int32_t taosCloseRef(int32_t rsetId) {
|
|||
|
||||
pSet = tsRefSetList + rsetId;
|
||||
|
||||
pthread_mutex_lock(&tsRefMutex);
|
||||
taosThreadMutexLock(&tsRefMutex);
|
||||
|
||||
if (pSet->state == TSDB_REF_STATE_ACTIVE) {
|
||||
pSet->state = TSDB_REF_STATE_DELETED;
|
||||
|
@ -134,7 +134,7 @@ int32_t taosCloseRef(int32_t rsetId) {
|
|||
uTrace("rsetId:%d is already closed, count:%d", rsetId, pSet->count);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsRefMutex);
|
||||
taosThreadMutexUnlock(&tsRefMutex);
|
||||
|
||||
if (deleted) taosDecRsetCount(pSet);
|
||||
|
||||
|
@ -354,7 +354,7 @@ int32_t taosListRef() {
|
|||
SRefNode *pNode;
|
||||
int32_t num = 0;
|
||||
|
||||
pthread_mutex_lock(&tsRefMutex);
|
||||
taosThreadMutexLock(&tsRefMutex);
|
||||
|
||||
for (int32_t i = 0; i < TSDB_REF_OBJECTS; ++i) {
|
||||
pSet = tsRefSetList + i;
|
||||
|
@ -374,7 +374,7 @@ int32_t taosListRef() {
|
|||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsRefMutex);
|
||||
taosThreadMutexUnlock(&tsRefMutex);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ static void taosUnlockList(int64_t *lockedBy) {
|
|||
}
|
||||
}
|
||||
|
||||
static void taosInitRefModule(void) { pthread_mutex_init(&tsRefMutex, NULL); }
|
||||
static void taosInitRefModule(void) { taosThreadMutexInit(&tsRefMutex, NULL); }
|
||||
|
||||
static void taosIncRsetCount(SRefSet *pSet) {
|
||||
atomic_add_fetch_32(&pSet->count, 1);
|
||||
|
@ -483,7 +483,7 @@ static void taosDecRsetCount(SRefSet *pSet) {
|
|||
|
||||
if (count > 0) return;
|
||||
|
||||
pthread_mutex_lock(&tsRefMutex);
|
||||
taosThreadMutexLock(&tsRefMutex);
|
||||
|
||||
if (pSet->state != TSDB_REF_STATE_EMPTY) {
|
||||
pSet->state = TSDB_REF_STATE_EMPTY;
|
||||
|
@ -497,5 +497,5 @@ static void taosDecRsetCount(SRefSet *pSet) {
|
|||
uTrace("rsetId:%d is cleaned, refSetNum:%d count:%d", pSet->rsetId, tsRefSetNum, pSet->count);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsRefMutex);
|
||||
taosThreadMutexUnlock(&tsRefMutex);
|
||||
}
|
||||
|
|
|
@ -26,12 +26,12 @@ typedef struct {
|
|||
char label[TSDB_LABEL_LEN];
|
||||
tsem_t emptySem;
|
||||
tsem_t fullSem;
|
||||
pthread_mutex_t queueMutex;
|
||||
TdThreadMutex queueMutex;
|
||||
int32_t fullSlot;
|
||||
int32_t emptySlot;
|
||||
int32_t queueSize;
|
||||
int32_t numOfThreads;
|
||||
pthread_t *qthread;
|
||||
TdThread *qthread;
|
||||
SSchedMsg *queue;
|
||||
bool stop;
|
||||
void *pTmrCtrl;
|
||||
|
@ -55,7 +55,7 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pSched->qthread = calloc(sizeof(pthread_t), numOfThreads);
|
||||
pSched->qthread = calloc(sizeof(TdThread), numOfThreads);
|
||||
if (pSched->qthread == NULL) {
|
||||
uError("%s: no enough memory for qthread", label);
|
||||
taosCleanUpScheduler(pSched);
|
||||
|
@ -68,7 +68,7 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
|
|||
pSched->fullSlot = 0;
|
||||
pSched->emptySlot = 0;
|
||||
|
||||
if (pthread_mutex_init(&pSched->queueMutex, NULL) < 0) {
|
||||
if (taosThreadMutexInit(&pSched->queueMutex, NULL) < 0) {
|
||||
uError("init %s:queueMutex failed(%s)", label, strerror(errno));
|
||||
taosCleanUpScheduler(pSched);
|
||||
return NULL;
|
||||
|
@ -88,11 +88,11 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
|
|||
|
||||
pSched->stop = false;
|
||||
for (int32_t i = 0; i < numOfThreads; ++i) {
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
int32_t code = pthread_create(pSched->qthread + i, &attr, taosProcessSchedQueue, (void *)pSched);
|
||||
pthread_attr_destroy(&attr);
|
||||
TdThreadAttr attr;
|
||||
taosThreadAttrInit(&attr);
|
||||
taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
int32_t code = taosThreadCreate(pSched->qthread + i, &attr, taosProcessSchedQueue, (void *)pSched);
|
||||
taosThreadAttrDestroy(&attr);
|
||||
if (code != 0) {
|
||||
uError("%s: failed to create rpc thread(%s)", label, strerror(errno));
|
||||
taosCleanUpScheduler(pSched);
|
||||
|
@ -135,7 +135,7 @@ void *taosProcessSchedQueue(void *scheduler) {
|
|||
break;
|
||||
}
|
||||
|
||||
if ((ret = pthread_mutex_lock(&pSched->queueMutex)) != 0) {
|
||||
if ((ret = taosThreadMutexLock(&pSched->queueMutex)) != 0) {
|
||||
uFatal("lock %s queueMutex failed(%s)", pSched->label, strerror(errno));
|
||||
exit(ret);
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ void *taosProcessSchedQueue(void *scheduler) {
|
|||
memset(pSched->queue + pSched->fullSlot, 0, sizeof(SSchedMsg));
|
||||
pSched->fullSlot = (pSched->fullSlot + 1) % pSched->queueSize;
|
||||
|
||||
if ((ret = pthread_mutex_unlock(&pSched->queueMutex)) != 0) {
|
||||
if ((ret = taosThreadMutexUnlock(&pSched->queueMutex)) != 0) {
|
||||
uFatal("unlock %s queueMutex failed(%s)", pSched->label, strerror(errno));
|
||||
exit(ret);
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) {
|
|||
exit(ret);
|
||||
}
|
||||
|
||||
if ((ret = pthread_mutex_lock(&pSched->queueMutex)) != 0) {
|
||||
if ((ret = taosThreadMutexLock(&pSched->queueMutex)) != 0) {
|
||||
uFatal("lock %s queueMutex failed(%s)", pSched->label, strerror(errno));
|
||||
exit(ret);
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) {
|
|||
pSched->queue[pSched->emptySlot] = *pMsg;
|
||||
pSched->emptySlot = (pSched->emptySlot + 1) % pSched->queueSize;
|
||||
|
||||
if ((ret = pthread_mutex_unlock(&pSched->queueMutex)) != 0) {
|
||||
if ((ret = taosThreadMutexUnlock(&pSched->queueMutex)) != 0) {
|
||||
uFatal("unlock %s queueMutex failed(%s)", pSched->label, strerror(errno));
|
||||
exit(ret);
|
||||
}
|
||||
|
@ -208,13 +208,13 @@ void taosCleanUpScheduler(void *param) {
|
|||
}
|
||||
for (int32_t i = 0; i < pSched->numOfThreads; ++i) {
|
||||
if (taosCheckPthreadValid(pSched->qthread[i])) {
|
||||
pthread_join(pSched->qthread[i], NULL);
|
||||
taosThreadJoin(pSched->qthread[i], NULL);
|
||||
}
|
||||
}
|
||||
|
||||
tsem_destroy(&pSched->emptySem);
|
||||
tsem_destroy(&pSched->fullSem);
|
||||
pthread_mutex_destroy(&pSched->queueMutex);
|
||||
taosThreadMutexDestroy(&pSched->queueMutex);
|
||||
|
||||
if (pSched->pTimer) {
|
||||
taosTmrStopA(&pSched->pTimer);
|
||||
|
|
|
@ -70,13 +70,13 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
|
|||
}
|
||||
|
||||
if (SL_IS_THREAD_SAFE(pSkipList)) {
|
||||
pSkipList->lock = (pthread_rwlock_t *)calloc(1, sizeof(pthread_rwlock_t));
|
||||
pSkipList->lock = (TdThreadRwlock *)calloc(1, sizeof(TdThreadRwlock));
|
||||
if (pSkipList->lock == NULL) {
|
||||
tSkipListDestroy(pSkipList);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pthread_rwlock_init(pSkipList->lock, NULL) != 0) {
|
||||
if (taosThreadRwlockInit(pSkipList->lock, NULL) != 0) {
|
||||
tSkipListDestroy(pSkipList);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ void tSkipListDestroy(SSkipList *pSkipList) {
|
|||
|
||||
tSkipListUnlock(pSkipList);
|
||||
if (pSkipList->lock != NULL) {
|
||||
pthread_rwlock_destroy(pSkipList->lock);
|
||||
taosThreadRwlockDestroy(pSkipList->lock);
|
||||
tfree(pSkipList->lock);
|
||||
}
|
||||
|
||||
|
@ -435,21 +435,21 @@ static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t
|
|||
|
||||
static FORCE_INLINE int32_t tSkipListWLock(SSkipList *pSkipList) {
|
||||
if (pSkipList->lock) {
|
||||
return pthread_rwlock_wrlock(pSkipList->lock);
|
||||
return taosThreadRwlockWrlock(pSkipList->lock);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tSkipListRLock(SSkipList *pSkipList) {
|
||||
if (pSkipList->lock) {
|
||||
return pthread_rwlock_rdlock(pSkipList->lock);
|
||||
return taosThreadRwlockRdlock(pSkipList->lock);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tSkipListUnlock(SSkipList *pSkipList) {
|
||||
if (pSkipList->lock) {
|
||||
return pthread_rwlock_unlock(pSkipList->lock);
|
||||
return taosThreadRwlockUnlock(pSkipList->lock);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "tthread.h"
|
||||
|
||||
pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param) {
|
||||
pthread_t* pthread = (pthread_t*)malloc(sizeof(pthread_t));
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
int32_t ret = pthread_create(pthread, &thattr, __start_routine, param);
|
||||
pthread_attr_destroy(&thattr);
|
||||
TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param) {
|
||||
TdThread* pthread = (TdThread*)malloc(sizeof(TdThread));
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
int32_t ret = taosThreadCreate(pthread, &thattr, __start_routine, param);
|
||||
taosThreadAttrDestroy(&thattr);
|
||||
|
||||
if (ret != 0) {
|
||||
free(pthread);
|
||||
|
@ -31,20 +31,20 @@ pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param) {
|
|||
return pthread;
|
||||
}
|
||||
|
||||
bool taosDestoryThread(pthread_t* pthread) {
|
||||
bool taosDestoryThread(TdThread* pthread) {
|
||||
if (pthread == NULL) return false;
|
||||
if (taosThreadRunning(pthread)) {
|
||||
pthread_cancel(*pthread);
|
||||
pthread_join(*pthread, NULL);
|
||||
taosThreadCancel(*pthread);
|
||||
taosThreadJoin(*pthread, NULL);
|
||||
}
|
||||
|
||||
free(pthread);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool taosThreadRunning(pthread_t* pthread) {
|
||||
bool taosThreadRunning(TdThread* pthread) {
|
||||
if (pthread == NULL) return false;
|
||||
int32_t ret = pthread_kill(*pthread, 0);
|
||||
int32_t ret = taosThreadKill(*pthread, 0);
|
||||
if (ret == ESRCH) return false;
|
||||
if (ret == EINVAL) return false;
|
||||
// alive
|
||||
|
|
|
@ -102,7 +102,7 @@ typedef struct timer_map_t {
|
|||
} timer_map_t;
|
||||
|
||||
typedef struct time_wheel_t {
|
||||
pthread_mutex_t mutex;
|
||||
TdThreadMutex mutex;
|
||||
int64_t nextScanAt;
|
||||
uint32_t resolution;
|
||||
uint16_t size;
|
||||
|
@ -112,8 +112,8 @@ typedef struct time_wheel_t {
|
|||
|
||||
int32_t tsMaxTmrCtrl = 512;
|
||||
|
||||
static pthread_once_t tmrModuleInit = PTHREAD_ONCE_INIT;
|
||||
static pthread_mutex_t tmrCtrlMutex;
|
||||
static TdThreadOnce tmrModuleInit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadMutex tmrCtrlMutex;
|
||||
static tmr_ctrl_t* tmrCtrls;
|
||||
static tmr_ctrl_t* unusedTmrCtrl = NULL;
|
||||
static void* tmrQhandle;
|
||||
|
@ -230,7 +230,7 @@ static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
|
|||
timer->prev = NULL;
|
||||
timer->expireAt = taosGetMonotonicMs() + delay;
|
||||
|
||||
pthread_mutex_lock(&wheel->mutex);
|
||||
taosThreadMutexLock(&wheel->mutex);
|
||||
|
||||
uint32_t idx = 0;
|
||||
if (timer->expireAt > wheel->nextScanAt) {
|
||||
|
@ -248,7 +248,7 @@ static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
|
|||
p->prev = timer;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&wheel->mutex);
|
||||
taosThreadMutexUnlock(&wheel->mutex);
|
||||
}
|
||||
|
||||
static bool removeFromWheel(tmr_obj_t* timer) {
|
||||
|
@ -259,7 +259,7 @@ static bool removeFromWheel(tmr_obj_t* timer) {
|
|||
time_wheel_t* wheel = wheels + wheelIdx;
|
||||
|
||||
bool removed = false;
|
||||
pthread_mutex_lock(&wheel->mutex);
|
||||
taosThreadMutexLock(&wheel->mutex);
|
||||
// other thread may modify timer->wheel, check again.
|
||||
if (timer->wheel < tListLen(wheels)) {
|
||||
if (timer->prev != NULL) {
|
||||
|
@ -277,7 +277,7 @@ static bool removeFromWheel(tmr_obj_t* timer) {
|
|||
timerDecRef(timer);
|
||||
removed = true;
|
||||
}
|
||||
pthread_mutex_unlock(&wheel->mutex);
|
||||
taosThreadMutexUnlock(&wheel->mutex);
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ static void taosTimerLoopFunc(int32_t signo) {
|
|||
|
||||
time_wheel_t* wheel = wheels + i;
|
||||
while (now >= wheel->nextScanAt) {
|
||||
pthread_mutex_lock(&wheel->mutex);
|
||||
taosThreadMutexLock(&wheel->mutex);
|
||||
wheel->index = (wheel->index + 1) % wheel->size;
|
||||
tmr_obj_t* timer = wheel->slots[wheel->index];
|
||||
while (timer != NULL) {
|
||||
|
@ -407,7 +407,7 @@ static void taosTimerLoopFunc(int32_t signo) {
|
|||
timer = next;
|
||||
}
|
||||
wheel->nextScanAt += wheel->resolution;
|
||||
pthread_mutex_unlock(&wheel->mutex);
|
||||
taosThreadMutexUnlock(&wheel->mutex);
|
||||
}
|
||||
|
||||
addToExpired(expired);
|
||||
|
@ -528,12 +528,12 @@ static void taosTmrModuleInit(void) {
|
|||
(tmrCtrls + tsMaxTmrCtrl - 1)->next = NULL;
|
||||
unusedTmrCtrl = tmrCtrls;
|
||||
|
||||
pthread_mutex_init(&tmrCtrlMutex, NULL);
|
||||
taosThreadMutexInit(&tmrCtrlMutex, NULL);
|
||||
|
||||
int64_t now = taosGetMonotonicMs();
|
||||
for (int32_t i = 0; i < tListLen(wheels); i++) {
|
||||
time_wheel_t* wheel = wheels + i;
|
||||
if (pthread_mutex_init(&wheel->mutex, NULL) != 0) {
|
||||
if (taosThreadMutexInit(&wheel->mutex, NULL) != 0) {
|
||||
tmrError("failed to create the mutex for wheel, reason:%s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
@ -564,15 +564,15 @@ void* taosTmrInit(int32_t maxNumOfTmrs, int32_t resolution, int32_t longest, con
|
|||
const char* ret = taosMonotonicInit();
|
||||
tmrDebug("ttimer monotonic clock source:%s", ret);
|
||||
|
||||
pthread_once(&tmrModuleInit, taosTmrModuleInit);
|
||||
taosThreadOnce(&tmrModuleInit, taosTmrModuleInit);
|
||||
|
||||
pthread_mutex_lock(&tmrCtrlMutex);
|
||||
taosThreadMutexLock(&tmrCtrlMutex);
|
||||
tmr_ctrl_t* ctrl = unusedTmrCtrl;
|
||||
if (ctrl != NULL) {
|
||||
unusedTmrCtrl = ctrl->next;
|
||||
numOfTmrCtrl++;
|
||||
}
|
||||
pthread_mutex_unlock(&tmrCtrlMutex);
|
||||
taosThreadMutexUnlock(&tmrCtrlMutex);
|
||||
|
||||
if (ctrl == NULL) {
|
||||
tmrError("%s too many timer controllers, failed to create timer controller.", label);
|
||||
|
@ -594,11 +594,11 @@ void taosTmrCleanUp(void* handle) {
|
|||
tmrDebug("%s timer controller is cleaned up.", ctrl->label);
|
||||
ctrl->label[0] = 0;
|
||||
|
||||
pthread_mutex_lock(&tmrCtrlMutex);
|
||||
taosThreadMutexLock(&tmrCtrlMutex);
|
||||
ctrl->next = unusedTmrCtrl;
|
||||
numOfTmrCtrl--;
|
||||
unusedTmrCtrl = ctrl;
|
||||
pthread_mutex_unlock(&tmrCtrlMutex);
|
||||
taosThreadMutexUnlock(&tmrCtrlMutex);
|
||||
|
||||
tmrDebug("time controller's tmr ctrl size: %d", numOfTmrCtrl);
|
||||
if (numOfTmrCtrl <= 0) {
|
||||
|
@ -608,11 +608,11 @@ void taosTmrCleanUp(void* handle) {
|
|||
|
||||
for (int32_t i = 0; i < tListLen(wheels); i++) {
|
||||
time_wheel_t* wheel = wheels + i;
|
||||
pthread_mutex_destroy(&wheel->mutex);
|
||||
taosThreadMutexDestroy(&wheel->mutex);
|
||||
free(wheel->slots);
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&tmrCtrlMutex);
|
||||
taosThreadMutexDestroy(&tmrCtrlMutex);
|
||||
|
||||
for (size_t i = 0; i < timerMap.size; i++) {
|
||||
timer_list_t* list = timerMap.slots + i;
|
||||
|
|
|
@ -28,7 +28,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&pool->mutex, NULL)) {
|
||||
if (taosThreadMutexInit(&pool->mutex, NULL)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -56,13 +56,13 @@ void tQWorkerCleanup(SQWorkerPool *pool) {
|
|||
SQWorker *worker = pool->workers + i;
|
||||
if (worker == NULL) continue;
|
||||
if (taosCheckPthreadValid(worker->thread)) {
|
||||
pthread_join(worker->thread, NULL);
|
||||
taosThreadJoin(worker->thread, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
tfree(pool->workers);
|
||||
taosCloseQset(pool->qset);
|
||||
pthread_mutex_destroy(&pool->mutex);
|
||||
taosThreadMutexDestroy(&pool->mutex);
|
||||
|
||||
uDebug("worker:%s is closed", pool->name);
|
||||
}
|
||||
|
@ -94,10 +94,10 @@ static void *tQWorkerThreadFp(SQWorker *worker) {
|
|||
}
|
||||
|
||||
STaosQueue *tWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp, ThreadFp threadFp) {
|
||||
pthread_mutex_lock(&pool->mutex);
|
||||
taosThreadMutexLock(&pool->mutex);
|
||||
STaosQueue *queue = taosOpenQueue();
|
||||
if (queue == NULL) {
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -110,11 +110,11 @@ STaosQueue *tWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp, Threa
|
|||
do {
|
||||
SQWorker *worker = pool->workers + pool->num;
|
||||
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&worker->thread, &thAttr, threadFp, worker) != 0) {
|
||||
if (taosThreadCreate(&worker->thread, &thAttr, threadFp, worker) != 0) {
|
||||
uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno));
|
||||
taosCloseQueue(queue);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -122,13 +122,13 @@ STaosQueue *tWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp, Threa
|
|||
break;
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
pool->num++;
|
||||
uDebug("worker:%s:%d is launched, total:%d", pool->name, worker->id, pool->num);
|
||||
} while (pool->num < pool->min);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
uDebug("worker:%s, queue:%p is allocated, ahandle:%p", pool->name, queue, ahandle);
|
||||
|
||||
return queue;
|
||||
|
@ -194,7 +194,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&pool->mutex, NULL) != 0) {
|
||||
if (taosThreadMutexInit(&pool->mutex, NULL) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -224,14 +224,14 @@ void tWWorkerCleanup(SWWorkerPool *pool) {
|
|||
for (int32_t i = 0; i < pool->max; ++i) {
|
||||
SWWorker *worker = pool->workers + i;
|
||||
if (taosCheckPthreadValid(worker->thread)) {
|
||||
pthread_join(worker->thread, NULL);
|
||||
taosThreadJoin(worker->thread, NULL);
|
||||
taosFreeQall(worker->qall);
|
||||
taosCloseQset(worker->qset);
|
||||
}
|
||||
}
|
||||
|
||||
tfree(pool->workers);
|
||||
pthread_mutex_destroy(&pool->mutex);
|
||||
taosThreadMutexDestroy(&pool->mutex);
|
||||
|
||||
uInfo("worker:%s is closed", pool->name);
|
||||
}
|
||||
|
@ -265,12 +265,12 @@ static void *tWWorkerThreadFp(SWWorker *worker) {
|
|||
}
|
||||
|
||||
STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
|
||||
pthread_mutex_lock(&pool->mutex);
|
||||
taosThreadMutexLock(&pool->mutex);
|
||||
SWWorker *worker = pool->workers + pool->nextId;
|
||||
|
||||
STaosQueue *queue = taosOpenQueue();
|
||||
if (queue == NULL) {
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
|
|||
worker->qset = taosOpenQset();
|
||||
if (worker->qset == NULL) {
|
||||
taosCloseQueue(queue);
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -290,15 +290,15 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
|
|||
if (worker->qall == NULL) {
|
||||
taosCloseQset(worker->qset);
|
||||
taosCloseQueue(queue);
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) {
|
||||
if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) {
|
||||
uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno));
|
||||
taosFreeQall(worker->qall);
|
||||
taosCloseQset(worker->qset);
|
||||
|
@ -310,13 +310,13 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
|
|||
pool->nextId = (pool->nextId + 1) % pool->max;
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
} else {
|
||||
taosAddIntoQset(worker->qset, queue, ahandle);
|
||||
pool->nextId = (pool->nextId + 1) % pool->max;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
uDebug("worker:%s, queue:%p is allocated, ahandle:%p", pool->name, queue, ahandle);
|
||||
|
||||
return queue;
|
||||
|
|
|
@ -49,7 +49,7 @@ typedef struct {
|
|||
int64_t startMs;
|
||||
int64_t maxDelay;
|
||||
int64_t minDelay;
|
||||
pthread_t thread;
|
||||
TdThread thread;
|
||||
} SThreadInfo;
|
||||
|
||||
// void parseArgument(int32_t argc, char *argv[]);
|
||||
|
@ -400,9 +400,9 @@ int32_t main(int32_t argc, char *argv[]) {
|
|||
pPrint("%d threads are spawned to create %" PRId64 " tables, offset is %" PRId64 " ", numOfThreads, numOfTables,
|
||||
startOffset);
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
SThreadInfo *pInfo = (SThreadInfo *)calloc(numOfThreads, sizeof(SThreadInfo));
|
||||
|
||||
// int64_t numOfTablesPerThread = numOfTables / numOfThreads;
|
||||
|
@ -430,12 +430,12 @@ int32_t main(int32_t argc, char *argv[]) {
|
|||
pInfo[i].minDelay = INT64_MAX;
|
||||
strcpy(pInfo[i].dbName, dbName);
|
||||
strcpy(pInfo[i].stbName, stbName);
|
||||
pthread_create(&(pInfo[i].thread), &thattr, threadFunc, (void *)(pInfo + i));
|
||||
taosThreadCreate(&(pInfo[i].thread), &thattr, threadFunc, (void *)(pInfo + i));
|
||||
}
|
||||
|
||||
taosMsleep(300);
|
||||
for (int32_t i = 0; i < numOfThreads; i++) {
|
||||
pthread_join(pInfo[i].thread, NULL);
|
||||
taosThreadJoin(pInfo[i].thread, NULL);
|
||||
}
|
||||
|
||||
int64_t maxDelay = 0;
|
||||
|
@ -465,6 +465,6 @@ int32_t main(int32_t argc, char *argv[]) {
|
|||
numOfThreads, NC);
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thattr);
|
||||
taosThreadAttrDestroy(&thattr);
|
||||
free(pInfo);
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ typedef struct _script_t {
|
|||
char *optionBuffer;
|
||||
SCmdLine *lines; // command list
|
||||
SVariable variables[MAX_VAR_LEN];
|
||||
pthread_t bgPid;
|
||||
TdThread bgPid;
|
||||
char auth[128];
|
||||
struct _script_t *bgScripts[MAX_BACKGROUND_SCRIPT_NUM];
|
||||
} SScript;
|
||||
|
|
|
@ -293,7 +293,7 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
|
|||
script->bgScripts[script->bgScriptLen++] = newScript;
|
||||
simInfo("script:%s, start to execute in background,", newScript->fileName);
|
||||
|
||||
if (pthread_create(&newScript->bgPid, NULL, simExecuteScript, (void *)newScript) != 0) {
|
||||
if (taosThreadCreate(&newScript->bgPid, NULL, simExecuteScript, (void *)newScript) != 0) {
|
||||
sprintf(script->error, "lineNum:%d. create background thread failed", script->lines[script->linePos].lineNum);
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
@ -55,7 +55,7 @@ void simFreeScript(SScript *script) {
|
|||
simDebug("script:%s, is background script, set stop flag", bgScript->fileName);
|
||||
bgScript->killed = true;
|
||||
if (taosCheckPthreadValid(bgScript->bgPid)) {
|
||||
pthread_join(bgScript->bgPid, NULL);
|
||||
taosThreadJoin(bgScript->bgPid, NULL);
|
||||
}
|
||||
|
||||
simDebug("script:%s, background thread joined", bgScript->fileName);
|
||||
|
|
|
@ -31,7 +31,7 @@ static int32_t checkedNum = 0;
|
|||
static int32_t errorNum = 0;
|
||||
|
||||
typedef struct {
|
||||
pthread_t threadID;
|
||||
TdThread threadID;
|
||||
int threadIndex;
|
||||
int totalThreads;
|
||||
void * taos;
|
||||
|
@ -152,7 +152,7 @@ static void *shellCheckThreadFp(void *arg) {
|
|||
}
|
||||
|
||||
static void shellRunCheckThreads(TAOS *con, SShellArguments *_args) {
|
||||
pthread_attr_t thattr;
|
||||
TdThreadAttr thattr;
|
||||
ShellThreadObj *threadObj = (ShellThreadObj *)calloc(_args->threadNum, sizeof(ShellThreadObj));
|
||||
for (int t = 0; t < _args->threadNum; ++t) {
|
||||
ShellThreadObj *pThread = threadObj + t;
|
||||
|
@ -161,17 +161,17 @@ static void shellRunCheckThreads(TAOS *con, SShellArguments *_args) {
|
|||
pThread->taos = con;
|
||||
pThread->db = _args->database;
|
||||
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&(pThread->threadID), &thattr, shellCheckThreadFp, (void *)pThread) != 0) {
|
||||
if (taosThreadCreate(&(pThread->threadID), &thattr, shellCheckThreadFp, (void *)pThread) != 0) {
|
||||
fprintf(stderr, "ERROR: thread:%d failed to start\n", pThread->threadIndex);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int t = 0; t < _args->threadNum; ++t) {
|
||||
pthread_join(threadObj[t].threadID, NULL);
|
||||
taosThreadJoin(threadObj[t].threadID, NULL);
|
||||
}
|
||||
|
||||
for (int t = 0; t < _args->threadNum; ++t) {
|
||||
|
|
|
@ -365,7 +365,7 @@ void *shellLoopQuery(void *arg) {
|
|||
|
||||
setThreadName("shellLoopQuery");
|
||||
|
||||
pthread_cleanup_push(cleanup_handler, NULL);
|
||||
taosThreadCleanupPush(cleanup_handler, NULL);
|
||||
|
||||
char *command = malloc(MAX_COMMAND_SIZE);
|
||||
if (command == NULL){
|
||||
|
@ -389,7 +389,7 @@ void *shellLoopQuery(void *arg) {
|
|||
tfree(command);
|
||||
exitShell();
|
||||
|
||||
pthread_cleanup_pop(1);
|
||||
taosThreadCleanupPop(1);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ static int32_t shellSQLFileNum = 0;
|
|||
static char shellTablesSQLFile[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
typedef struct {
|
||||
pthread_t threadID;
|
||||
TdThread threadID;
|
||||
int threadIndex;
|
||||
int totalThreads;
|
||||
void *taos;
|
||||
|
@ -232,7 +232,7 @@ void* shellImportThreadFp(void *arg)
|
|||
|
||||
static void shellRunImportThreads(SShellArguments* _args)
|
||||
{
|
||||
pthread_attr_t thattr;
|
||||
TdThreadAttr thattr;
|
||||
ShellThreadObj *threadObj = (ShellThreadObj *)calloc(_args->threadNum, sizeof(ShellThreadObj));
|
||||
for (int t = 0; t < _args->threadNum; ++t) {
|
||||
ShellThreadObj *pThread = threadObj + t;
|
||||
|
@ -244,17 +244,17 @@ static void shellRunImportThreads(SShellArguments* _args)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&(pThread->threadID), &thattr, shellImportThreadFp, (void*)pThread) != 0) {
|
||||
if (taosThreadCreate(&(pThread->threadID), &thattr, shellImportThreadFp, (void*)pThread) != 0) {
|
||||
fprintf(stderr, "ERROR: thread:%d failed to start\n", pThread->threadIndex);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int t = 0; t < _args->threadNum; ++t) {
|
||||
pthread_join(threadObj[t].threadID, NULL);
|
||||
taosThreadJoin(threadObj[t].threadID, NULL);
|
||||
}
|
||||
|
||||
for (int t = 0; t < _args->threadNum; ++t) {
|
||||
|
|
|
@ -519,7 +519,7 @@ static void taosNetTestServer(char *host, int32_t startPort, int32_t pkgLen) {
|
|||
int32_t num = endPort - startPort + 1;
|
||||
if (num < 0) num = 1;
|
||||
|
||||
pthread_t *pids = malloc(2 * num * sizeof(pthread_t));
|
||||
TdThread *pids = malloc(2 * num * sizeof(TdThread));
|
||||
STestInfo *tinfos = malloc(num * sizeof(STestInfo));
|
||||
STestInfo *uinfos = malloc(num * sizeof(STestInfo));
|
||||
|
||||
|
@ -528,7 +528,7 @@ static void taosNetTestServer(char *host, int32_t startPort, int32_t pkgLen) {
|
|||
tcpInfo->port = port + i;
|
||||
tcpInfo->pktLen = pkgLen;
|
||||
|
||||
if (pthread_create(pids + i, NULL, taosNetBindTcpPort, tcpInfo) != 0) {
|
||||
if (taosThreadCreate(pids + i, NULL, taosNetBindTcpPort, tcpInfo) != 0) {
|
||||
uInfo("failed to create TCP test thread, %s:%d", tcpInfo->hostFqdn, tcpInfo->port);
|
||||
exit(-1);
|
||||
}
|
||||
|
@ -536,15 +536,15 @@ static void taosNetTestServer(char *host, int32_t startPort, int32_t pkgLen) {
|
|||
STestInfo *udpInfo = uinfos + i;
|
||||
udpInfo->port = port + i;
|
||||
tcpInfo->pktLen = pkgLen;
|
||||
if (pthread_create(pids + num + i, NULL, taosNetBindUdpPort, udpInfo) != 0) {
|
||||
if (taosThreadCreate(pids + num + i, NULL, taosNetBindUdpPort, udpInfo) != 0) {
|
||||
uInfo("failed to create UDP test thread, %s:%d", tcpInfo->hostFqdn, tcpInfo->port);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < num; i++) {
|
||||
pthread_join(pids[i], NULL);
|
||||
pthread_join(pids[(num + i)], NULL);
|
||||
taosThreadJoin(pids[i], NULL);
|
||||
taosThreadJoin(pids[(num + i)], NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -395,7 +395,7 @@ void *shellLoopQuery(void *arg) {
|
|||
|
||||
setThreadName("shellLoopQuery");
|
||||
|
||||
pthread_cleanup_push(cleanup_handler, NULL);
|
||||
taosThreadCleanupPush(cleanup_handler, NULL);
|
||||
|
||||
char *command = malloc(MAX_COMMAND_SIZE);
|
||||
if (command == NULL){
|
||||
|
@ -419,7 +419,7 @@ void *shellLoopQuery(void *arg) {
|
|||
tfree(command);
|
||||
exitShell();
|
||||
|
||||
pthread_cleanup_pop(1);
|
||||
taosThreadCleanupPop(1);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "shell.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
pthread_t pid;
|
||||
TdThread pid;
|
||||
static tsem_t cancelSem;
|
||||
|
||||
void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) {
|
||||
|
@ -140,8 +140,8 @@ int main(int argc, char *argv[]) {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
pthread_t spid;
|
||||
pthread_create(&spid, NULL, cancelHandler, NULL);
|
||||
TdThread spid;
|
||||
taosThreadCreate(&spid, NULL, cancelHandler, NULL);
|
||||
|
||||
/* Interrupt handler. */
|
||||
taosSetSignal(SIGTERM, shellQueryInterruptHandler);
|
||||
|
@ -154,7 +154,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
/* Loop to query the input. */
|
||||
while (1) {
|
||||
pthread_create(&pid, NULL, shellLoopQuery, con);
|
||||
pthread_join(pid, NULL);
|
||||
taosThreadCreate(&pid, NULL, shellLoopQuery, con);
|
||||
taosThreadJoin(pid, NULL);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue