Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3544df41
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3544df41
编写于
3月 20, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into feature/shm
上级
410982c8
a1d17e37
变更
110
展开全部
隐藏空白更改
内联
并排
Showing
110 changed file
with
994 addition
and
769 deletion
+994
-769
include/libs/wal/wal.h
include/libs/wal/wal.h
+1
-1
include/os/os.h
include/os/os.h
+1
-2
include/os/osSemaphore.h
include/os/osSemaphore.h
+15
-16
include/os/osString.h
include/os/osString.h
+1
-1
include/os/osThread.h
include/os/osThread.h
+88
-0
include/os/osTimezone.h
include/os/osTimezone.h
+5
-0
include/util/tidpool.h
include/util/tidpool.h
+1
-1
include/util/tskiplist.h
include/util/tskiplist.h
+2
-2
include/util/tthread.h
include/util/tthread.h
+3
-3
include/util/tworker.h
include/util/tworker.h
+4
-4
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+4
-4
source/client/src/clientEnv.c
source/client/src/clientEnv.c
+7
-7
source/client/src/clientHb.c
source/client/src/clientHb.c
+14
-14
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+6
-6
source/dnode/mgmt/test/sut/inc/server.h
source/dnode/mgmt/test/sut/inc/server.h
+1
-1
source/dnode/vnode/src/inc/tsdbDef.h
source/dnode/vnode/src/inc/tsdbDef.h
+2
-2
source/dnode/vnode/src/inc/tsdbFS.h
source/dnode/vnode/src/inc/tsdbFS.h
+4
-4
source/dnode/vnode/src/inc/tsdbSma.h
source/dnode/vnode/src/inc/tsdbSma.h
+4
-4
source/dnode/vnode/src/inc/vnd.h
source/dnode/vnode/src/inc/vnd.h
+3
-3
source/dnode/vnode/src/meta/metaBDBImpl.c
source/dnode/vnode/src/meta/metaBDBImpl.c
+6
-6
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+3
-3
source/dnode/vnode/src/tsdb/tsdbMain.c
source/dnode/vnode/src/tsdb/tsdbMain.c
+9
-9
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbSma.c
source/dnode/vnode/src/tsdb/tsdbSma.c
+2
-2
source/dnode/vnode/src/vnd/vnodeBufferPool.c
source/dnode/vnode/src/vnd/vnodeBufferPool.c
+2
-2
source/dnode/vnode/src/vnd/vnodeMgr.c
source/dnode/vnode/src/vnd/vnodeMgr.c
+17
-17
source/dnode/vnode/test/tsdbSmaTest.cpp
source/dnode/vnode/test/tsdbSmaTest.cpp
+1
-1
source/libs/catalog/inc/catalogInt.h
source/libs/catalog/inc/catalogInt.h
+1
-1
source/libs/catalog/src/catalog.c
source/libs/catalog/src/catalog.c
+5
-5
source/libs/catalog/test/catalogTests.cpp
source/libs/catalog/test/catalogTests.cpp
+15
-15
source/libs/executor/inc/dataSinkInt.h
source/libs/executor/inc/dataSinkInt.h
+1
-1
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+1
-1
source/libs/executor/src/dataDispatcher.c
source/libs/executor/src/dataDispatcher.c
+11
-11
source/libs/executor/src/dataSinkMgt.c
source/libs/executor/src/dataSinkMgt.c
+1
-1
source/libs/executor/src/executorMain.c
source/libs/executor/src/executorMain.c
+1
-1
source/libs/function/inc/tscript.h
source/libs/function/inc/tscript.h
+1
-1
source/libs/function/src/functionMgt.c
source/libs/function/src/functionMgt.c
+2
-2
source/libs/function/src/tscript.c
source/libs/function/src/tscript.c
+7
-7
source/libs/index/inc/indexInt.h
source/libs/index/inc/indexInt.h
+1
-1
source/libs/index/inc/index_cache.h
source/libs/index/inc/index_cache.h
+2
-2
source/libs/index/inc/index_fst.h
source/libs/index/inc/index_fst.h
+1
-1
source/libs/index/src/index.c
source/libs/index/src/index.c
+10
-10
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+18
-18
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+6
-6
source/libs/monitor/inc/monInt.h
source/libs/monitor/inc/monInt.h
+1
-1
source/libs/monitor/src/monitor.c
source/libs/monitor/src/monitor.c
+6
-6
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+2
-2
source/libs/qworker/test/qworkerTests.cpp
source/libs/qworker/test/qworkerTests.cpp
+32
-32
source/libs/scheduler/test/schedulerTests.cpp
source/libs/scheduler/test/schedulerTests.cpp
+18
-18
source/libs/sync/inc/syncIO.h
source/libs/sync/inc/syncIO.h
+1
-1
source/libs/sync/src/syncIO.c
source/libs/sync/src/syncIO.c
+2
-2
source/libs/tdb/src/db/tdbPCache.c
source/libs/tdb/src/db/tdbPCache.c
+5
-5
source/libs/tdb/src/inc/tdbPage.h
source/libs/tdb/src/inc/tdbPage.h
+5
-5
source/libs/tfs/inc/tfsInt.h
source/libs/tfs/inc/tfsInt.h
+6
-6
source/libs/tfs/src/tfs.c
source/libs/tfs/src/tfs.c
+2
-2
source/libs/tfs/src/tfsTier.c
source/libs/tfs/src/tfsTier.c
+2
-2
source/libs/transport/inc/transComm.h
source/libs/transport/inc/transComm.h
+1
-1
source/libs/transport/inc/transportInt.h
source/libs/transport/inc/transportInt.h
+1
-1
source/libs/transport/src/rpcCache.c
source/libs/transport/src/rpcCache.c
+7
-7
source/libs/transport/src/rpcMain.c
source/libs/transport/src/rpcMain.c
+8
-8
source/libs/transport/src/rpcTcp.c
source/libs/transport/src/rpcTcp.c
+29
-29
source/libs/transport/src/rpcUdp.c
source/libs/transport/src/rpcUdp.c
+7
-7
source/libs/transport/src/thttp.c
source/libs/transport/src/thttp.c
+4
-2
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+8
-8
source/libs/transport/src/transComm.c
source/libs/transport/src/transComm.c
+4
-4
source/libs/transport/src/transSrv.c
source/libs/transport/src/transSrv.c
+10
-10
source/libs/transport/test/rclient.c
source/libs/transport/test/rclient.c
+5
-5
source/libs/transport/test/rsclient.c
source/libs/transport/test/rsclient.c
+5
-5
source/libs/transport/test/syncClient.c
source/libs/transport/test/syncClient.c
+5
-5
source/libs/transport/test/uv.c
source/libs/transport/test/uv.c
+3
-4
source/libs/wal/src/walMgmt.c
source/libs/wal/src/walMgmt.c
+13
-13
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+9
-9
source/os/src/osFile.c
source/os/src/osFile.c
+16
-16
source/os/src/osSemaphore.c
source/os/src/osSemaphore.c
+33
-34
source/os/src/osSocket.c
source/os/src/osSocket.c
+5
-5
source/os/src/osThread.c
source/os/src/osThread.c
+145
-0
source/os/src/osTimer.c
source/os/src/osTimer.c
+11
-11
source/os/src/osTimezone.c
source/os/src/osTimezone.c
+1
-0
source/util/CMakeLists.txt
source/util/CMakeLists.txt
+0
-4
source/util/src/tcache.c
source/util/src/tcache.c
+30
-30
source/util/src/terror.c
source/util/src/terror.c
+2
-2
source/util/src/tidpool.c
source/util/src/tidpool.c
+14
-14
source/util/src/tlog.c
source/util/src/tlog.c
+21
-21
source/util/src/tmempool.c
source/util/src/tmempool.c
+7
-7
source/util/src/tqueue.c
source/util/src/tqueue.c
+46
-46
source/util/src/tref.c
source/util/src/tref.c
+12
-12
source/util/src/tsched.c
source/util/src/tsched.c
+15
-15
source/util/src/tskiplist.c
source/util/src/tskiplist.c
+6
-6
source/util/src/tthread.c
source/util/src/tthread.c
+12
-12
source/util/src/ttimer.c
source/util/src/ttimer.c
+18
-18
source/util/src/tworker.c
source/util/src/tworker.c
+24
-24
source/util/test/trefTest.c
source/util/test/trefTest.c
+16
-17
tests/script/api/batchprepare.c
tests/script/api/batchprepare.c
+8
-9
tests/script/api/stmtBatchTest.c
tests/script/api/stmtBatchTest.c
+5
-6
tests/script/api/stmtTest.c
tests/script/api/stmtTest.c
+0
-1
tests/script/api/stmt_function.c
tests/script/api/stmt_function.c
+0
-1
tests/script/http/httpTest.c
tests/script/http/httpTest.c
+6
-7
tests/script/http/httpTestSqlUtc.c
tests/script/http/httpTestSqlUtc.c
+6
-7
tests/script/http/httpTestSqlt.c
tests/script/http/httpTestSqlt.c
+6
-7
tests/test/c/create_table.c
tests/test/c/create_table.c
+7
-7
tests/tsim/inc/simInt.h
tests/tsim/inc/simInt.h
+1
-1
tests/tsim/src/simExe.c
tests/tsim/src/simExe.c
+1
-1
tests/tsim/src/simSystem.c
tests/tsim/src/simSystem.c
+1
-1
tools/shell/src/backup/shellCheck.c
tools/shell/src/backup/shellCheck.c
+6
-6
tools/shell/src/backup/shellDarwin.c
tools/shell/src/backup/shellDarwin.c
+2
-2
tools/shell/src/backup/shellImport.c
tools/shell/src/backup/shellImport.c
+6
-6
tools/shell/src/backup/tnettest.c
tools/shell/src/backup/tnettest.c
+5
-5
tools/shell/src/shellLinux.c
tools/shell/src/shellLinux.c
+2
-2
tools/shell/src/shellMain.c
tools/shell/src/shellMain.c
+5
-5
未找到文件。
include/libs/wal/wal.h
浏览文件 @
3544df41
...
@@ -127,7 +127,7 @@ typedef struct SWal {
...
@@ -127,7 +127,7 @@ typedef struct SWal {
int64_t
lastRollSeq
;
int64_t
lastRollSeq
;
// ctl
// ctl
int64_t
refId
;
int64_t
refId
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
// path
// path
char
path
[
WAL_PATH_LEN
];
char
path
[
WAL_PATH_LEN
];
// reusable write head
// reusable write head
...
...
include/os/os.h
浏览文件 @
3544df41
...
@@ -22,7 +22,6 @@ extern "C" {
...
@@ -22,7 +22,6 @@ extern "C" {
#include <assert.h>
#include <assert.h>
#include <ctype.h>
#include <ctype.h>
#include <pthread.h>
#include <semaphore.h>
#include <semaphore.h>
#include <regex.h>
#include <regex.h>
...
@@ -83,6 +82,7 @@ extern "C" {
...
@@ -83,6 +82,7 @@ extern "C" {
#include "osMath.h"
#include "osMath.h"
#include "osMemory.h"
#include "osMemory.h"
#include "osRand.h"
#include "osRand.h"
#include "osThread.h"
#include "osSemaphore.h"
#include "osSemaphore.h"
#include "osSignal.h"
#include "osSignal.h"
#include "osSleep.h"
#include "osSleep.h"
...
@@ -90,7 +90,6 @@ extern "C" {
...
@@ -90,7 +90,6 @@ extern "C" {
#include "osString.h"
#include "osString.h"
#include "osSysinfo.h"
#include "osSysinfo.h"
#include "osSystem.h"
#include "osSystem.h"
#include "osThread.h"
#include "osTime.h"
#include "osTime.h"
#include "osTimer.h"
#include "osTimer.h"
#include "osTimezone.h"
#include "osTimezone.h"
...
...
include/os/osSemaphore.h
浏览文件 @
3544df41
...
@@ -20,7 +20,6 @@
...
@@ -20,7 +20,6 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include <pthread.h>
#include <semaphore.h>
#include <semaphore.h>
#if defined (_TD_DARWIN_64)
#if defined (_TD_DARWIN_64)
...
@@ -38,25 +37,25 @@ extern "C" {
...
@@ -38,25 +37,25 @@ extern "C" {
#endif
#endif
#if defined (_TD_DARWIN_64)
#if defined (_TD_DARWIN_64)
// #define
pthread_rwlock_t pthread_mutex_t
// #define
TdThreadRwlock TdThreadMutex
// #define
pthread_rwlock_init(lock, NULL) pthread_mutex_i
nit(lock, NULL)
// #define
taosThreadRwlockInit(lock, NULL) taosThreadMutexI
nit(lock, NULL)
// #define
pthread_rwlock_destroy(lock) pthread_mutex_d
estroy(lock)
// #define
taosThreadRwlockDestroy(lock) taosThreadMutexD
estroy(lock)
// #define
pthread_rwlock_wrlock(lock) pthread_mutex_l
ock(lock)
// #define
taosThreadRwlockWrlock(lock) taosThreadMutexL
ock(lock)
// #define
pthread_rwlock_rdlock(lock) pthread_mutex_l
ock(lock)
// #define
taosThreadRwlockRdlock(lock) taosThreadMutexL
ock(lock)
// #define
pthread_rwlock_unlock(lock) pthread_mutex_u
nlock(lock)
// #define
taosThreadRwlockUnlock(lock) taosThreadMutexU
nlock(lock)
#define
pthread_spinlock_t pthread_mutex_t
#define
TdThreadSpinlock TdThreadMutex
#define
pthread_spin_init(lock, NULL) pthread_mutex_i
nit(lock, NULL)
#define
taosThreadSpinInit(lock, NULL) taosThreadMutexI
nit(lock, NULL)
#define
pthread_spin_destroy(lock) pthread_mutex_d
estroy(lock)
#define
taosThreadSpinDestroy(lock) taosThreadMutexD
estroy(lock)
#define
pthread_spin_lock(lock) pthread_mutex_l
ock(lock)
#define
taosThreadSpinLock(lock) taosThreadMutexL
ock(lock)
#define
pthread_spin_unlock(lock) pthread_mutex_u
nlock(lock)
#define
taosThreadSpinUnlock(lock) taosThreadMutexU
nlock(lock)
#endif
#endif
bool
taosCheckPthreadValid
(
pthread_t
thread
);
bool
taosCheckPthreadValid
(
TdThread
thread
);
int64_t
taosGetSelfPthreadId
();
int64_t
taosGetSelfPthreadId
();
int64_t
taosGetPthreadId
(
pthread_t
thread
);
int64_t
taosGetPthreadId
(
TdThread
thread
);
void
taosResetPthread
(
pthread_t
*
thread
);
void
taosResetPthread
(
TdThread
*
thread
);
bool
taosComparePthread
(
pthread_t
first
,
pthread_t
second
);
bool
taosComparePthread
(
TdThread
first
,
TdThread
second
);
int32_t
taosGetPId
();
int32_t
taosGetPId
();
int32_t
taosGetAppName
(
char
*
name
,
int32_t
*
len
);
int32_t
taosGetAppName
(
char
*
name
,
int32_t
*
len
);
...
...
include/os/osString.h
浏览文件 @
3544df41
...
@@ -35,7 +35,7 @@ typedef int32_t TdUcs4;
...
@@ -35,7 +35,7 @@ typedef int32_t TdUcs4;
#define wctomb WCTOMB_FUNC_TAOS_FORBID
#define wctomb WCTOMB_FUNC_TAOS_FORBID
#define wcstombs WCSTOMBS_FUNC_TAOS_FORBID
#define wcstombs WCSTOMBS_FUNC_TAOS_FORBID
#define wcsncpy WCSNCPY_FUNC_TAOS_FORBID
#define wcsncpy WCSNCPY_FUNC_TAOS_FORBID
#define wchar_t WCHAR_T_
FUNC
_TAOS_FORBID
#define wchar_t WCHAR_T_
TYPE
_TAOS_FORBID
#endif
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
...
...
include/os/osThread.h
浏览文件 @
3544df41
...
@@ -22,6 +22,94 @@
...
@@ -22,6 +22,94 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
typedef
pthread_t
TdThread
;
typedef
pthread_spinlock_t
TdThreadSpinlock
;
typedef
pthread_mutex_t
TdThreadMutex
;
typedef
pthread_mutexattr_t
TdThreadMutexAttr
;
typedef
pthread_rwlock_t
TdThreadRwlock
;
typedef
pthread_attr_t
TdThreadAttr
;
typedef
pthread_once_t
TdThreadOnce
;
typedef
pthread_rwlockattr_t
TdThreadRwlockAttr
;
typedef
pthread_cond_t
TdThreadCond
;
typedef
pthread_condattr_t
TdThreadCondAttr
;
#define taosThreadCleanupPush pthread_cleanup_push
#define taosThreadCleanupPop pthread_cleanup_pop
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define pthread_t PTHREAD_T_TYPE_TAOS_FORBID
#define pthread_spinlock_t PTHREAD_SPINLOCK_T_TYPE_TAOS_FORBID
#define pthread_mutex_t PTHREAD_MUTEX_T_TYPE_TAOS_FORBID
#define pthread_mutexattr_t PTHREAD_MUTEXATTR_T_TYPE_TAOS_FORBID
#define pthread_rwlock_t PTHREAD_RWLOCK_T_TYPE_TAOS_FORBID
#define pthread_attr_t PTHREAD_ATTR_T_TYPE_TAOS_FORBID
#define pthread_once_t PTHREAD_ONCE_T_TYPE_TAOS_FORBID
#define pthread_rwlockattr_t PTHREAD_RWLOCKATTR_T_TYPE_TAOS_FORBID
#define pthread_cond_t PTHREAD_COND_T_TYPE_TAOS_FORBID
#define pthread_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID
#define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID
#define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID
#define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID
#define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID
#define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID
#define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID
#define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID
#define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID
#define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID
#define pthread_attr_init PTHREAD_ATTR_INIT_FUNC_TAOS_FORBID
#define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID
#define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID
#define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE_FUNC_TAOS_FORBID
#define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID
#define pthread_join PTHREAD_JOIN_FUNC_TAOS_FORBID
#define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID
#define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID
#define pthread_cond_signal PTHREAD_COND_SIGNAL_FUNC_TAOS_FORBID
#define pthread_cond_init PTHREAD_COND_INIT_FUNC_TAOS_FORBID
#define pthread_cond_broadcast PTHREAD_COND_BROADCAST_FUNC_TAOS_FORBID
#define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID
#define pthread_cond_wait PTHREAD_COND_WAIT_FUNC_TAOS_FORBID
#define pthread_self PTHREAD_SELF_FUNC_TAOS_FORBID
#define pthread_equal PTHREAD_EQUAL_FUNC_TAOS_FORBID
#define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID
#define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID
#define pthread_kill PTHREAD_KILL_FUNC_TAOS_FORBID
#endif
int32_t
taosThreadSpinInit
(
TdThreadSpinlock
*
lock
,
int
pshared
);
int32_t
taosThreadMutexInit
(
TdThreadMutex
*
mutex
,
const
TdThreadMutexAttr
*
attr
);
int32_t
taosThreadSpinDestroy
(
TdThreadSpinlock
*
lock
);
int32_t
taosThreadMutexDestroy
(
TdThreadMutex
*
mutex
);
int32_t
taosThreadSpinLock
(
TdThreadSpinlock
*
lock
);
int32_t
taosThreadMutexLock
(
TdThreadMutex
*
mutex
);
int32_t
taosThreadRwlockRdlock
(
TdThreadRwlock
*
rwlock
);
int32_t
taosThreadSpinUnlock
(
TdThreadSpinlock
*
lock
);
int32_t
taosThreadMutexUnlock
(
TdThreadMutex
*
mutex
);
int32_t
taosThreadRwlockWrlock
(
TdThreadRwlock
*
rwlock
);
int32_t
taosThreadRwlockUnlock
(
TdThreadRwlock
*
rwlock
);
void
taosThreadTestCancel
(
void
);
int32_t
taosThreadAttrInit
(
TdThreadAttr
*
attr
);
int32_t
taosThreadCreate
(
TdThread
*
tid
,
const
TdThreadAttr
*
attr
,
void
*
(
*
start
)(
void
*
),
void
*
arg
);
int32_t
taosThreadOnce
(
TdThreadOnce
*
onceControl
,
void
(
*
initRoutine
)(
void
));
int32_t
taosThreadAttrSetDetachState
(
TdThreadAttr
*
attr
,
int32_t
detachState
);
int32_t
taosThreadAttrDestroy
(
TdThreadAttr
*
attr
);
int32_t
taosThreadJoin
(
TdThread
thread
,
void
**
pValue
);
int32_t
taosThreadRwlockInit
(
TdThreadRwlock
*
rwlock
,
const
TdThreadRwlockAttr
*
attr
);
int32_t
taosThreadRwlockDestroy
(
TdThreadRwlock
*
rwlock
);
int32_t
taosThreadCondSignal
(
TdThreadCond
*
cond
);
int32_t
taosThreadCondInit
(
TdThreadCond
*
cond
,
const
TdThreadCondAttr
*
attr
);
int32_t
taosThreadCondBroadcast
(
TdThreadCond
*
cond
);
int32_t
taosThreadCondDestroy
(
TdThreadCond
*
cond
);
int32_t
taosThreadCondWait
(
TdThreadCond
*
cond
,
TdThreadMutex
*
mutex
);
TdThread
taosThreadSelf
(
void
);
int32_t
taosThreadEqual
(
TdThread
t1
,
TdThread
t2
);
int32_t
taosThreadSigmask
(
int
how
,
sigset_t
const
*
set
,
sigset_t
*
oset
);
int32_t
taosThreadCancel
(
TdThread
thread
);
int32_t
taosThreadKill
(
TdThread
thread
,
int
sig
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
include/os/osTimezone.h
浏览文件 @
3544df41
...
@@ -20,6 +20,11 @@
...
@@ -20,6 +20,11 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define tzset TZSET_FUNC_TAOS_FORBID
#endif
void
taosGetSystemTimezone
(
char
*
outTimezone
);
void
taosGetSystemTimezone
(
char
*
outTimezone
);
void
taosSetSystemTimezone
(
const
char
*
inTimezone
,
char
*
outTimezone
,
int8_t
*
outDaylight
);
void
taosSetSystemTimezone
(
const
char
*
inTimezone
,
char
*
outTimezone
,
int8_t
*
outDaylight
);
...
...
include/util/tidpool.h
浏览文件 @
3544df41
...
@@ -27,7 +27,7 @@ typedef struct {
...
@@ -27,7 +27,7 @@ typedef struct {
int32_t
numOfFree
;
int32_t
numOfFree
;
int32_t
freeSlot
;
int32_t
freeSlot
;
bool
*
freeList
;
bool
*
freeList
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
}
id_pool_t
;
}
id_pool_t
;
void
*
taosInitIdPool
(
int32_t
maxId
);
void
*
taosInitIdPool
(
int32_t
maxId
);
...
...
include/util/tskiplist.h
浏览文件 @
3544df41
...
@@ -57,7 +57,7 @@ typedef struct SSkipListNode {
...
@@ -57,7 +57,7 @@ typedef struct SSkipListNode {
* @date 2017/11/12
* @date 2017/11/12
* the simple version of skip list.
* 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.
* 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
* 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.
* this simple version in a multi-thread environment, to achieve higher performance of read/write operations.
...
@@ -106,7 +106,7 @@ typedef struct SSkipList {
...
@@ -106,7 +106,7 @@ typedef struct SSkipList {
uint32_t
seed
;
uint32_t
seed
;
__compar_fn_t
comparFn
;
__compar_fn_t
comparFn
;
__sl_key_fn_t
keyFn
;
__sl_key_fn_t
keyFn
;
pthread_rwlock_t
*
lock
;
TdThreadRwlock
*
lock
;
uint16_t
len
;
uint16_t
len
;
uint8_t
maxLevel
;
uint8_t
maxLevel
;
uint8_t
flags
;
uint8_t
flags
;
...
...
include/util/tthread.h
浏览文件 @
3544df41
...
@@ -22,9 +22,9 @@
...
@@ -22,9 +22,9 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
pthread_t
*
taosCreateThread
(
void
*
(
*
__start_routine
)(
void
*
),
void
*
param
);
TdThread
*
taosCreateThread
(
void
*
(
*
__start_routine
)(
void
*
),
void
*
param
);
bool
taosDestoryThread
(
pthread_t
*
pthread
);
bool
taosDestoryThread
(
TdThread
*
pthread
);
bool
taosThreadRunning
(
pthread_t
*
pthread
);
bool
taosThreadRunning
(
TdThread
*
pthread
);
typedef
void
*
(
*
ThreadFp
)(
void
*
param
);
typedef
void
*
(
*
ThreadFp
)(
void
*
param
);
...
...
include/util/tworker.h
浏览文件 @
3544df41
...
@@ -27,7 +27,7 @@ typedef struct SWWorkerPool SWWorkerPool;
...
@@ -27,7 +27,7 @@ typedef struct SWWorkerPool SWWorkerPool;
typedef
struct
SQWorker
{
typedef
struct
SQWorker
{
int32_t
id
;
// worker ID
int32_t
id
;
// worker ID
pthread_t
thread
;
// thread
TdThread
thread
;
// thread
SQWorkerPool
*
pool
;
SQWorkerPool
*
pool
;
}
SQWorker
,
SFWorker
;
}
SQWorker
,
SFWorker
;
...
@@ -38,12 +38,12 @@ typedef struct SQWorkerPool {
...
@@ -38,12 +38,12 @@ typedef struct SQWorkerPool {
STaosQset
*
qset
;
STaosQset
*
qset
;
const
char
*
name
;
const
char
*
name
;
SQWorker
*
workers
;
SQWorker
*
workers
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
}
SQWorkerPool
,
SFWorkerPool
;
}
SQWorkerPool
,
SFWorkerPool
;
typedef
struct
SWWorker
{
typedef
struct
SWWorker
{
int32_t
id
;
// worker id
int32_t
id
;
// worker id
pthread_t
thread
;
// thread
TdThread
thread
;
// thread
STaosQall
*
qall
;
STaosQall
*
qall
;
STaosQset
*
qset
;
// queue set
STaosQset
*
qset
;
// queue set
SWWorkerPool
*
pool
;
SWWorkerPool
*
pool
;
...
@@ -54,7 +54,7 @@ typedef struct SWWorkerPool {
...
@@ -54,7 +54,7 @@ typedef struct SWWorkerPool {
int32_t
nextId
;
// from 0 to max-1, cyclic
int32_t
nextId
;
// from 0 to max-1, cyclic
const
char
*
name
;
const
char
*
name
;
SWWorker
*
workers
;
SWWorker
*
workers
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
}
SWWorkerPool
;
}
SWWorkerPool
;
int32_t
tQWorkerInit
(
SQWorkerPool
*
pool
);
int32_t
tQWorkerInit
(
SQWorkerPool
*
pool
);
...
...
source/client/inc/clientInt.h
浏览文件 @
3544df41
...
@@ -77,8 +77,8 @@ typedef struct {
...
@@ -77,8 +77,8 @@ typedef struct {
int8_t
inited
;
int8_t
inited
;
// ctl
// ctl
int8_t
threadStop
;
int8_t
threadStop
;
pthread_t
thread
;
TdThread
thread
;
pthread_mutex_t
lock
;
// used when app init and cleanup
TdThreadMutex
lock
;
// used when app init and cleanup
SArray
*
appHbMgrs
;
// SArray<SAppHbMgr*> one for each cluster
SArray
*
appHbMgrs
;
// SArray<SAppHbMgr*> one for each cluster
FHbReqHandle
reqHandle
[
HEARTBEAT_TYPE_MAX
];
FHbReqHandle
reqHandle
[
HEARTBEAT_TYPE_MAX
];
FHbRspHandle
rspHandle
[
HEARTBEAT_TYPE_MAX
];
FHbRspHandle
rspHandle
[
HEARTBEAT_TYPE_MAX
];
...
@@ -125,7 +125,7 @@ typedef struct SAppInfo {
...
@@ -125,7 +125,7 @@ typedef struct SAppInfo {
int32_t
pid
;
int32_t
pid
;
int32_t
numOfThreads
;
int32_t
numOfThreads
;
SHashObj
*
pInstMap
;
SHashObj
*
pInstMap
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
}
SAppInfo
;
}
SAppInfo
;
typedef
struct
STscObj
{
typedef
struct
STscObj
{
...
@@ -137,7 +137,7 @@ typedef struct STscObj {
...
@@ -137,7 +137,7 @@ typedef struct STscObj {
uint32_t
connId
;
uint32_t
connId
;
int32_t
connType
;
int32_t
connType
;
uint64_t
id
;
// ref ID returned by taosAddRef
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
int32_t
numOfReqs
;
// number of sqlObj bound to this connection
SAppInstInfo
*
pAppInfo
;
SAppInstInfo
*
pAppInfo
;
}
STscObj
;
}
STscObj
;
...
...
source/client/src/clientEnv.c
浏览文件 @
3544df41
...
@@ -33,7 +33,7 @@ SAppInfo appInfo;
...
@@ -33,7 +33,7 @@ SAppInfo appInfo;
int32_t
clientReqRefPool
=
-
1
;
int32_t
clientReqRefPool
=
-
1
;
int32_t
clientConnRefPool
=
-
1
;
int32_t
clientConnRefPool
=
-
1
;
static
pthread_once_t
tscinit
=
PTHREAD_ONCE_INIT
;
static
TdThreadOnce
tscinit
=
PTHREAD_ONCE_INIT
;
volatile
int32_t
tscInitRes
=
0
;
volatile
int32_t
tscInitRes
=
0
;
static
void
registerRequest
(
SRequestObj
*
pRequest
)
{
static
void
registerRequest
(
SRequestObj
*
pRequest
)
{
...
@@ -114,7 +114,7 @@ void destroyTscObj(void *pObj) {
...
@@ -114,7 +114,7 @@ void destroyTscObj(void *pObj) {
hbDeregisterConn
(
pTscObj
->
pAppInfo
->
pAppHbMgr
,
connKey
);
hbDeregisterConn
(
pTscObj
->
pAppInfo
->
pAppHbMgr
,
connKey
);
atomic_sub_fetch_64
(
&
pTscObj
->
pAppInfo
->
numOfConns
,
1
);
atomic_sub_fetch_64
(
&
pTscObj
->
pAppInfo
->
numOfConns
,
1
);
tscDebug
(
"connObj 0x%"
PRIx64
" destroyed, totalConn:%"
PRId64
,
pTscObj
->
id
,
pTscObj
->
pAppInfo
->
numOfConns
);
tscDebug
(
"connObj 0x%"
PRIx64
" destroyed, totalConn:%"
PRId64
,
pTscObj
->
id
,
pTscObj
->
pAppInfo
->
numOfConns
);
pthread_mutex_d
estroy
(
&
pTscObj
->
mutex
);
taosThreadMutexD
estroy
(
&
pTscObj
->
mutex
);
tfree
(
pTscObj
);
tfree
(
pTscObj
);
}
}
...
@@ -133,7 +133,7 @@ void *createTscObj(const char *user, const char *auth, const char *db, SAppInstI
...
@@ -133,7 +133,7 @@ void *createTscObj(const char *user, const char *auth, const char *db, SAppInstI
tstrncpy
(
pObj
->
db
,
db
,
tListLen
(
pObj
->
db
));
tstrncpy
(
pObj
->
db
,
db
,
tListLen
(
pObj
->
db
));
}
}
pthread_mutex_i
nit
(
&
pObj
->
mutex
,
NULL
);
taosThreadMutexI
nit
(
&
pObj
->
mutex
,
NULL
);
pObj
->
id
=
taosAddRef
(
clientConnRefPool
,
pObj
);
pObj
->
id
=
taosAddRef
(
clientConnRefPool
,
pObj
);
tscDebug
(
"connObj created, 0x%"
PRIx64
,
pObj
->
id
);
tscDebug
(
"connObj created, 0x%"
PRIx64
,
pObj
->
id
);
...
@@ -242,7 +242,7 @@ void taos_init_imp(void) {
...
@@ -242,7 +242,7 @@ void taos_init_imp(void) {
// transDestroyBuffer(&conn->readBuf);
// transDestroyBuffer(&conn->readBuf);
taosGetAppName
(
appInfo
.
appName
,
NULL
);
taosGetAppName
(
appInfo
.
appName
,
NULL
);
pthread_mutex_i
nit
(
&
appInfo
.
mutex
,
NULL
);
taosThreadMutexI
nit
(
&
appInfo
.
mutex
,
NULL
);
appInfo
.
pid
=
taosGetPId
();
appInfo
.
pid
=
taosGetPId
();
appInfo
.
startTime
=
taosGetTimestampMs
();
appInfo
.
startTime
=
taosGetTimestampMs
();
...
@@ -251,7 +251,7 @@ void taos_init_imp(void) {
...
@@ -251,7 +251,7 @@ void taos_init_imp(void) {
}
}
int
taos_init
()
{
int
taos_init
()
{
pthread_o
nce
(
&
tscinit
,
taos_init_imp
);
taosThreadO
nce
(
&
tscinit
,
taos_init_imp
);
return
tscInitRes
;
return
tscInitRes
;
}
}
...
@@ -507,9 +507,9 @@ static setConfRet taos_set_config_imp(const char *config){
...
@@ -507,9 +507,9 @@ static setConfRet taos_set_config_imp(const char *config){
}
}
setConfRet taos_set_config(const char *config){
setConfRet taos_set_config(const char *config){
pthread_mutex_l
ock(&setConfMutex);
taosThreadMutexL
ock(&setConfMutex);
setConfRet ret = taos_set_config_imp(config);
setConfRet ret = taos_set_config_imp(config);
pthread_mutex_u
nlock(&setConfMutex);
taosThreadMutexU
nlock(&setConfMutex);
return ret;
return ret;
}
}
#endif
#endif
source/client/src/clientHb.c
浏览文件 @
3544df41
...
@@ -372,7 +372,7 @@ static void *hbThreadFunc(void *param) {
...
@@ -372,7 +372,7 @@ static void *hbThreadFunc(void *param) {
break
;
break
;
}
}
pthread_mutex_l
ock
(
&
clientHbMgr
.
lock
);
taosThreadMutexL
ock
(
&
clientHbMgr
.
lock
);
int
sz
=
taosArrayGetSize
(
clientHbMgr
.
appHbMgrs
);
int
sz
=
taosArrayGetSize
(
clientHbMgr
.
appHbMgrs
);
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
...
@@ -423,7 +423,7 @@ static void *hbThreadFunc(void *param) {
...
@@ -423,7 +423,7 @@ static void *hbThreadFunc(void *param) {
atomic_add_fetch_32
(
&
pAppHbMgr
->
reportCnt
,
1
);
atomic_add_fetch_32
(
&
pAppHbMgr
->
reportCnt
,
1
);
}
}
pthread_mutex_u
nlock
(
&
clientHbMgr
.
lock
);
taosThreadMutexU
nlock
(
&
clientHbMgr
.
lock
);
taosMsleep
(
HEARTBEAT_INTERVAL
);
taosMsleep
(
HEARTBEAT_INTERVAL
);
}
}
...
@@ -431,15 +431,15 @@ static void *hbThreadFunc(void *param) {
...
@@ -431,15 +431,15 @@ static void *hbThreadFunc(void *param) {
}
}
static
int32_t
hbCreateThread
()
{
static
int32_t
hbCreateThread
()
{
pthread_attr_t
thAttr
;
TdThreadAttr
thAttr
;
pthread_attr_i
nit
(
&
thAttr
);
taosThreadAttrI
nit
(
&
thAttr
);
pthread_attr_setdetachs
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
// if (
pthread_c
reate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
// if (
taosThreadC
reate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
// terrno = TAOS_SYSTEM_ERROR(errno);
// terrno = TAOS_SYSTEM_ERROR(errno);
// return -1;
// return -1;
// }
// }
//
pthread_attr_d
estroy(&thAttr);
//
taosThreadAttrD
estroy(&thAttr);
return
0
;
return
0
;
}
}
...
@@ -492,15 +492,15 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
...
@@ -492,15 +492,15 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
return
NULL
;
return
NULL
;
}
}
pthread_mutex_l
ock
(
&
clientHbMgr
.
lock
);
taosThreadMutexL
ock
(
&
clientHbMgr
.
lock
);
taosArrayPush
(
clientHbMgr
.
appHbMgrs
,
&
pAppHbMgr
);
taosArrayPush
(
clientHbMgr
.
appHbMgrs
,
&
pAppHbMgr
);
pthread_mutex_u
nlock
(
&
clientHbMgr
.
lock
);
taosThreadMutexU
nlock
(
&
clientHbMgr
.
lock
);
return
pAppHbMgr
;
return
pAppHbMgr
;
}
}
void
appHbMgrCleanup
(
void
)
{
void
appHbMgrCleanup
(
void
)
{
pthread_mutex_l
ock
(
&
clientHbMgr
.
lock
);
taosThreadMutexL
ock
(
&
clientHbMgr
.
lock
);
int
sz
=
taosArrayGetSize
(
clientHbMgr
.
appHbMgrs
);
int
sz
=
taosArrayGetSize
(
clientHbMgr
.
appHbMgrs
);
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
...
@@ -511,7 +511,7 @@ void appHbMgrCleanup(void) {
...
@@ -511,7 +511,7 @@ void appHbMgrCleanup(void) {
pTarget
->
connInfo
=
NULL
;
pTarget
->
connInfo
=
NULL
;
}
}
pthread_mutex_u
nlock
(
&
clientHbMgr
.
lock
);
taosThreadMutexU
nlock
(
&
clientHbMgr
.
lock
);
}
}
int
hbMgrInit
()
{
int
hbMgrInit
()
{
...
@@ -520,7 +520,7 @@ int hbMgrInit() {
...
@@ -520,7 +520,7 @@ int hbMgrInit() {
if
(
old
==
1
)
return
0
;
if
(
old
==
1
)
return
0
;
clientHbMgr
.
appHbMgrs
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
clientHbMgr
.
appHbMgrs
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
pthread_mutex_i
nit
(
&
clientHbMgr
.
lock
,
NULL
);
taosThreadMutexI
nit
(
&
clientHbMgr
.
lock
,
NULL
);
// init handle funcs
// init handle funcs
hbMgrInitHandle
();
hbMgrInitHandle
();
...
@@ -539,10 +539,10 @@ void hbMgrCleanUp() {
...
@@ -539,10 +539,10 @@ void hbMgrCleanUp() {
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
if (old == 0) return;
if (old == 0) return;
pthread_mutex_l
ock(&clientHbMgr.lock);
taosThreadMutexL
ock(&clientHbMgr.lock);
appHbMgrCleanup();
appHbMgrCleanup();
taosArrayDestroy(clientHbMgr.appHbMgrs);
taosArrayDestroy(clientHbMgr.appHbMgrs);
pthread_mutex_u
nlock(&clientHbMgr.lock);
taosThreadMutexU
nlock(&clientHbMgr.lock);
clientHbMgr.appHbMgrs = NULL;
clientHbMgr.appHbMgrs = NULL;
#endif
#endif
...
...
source/client/src/clientImpl.c
浏览文件 @
3544df41
...
@@ -95,7 +95,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
...
@@ -95,7 +95,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
char
*
key
=
getClusterKey
(
user
,
secretEncrypt
,
ip
,
port
);
char
*
key
=
getClusterKey
(
user
,
secretEncrypt
,
ip
,
port
);
SAppInstInfo
**
pInst
=
NULL
;
SAppInstInfo
**
pInst
=
NULL
;
pthread_mutex_l
ock
(
&
appInfo
.
mutex
);
taosThreadMutexL
ock
(
&
appInfo
.
mutex
);
pInst
=
taosHashGet
(
appInfo
.
pInstMap
,
key
,
strlen
(
key
));
pInst
=
taosHashGet
(
appInfo
.
pInstMap
,
key
,
strlen
(
key
));
SAppInstInfo
*
p
=
NULL
;
SAppInstInfo
*
p
=
NULL
;
...
@@ -109,7 +109,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
...
@@ -109,7 +109,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
pInst
=
&
p
;
pInst
=
&
p
;
}
}
pthread_mutex_u
nlock
(
&
appInfo
.
mutex
);
taosThreadMutexU
nlock
(
&
appInfo
.
mutex
);
tfree
(
key
);
tfree
(
key
);
return
taosConnectImpl
(
user
,
&
secretEncrypt
[
0
],
localDb
,
NULL
,
NULL
,
*
pInst
);
return
taosConnectImpl
(
user
,
&
secretEncrypt
[
0
],
localDb
,
NULL
,
NULL
,
*
pInst
);
...
@@ -591,21 +591,21 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t
...
@@ -591,21 +591,21 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t
char
*
getDbOfConnection
(
STscObj
*
pObj
)
{
char
*
getDbOfConnection
(
STscObj
*
pObj
)
{
char
*
p
=
NULL
;
char
*
p
=
NULL
;
pthread_mutex_l
ock
(
&
pObj
->
mutex
);
taosThreadMutexL
ock
(
&
pObj
->
mutex
);
size_t
len
=
strlen
(
pObj
->
db
);
size_t
len
=
strlen
(
pObj
->
db
);
if
(
len
>
0
)
{
if
(
len
>
0
)
{
p
=
strndup
(
pObj
->
db
,
tListLen
(
pObj
->
db
));
p
=
strndup
(
pObj
->
db
,
tListLen
(
pObj
->
db
));
}
}
pthread_mutex_u
nlock
(
&
pObj
->
mutex
);
taosThreadMutexU
nlock
(
&
pObj
->
mutex
);
return
p
;
return
p
;
}
}
void
setConnectionDB
(
STscObj
*
pTscObj
,
const
char
*
db
)
{
void
setConnectionDB
(
STscObj
*
pTscObj
,
const
char
*
db
)
{
assert
(
db
!=
NULL
&&
pTscObj
!=
NULL
);
assert
(
db
!=
NULL
&&
pTscObj
!=
NULL
);
pthread_mutex_l
ock
(
&
pTscObj
->
mutex
);
taosThreadMutexL
ock
(
&
pTscObj
->
mutex
);
tstrncpy
(
pTscObj
->
db
,
db
,
tListLen
(
pTscObj
->
db
));
tstrncpy
(
pTscObj
->
db
,
db
,
tListLen
(
pTscObj
->
db
));
pthread_mutex_u
nlock
(
&
pTscObj
->
mutex
);
taosThreadMutexU
nlock
(
&
pTscObj
->
mutex
);
}
}
void
setQueryResultFromRsp
(
SReqResultInfo
*
pResultInfo
,
const
SRetrieveTableRsp
*
pRsp
)
{
void
setQueryResultFromRsp
(
SReqResultInfo
*
pResultInfo
,
const
SRetrieveTableRsp
*
pRsp
)
{
...
...
source/dnode/mgmt/test/sut/inc/server.h
浏览文件 @
3544df41
...
@@ -28,7 +28,7 @@ class TestServer {
...
@@ -28,7 +28,7 @@ class TestServer {
private:
private:
SDnode
*
pDnode
;
SDnode
*
pDnode
;
pthread_t
threadId
;
TdThread
*
threadId
;
char
path
[
PATH_MAX
];
char
path
[
PATH_MAX
];
char
fqdn
[
TSDB_FQDN_LEN
];
char
fqdn
[
TSDB_FQDN_LEN
];
char
firstEp
[
TSDB_EP_LEN
];
char
firstEp
[
TSDB_EP_LEN
];
...
...
source/dnode/vnode/src/inc/tsdbDef.h
浏览文件 @
3544df41
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#ifndef _TD_TSDB_DEF_H_
#ifndef _TD_TSDB_DEF_H_
#define _TD_TSDB_DEF_H_
#define _TD_TSDB_DEF_H_
#include "tsdbDBDef.h"
#include "tmallocator.h"
#include "tmallocator.h"
#include "meta.h"
#include "meta.h"
#include "tcompression.h"
#include "tcompression.h"
...
@@ -27,7 +28,6 @@
...
@@ -27,7 +28,6 @@
#include "ttime.h"
#include "ttime.h"
#include "tsdb.h"
#include "tsdb.h"
#include "tsdbDBDef.h"
#include "tsdbCommit.h"
#include "tsdbCommit.h"
#include "tsdbFS.h"
#include "tsdbFS.h"
#include "tsdbFile.h"
#include "tsdbFile.h"
...
@@ -46,7 +46,7 @@ extern "C" {
...
@@ -46,7 +46,7 @@ extern "C" {
struct
STsdb
{
struct
STsdb
{
int32_t
vgId
;
int32_t
vgId
;
bool
repoLocked
;
bool
repoLocked
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
char
*
path
;
char
*
path
;
STsdbCfg
config
;
STsdbCfg
config
;
STsdbMemTable
*
mem
;
STsdbMemTable
*
mem
;
...
...
source/dnode/vnode/src/inc/tsdbFS.h
浏览文件 @
3544df41
...
@@ -64,7 +64,7 @@ typedef struct {
...
@@ -64,7 +64,7 @@ typedef struct {
*/
*/
typedef
struct
{
typedef
struct
{
pthread_rwlock_t
lock
;
TdThreadRwlock
lock
;
SFSStatus
*
cstatus
;
// current status
SFSStatus
*
cstatus
;
// current status
SHashObj
*
metaCache
;
// meta cache
SHashObj
*
metaCache
;
// meta cache
...
@@ -108,7 +108,7 @@ SDFileSet *tsdbFSIterNext(SFSIter *pIter);
...
@@ -108,7 +108,7 @@ SDFileSet *tsdbFSIterNext(SFSIter *pIter);
int
tsdbLoadMetaCache
(
STsdb
*
pRepo
,
bool
recoverMeta
);
int
tsdbLoadMetaCache
(
STsdb
*
pRepo
,
bool
recoverMeta
);
static
FORCE_INLINE
int
tsdbRLockFS
(
STsdbFS
*
pFs
)
{
static
FORCE_INLINE
int
tsdbRLockFS
(
STsdbFS
*
pFs
)
{
int
code
=
pthread_rwlock_r
dlock
(
&
(
pFs
->
lock
));
int
code
=
taosThreadRwlockR
dlock
(
&
(
pFs
->
lock
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
return
-
1
;
...
@@ -117,7 +117,7 @@ static FORCE_INLINE int tsdbRLockFS(STsdbFS *pFs) {
...
@@ -117,7 +117,7 @@ static FORCE_INLINE int tsdbRLockFS(STsdbFS *pFs) {
}
}
static
FORCE_INLINE
int
tsdbWLockFS
(
STsdbFS
*
pFs
)
{
static
FORCE_INLINE
int
tsdbWLockFS
(
STsdbFS
*
pFs
)
{
int
code
=
pthread_rwlock_w
rlock
(
&
(
pFs
->
lock
));
int
code
=
taosThreadRwlockW
rlock
(
&
(
pFs
->
lock
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
return
-
1
;
...
@@ -126,7 +126,7 @@ static FORCE_INLINE int tsdbWLockFS(STsdbFS *pFs) {
...
@@ -126,7 +126,7 @@ static FORCE_INLINE int tsdbWLockFS(STsdbFS *pFs) {
}
}
static
FORCE_INLINE
int
tsdbUnLockFS
(
STsdbFS
*
pFs
)
{
static
FORCE_INLINE
int
tsdbUnLockFS
(
STsdbFS
*
pFs
)
{
int
code
=
pthread_rwlock_u
nlock
(
&
(
pFs
->
lock
));
int
code
=
taosThreadRwlockU
nlock
(
&
(
pFs
->
lock
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
return
-
1
;
...
...
source/dnode/vnode/src/inc/tsdbSma.h
浏览文件 @
3544df41
...
@@ -20,7 +20,7 @@ typedef struct SSmaStat SSmaStat;
...
@@ -20,7 +20,7 @@ typedef struct SSmaStat SSmaStat;
typedef
struct
SSmaEnv
SSmaEnv
;
typedef
struct
SSmaEnv
SSmaEnv
;
struct
SSmaEnv
{
struct
SSmaEnv
{
pthread_rwlock_t
lock
;
TdThreadRwlock
lock
;
SDiskID
did
;
SDiskID
did
;
TDBEnv
dbEnv
;
// TODO: If it's better to put it in smaIndex level?
TDBEnv
dbEnv
;
// TODO: If it's better to put it in smaIndex level?
char
*
path
;
// relative path
char
*
path
;
// relative path
...
@@ -51,7 +51,7 @@ static FORCE_INLINE int32_t tsdbEncodeTSmaKey(tb_uid_t tableUid, col_id_t colId,
...
@@ -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
)
{
static
FORCE_INLINE
int
tsdbRLockSma
(
SSmaEnv
*
pEnv
)
{
int
code
=
pthread_rwlock_r
dlock
(
&
(
pEnv
->
lock
));
int
code
=
taosThreadRwlockR
dlock
(
&
(
pEnv
->
lock
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
return
-
1
;
...
@@ -60,7 +60,7 @@ static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
...
@@ -60,7 +60,7 @@ static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
}
}
static
FORCE_INLINE
int
tsdbWLockSma
(
SSmaEnv
*
pEnv
)
{
static
FORCE_INLINE
int
tsdbWLockSma
(
SSmaEnv
*
pEnv
)
{
int
code
=
pthread_rwlock_w
rlock
(
&
(
pEnv
->
lock
));
int
code
=
taosThreadRwlockW
rlock
(
&
(
pEnv
->
lock
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
return
-
1
;
...
@@ -69,7 +69,7 @@ static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
...
@@ -69,7 +69,7 @@ static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
}
}
static
FORCE_INLINE
int
tsdbUnLockSma
(
SSmaEnv
*
pEnv
)
{
static
FORCE_INLINE
int
tsdbUnLockSma
(
SSmaEnv
*
pEnv
)
{
int
code
=
pthread_rwlock_u
nlock
(
&
(
pEnv
->
lock
));
int
code
=
taosThreadRwlockU
nlock
(
&
(
pEnv
->
lock
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
return
-
1
;
...
...
source/dnode/vnode/src/inc/vnd.h
浏览文件 @
3544df41
...
@@ -48,9 +48,9 @@ typedef struct SVnodeMgr {
...
@@ -48,9 +48,9 @@ typedef struct SVnodeMgr {
// For commit
// For commit
bool
stop
;
bool
stop
;
uint16_t
nthreads
;
uint16_t
nthreads
;
pthread_t
*
threads
;
TdThread
*
threads
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
pthread_cond_t
hasTask
;
TdThreadCond
hasTask
;
TD_DLIST
(
SVnodeTask
)
queue
;
TD_DLIST
(
SVnodeTask
)
queue
;
// For vnode Mgmt
// For vnode Mgmt
PutToQueueFp
putToQueryQFp
;
PutToQueueFp
putToQueryQFp
;
...
...
source/dnode/vnode/src/meta/metaBDBImpl.c
浏览文件 @
3544df41
...
@@ -33,7 +33,7 @@ typedef struct {
...
@@ -33,7 +33,7 @@ typedef struct {
struct
SMetaDB
{
struct
SMetaDB
{
#if IMPL_WITH_LOCK
#if IMPL_WITH_LOCK
pthread_rwlock_t
rwlock
;
TdThreadRwlock
rwlock
;
#endif
#endif
// DB
// DB
DB
*
pTbDB
;
DB
*
pTbDB
;
...
@@ -317,7 +317,7 @@ static SMetaDB *metaNewDB() {
...
@@ -317,7 +317,7 @@ static SMetaDB *metaNewDB() {
}
}
#if IMPL_WITH_LOCK
#if IMPL_WITH_LOCK
pthread_rwlock_i
nit
(
&
pDB
->
rwlock
,
NULL
);
taosThreadRwlockI
nit
(
&
pDB
->
rwlock
,
NULL
);
#endif
#endif
return
pDB
;
return
pDB
;
...
@@ -326,7 +326,7 @@ static SMetaDB *metaNewDB() {
...
@@ -326,7 +326,7 @@ static SMetaDB *metaNewDB() {
static
void
metaFreeDB
(
SMetaDB
*
pDB
)
{
static
void
metaFreeDB
(
SMetaDB
*
pDB
)
{
if
(
pDB
)
{
if
(
pDB
)
{
#if IMPL_WITH_LOCK
#if IMPL_WITH_LOCK
pthread_rwlock_d
estroy
(
&
pDB
->
rwlock
);
taosThreadRwlockD
estroy
(
&
pDB
->
rwlock
);
#endif
#endif
free
(
pDB
);
free
(
pDB
);
}
}
...
@@ -965,18 +965,18 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
...
@@ -965,18 +965,18 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
static
void
metaDBWLock
(
SMetaDB
*
pDB
)
{
static
void
metaDBWLock
(
SMetaDB
*
pDB
)
{
#if IMPL_WITH_LOCK
#if IMPL_WITH_LOCK
pthread_rwlock_w
rlock
(
&
(
pDB
->
rwlock
));
taosThreadRwlockW
rlock
(
&
(
pDB
->
rwlock
));
#endif
#endif
}
}
static
void
metaDBRLock
(
SMetaDB
*
pDB
)
{
static
void
metaDBRLock
(
SMetaDB
*
pDB
)
{
#if IMPL_WITH_LOCK
#if IMPL_WITH_LOCK
pthread_rwlock_r
dlock
(
&
(
pDB
->
rwlock
));
taosThreadRwlockR
dlock
(
&
(
pDB
->
rwlock
));
#endif
#endif
}
}
static
void
metaDBULock
(
SMetaDB
*
pDB
)
{
static
void
metaDBULock
(
SMetaDB
*
pDB
)
{
#if IMPL_WITH_LOCK
#if IMPL_WITH_LOCK
pthread_rwlock_u
nlock
(
&
(
pDB
->
rwlock
));
taosThreadRwlockU
nlock
(
&
(
pDB
->
rwlock
));
#endif
#endif
}
}
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
3544df41
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
*/
*/
#include <regex.h>
#include <regex.h>
#include "os.h"
#include "tsdbDef.h"
#include "tsdbDef.h"
#include "os.h"
typedef
enum
{
TSDB_TXN_TEMP_FILE
=
0
,
TSDB_TXN_CURR_FILE
}
TSDB_TXN_FILE_T
;
typedef
enum
{
TSDB_TXN_TEMP_FILE
=
0
,
TSDB_TXN_CURR_FILE
}
TSDB_TXN_FILE_T
;
static
const
char
*
tsdbTxnFname
[]
=
{
"current.t"
,
"current"
};
static
const
char
*
tsdbTxnFname
[]
=
{
"current.t"
,
"current"
};
...
@@ -203,7 +203,7 @@ STsdbFS *tsdbNewFS(const STsdbCfg *pCfg) {
...
@@ -203,7 +203,7 @@ STsdbFS *tsdbNewFS(const STsdbCfg *pCfg) {
return
NULL
;
return
NULL
;
}
}
int
code
=
pthread_rwlock_i
nit
(
&
(
pfs
->
lock
),
NULL
);
int
code
=
taosThreadRwlockI
nit
(
&
(
pfs
->
lock
),
NULL
);
if
(
code
)
{
if
(
code
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
free
(
pfs
);
free
(
pfs
);
...
@@ -241,7 +241,7 @@ void *tsdbFreeFS(STsdbFS *pfs) {
...
@@ -241,7 +241,7 @@ void *tsdbFreeFS(STsdbFS *pfs) {
taosHashCleanup
(
pfs
->
metaCache
);
taosHashCleanup
(
pfs
->
metaCache
);
pfs
->
metaCache
=
NULL
;
pfs
->
metaCache
=
NULL
;
pfs
->
cstatus
=
tsdbFreeFSStatus
(
pfs
->
cstatus
);
pfs
->
cstatus
=
tsdbFreeFSStatus
(
pfs
->
cstatus
);
pthread_rwlock_d
estroy
(
&
(
pfs
->
lock
));
taosThreadRwlockD
estroy
(
&
(
pfs
->
lock
));
free
(
pfs
);
free
(
pfs
);
}
}
...
...
source/dnode/vnode/src/tsdb/tsdbMain.c
浏览文件 @
3544df41
...
@@ -110,7 +110,7 @@ static void tsdbCloseImpl(STsdb *pTsdb) {
...
@@ -110,7 +110,7 @@ static void tsdbCloseImpl(STsdb *pTsdb) {
}
}
int
tsdbLockRepo
(
STsdb
*
pTsdb
)
{
int
tsdbLockRepo
(
STsdb
*
pTsdb
)
{
int
code
=
pthread_mutex_l
ock
(
&
pTsdb
->
mutex
);
int
code
=
taosThreadMutexL
ock
(
&
pTsdb
->
mutex
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to lock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
tsdbError
(
"vgId:%d failed to lock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
...
@@ -123,7 +123,7 @@ int tsdbLockRepo(STsdb *pTsdb) {
...
@@ -123,7 +123,7 @@ int tsdbLockRepo(STsdb *pTsdb) {
int
tsdbUnlockRepo
(
STsdb
*
pTsdb
)
{
int
tsdbUnlockRepo
(
STsdb
*
pTsdb
)
{
ASSERT
(
IS_REPO_LOCKED
(
pTsdb
));
ASSERT
(
IS_REPO_LOCKED
(
pTsdb
));
pTsdb
->
repoLocked
=
false
;
pTsdb
->
repoLocked
=
false
;
int
code
=
pthread_mutex_u
nlock
(
&
pTsdb
->
mutex
);
int
code
=
taosThreadMutexU
nlock
(
&
pTsdb
->
mutex
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to unlock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
tsdbError
(
"vgId:%d failed to unlock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
...
@@ -298,7 +298,7 @@ STsdbCfg *tsdbGetCfg(const STsdbRepo *repo) {
...
@@ -298,7 +298,7 @@ STsdbCfg *tsdbGetCfg(const STsdbRepo *repo) {
}
}
int tsdbLockRepo(STsdbRepo *pRepo) {
int tsdbLockRepo(STsdbRepo *pRepo) {
int code =
pthread_mutex_l
ock(&pRepo->mutex);
int code =
taosThreadMutexL
ock(&pRepo->mutex);
if (code != 0) {
if (code != 0) {
tsdbError("vgId:%d failed to lock tsdb since %s", REPO_ID(pRepo), strerror(errno));
tsdbError("vgId:%d failed to lock tsdb since %s", REPO_ID(pRepo), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
terrno = TAOS_SYSTEM_ERROR(code);
...
@@ -311,7 +311,7 @@ int tsdbLockRepo(STsdbRepo *pRepo) {
...
@@ -311,7 +311,7 @@ int tsdbLockRepo(STsdbRepo *pRepo) {
int tsdbUnlockRepo(STsdbRepo *pRepo) {
int tsdbUnlockRepo(STsdbRepo *pRepo) {
ASSERT(IS_REPO_LOCKED(pRepo));
ASSERT(IS_REPO_LOCKED(pRepo));
pRepo->repoLocked = false;
pRepo->repoLocked = false;
int code =
pthread_mutex_u
nlock(&pRepo->mutex);
int code =
taosThreadMutexU
nlock(&pRepo->mutex);
if (code != 0) {
if (code != 0) {
tsdbError("vgId:%d failed to unlock tsdb since %s", REPO_ID(pRepo), strerror(errno));
tsdbError("vgId:%d failed to unlock tsdb since %s", REPO_ID(pRepo), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
terrno = TAOS_SYSTEM_ERROR(code);
...
@@ -388,7 +388,7 @@ int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg) {
...
@@ -388,7 +388,7 @@ int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg) {
tsdbError("vgId:%d no config changed", REPO_ID(repo));
tsdbError("vgId:%d no config changed", REPO_ID(repo));
}
}
int code =
pthread_mutex_l
ock(&repo->save_mutex);
int code =
taosThreadMutexL
ock(&repo->save_mutex);
if (code != 0) {
if (code != 0) {
tsdbError("vgId:%d failed to lock tsdb save config mutex since %s", REPO_ID(repo), strerror(errno));
tsdbError("vgId:%d failed to lock tsdb save config mutex since %s", REPO_ID(repo), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
terrno = TAOS_SYSTEM_ERROR(code);
...
@@ -416,7 +416,7 @@ int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg) {
...
@@ -416,7 +416,7 @@ int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg) {
repo->config_changed = true;
repo->config_changed = true;
pthread_mutex_u
nlock(&repo->save_mutex);
taosThreadMutexU
nlock(&repo->save_mutex);
// schedule a commit msg and wait for the new config applied
// schedule a commit msg and wait for the new config applied
tsdbSyncCommitConfig(repo);
tsdbSyncCommitConfig(repo);
...
@@ -690,14 +690,14 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) {
...
@@ -690,14 +690,14 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) {
pRepo->repoLocked = false;
pRepo->repoLocked = false;
pRepo->pthread = NULL;
pRepo->pthread = NULL;
int code =
pthread_mutex_i
nit(&(pRepo->mutex), NULL);
int code =
taosThreadMutexI
nit(&(pRepo->mutex), NULL);
if (code != 0) {
if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code);
terrno = TAOS_SYSTEM_ERROR(code);
tsdbFreeRepo(pRepo);
tsdbFreeRepo(pRepo);
return NULL;
return NULL;
}
}
code =
pthread_mutex_i
nit(&(pRepo->save_mutex), NULL);
code =
taosThreadMutexI
nit(&(pRepo->save_mutex), NULL);
if (code != 0) {
if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code);
terrno = TAOS_SYSTEM_ERROR(code);
tsdbFreeRepo(pRepo);
tsdbFreeRepo(pRepo);
...
@@ -747,7 +747,7 @@ static void tsdbFreeRepo(STsdbRepo *pRepo) {
...
@@ -747,7 +747,7 @@ static void tsdbFreeRepo(STsdbRepo *pRepo) {
// tsdbFreeMemTable(pRepo->mem);
// tsdbFreeMemTable(pRepo->mem);
// tsdbFreeMemTable(pRepo->imem);
// tsdbFreeMemTable(pRepo->imem);
tsem_destroy(&(pRepo->readyToCommit));
tsem_destroy(&(pRepo->readyToCommit));
pthread_mutex_d
estroy(&pRepo->mutex);
taosThreadMutexD
estroy(&pRepo->mutex);
free(pRepo);
free(pRepo);
}
}
}
}
...
...
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
3544df41
...
@@ -541,7 +541,7 @@ int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
...
@@ -541,7 +541,7 @@ int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
}
}
}
}
if (addNew) {
if (addNew) {
int code =
pthread_cond_s
ignal(&pBufPool->poolNotEmpty);
int code =
taosThreadCondS
ignal(&pBufPool->poolNotEmpty);
if (code != 0) {
if (code != 0) {
if (tsdbUnlockRepo(pRepo) < 0) return -1;
if (tsdbUnlockRepo(pRepo) < 0) return -1;
tsdbError("vgId:%d failed to signal pool not empty since %s", REPO_ID(pRepo), strerror(code));
tsdbError("vgId:%d failed to signal pool not empty since %s", REPO_ID(pRepo), strerror(code));
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
3544df41
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "tsdbDef.h"
#include <tdatablock.h>
#include <tdatablock.h>
#include "os.h"
#include "os.h"
#include "talgo.h"
#include "talgo.h"
...
@@ -20,7 +21,6 @@
...
@@ -20,7 +21,6 @@
#include "tdataformat.h"
#include "tdataformat.h"
#include "texception.h"
#include "texception.h"
#include "tsdb.h"
#include "tsdb.h"
#include "tsdbDef.h"
#include "tsdbFS.h"
#include "tsdbFS.h"
#include "tsdbLog.h"
#include "tsdbLog.h"
#include "tsdbReadImpl.h"
#include "tsdbReadImpl.h"
...
...
source/dnode/vnode/src/tsdb/tsdbSma.c
浏览文件 @
3544df41
...
@@ -124,7 +124,7 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
...
@@ -124,7 +124,7 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
return
NULL
;
return
NULL
;
}
}
int
code
=
pthread_rwlock_i
nit
(
&
(
pEnv
->
lock
),
NULL
);
int
code
=
taosThreadRwlockI
nit
(
&
(
pEnv
->
lock
),
NULL
);
if
(
code
)
{
if
(
code
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
free
(
pEnv
);
free
(
pEnv
);
...
@@ -181,7 +181,7 @@ void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
...
@@ -181,7 +181,7 @@ void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
tsdbDestroySmaState
(
pSmaEnv
->
pStat
);
tsdbDestroySmaState
(
pSmaEnv
->
pStat
);
tfree
(
pSmaEnv
->
pStat
);
tfree
(
pSmaEnv
->
pStat
);
tfree
(
pSmaEnv
->
path
);
tfree
(
pSmaEnv
->
path
);
pthread_rwlock_d
estroy
(
&
(
pSmaEnv
->
lock
));
taosThreadRwlockD
estroy
(
&
(
pSmaEnv
->
lock
));
tsdbCloseBDBEnv
(
pSmaEnv
->
dbEnv
);
tsdbCloseBDBEnv
(
pSmaEnv
->
dbEnv
);
}
}
}
}
...
...
source/dnode/vnode/src/vnd/vnodeBufferPool.c
浏览文件 @
3544df41
...
@@ -19,8 +19,8 @@
...
@@ -19,8 +19,8 @@
#define VNODE_BUF_POOL_SHARDS 3
#define VNODE_BUF_POOL_SHARDS 3
struct
SVBufPool
{
struct
SVBufPool
{
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
pthread_cond_t
hasFree
;
TdThreadCond
hasFree
;
TD_DLIST
(
SVMemAllocator
)
free
;
TD_DLIST
(
SVMemAllocator
)
free
;
TD_DLIST
(
SVMemAllocator
)
incycle
;
TD_DLIST
(
SVMemAllocator
)
incycle
;
SVMemAllocator
*
inuse
;
SVMemAllocator
*
inuse
;
...
...
source/dnode/vnode/src/vnd/vnodeMgr.c
浏览文件 @
3544df41
...
@@ -31,17 +31,17 @@ int vnodeInit(const SVnodeOpt *pOption) {
...
@@ -31,17 +31,17 @@ int vnodeInit(const SVnodeOpt *pOption) {
// Start commit handers
// Start commit handers
if
(
pOption
->
nthreads
>
0
)
{
if
(
pOption
->
nthreads
>
0
)
{
vnodeMgr
.
nthreads
=
pOption
->
nthreads
;
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
)
{
if
(
vnodeMgr
.
threads
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
pthread_mutex_i
nit
(
&
(
vnodeMgr
.
mutex
),
NULL
);
taosThreadMutexI
nit
(
&
(
vnodeMgr
.
mutex
),
NULL
);
pthread_cond_i
nit
(
&
(
vnodeMgr
.
hasTask
),
NULL
);
taosThreadCondI
nit
(
&
(
vnodeMgr
.
hasTask
),
NULL
);
TD_DLIST_INIT
(
&
(
vnodeMgr
.
queue
));
TD_DLIST_INIT
(
&
(
vnodeMgr
.
queue
));
for
(
uint16_t
i
=
0
;
i
<
pOption
->
nthreads
;
i
++
)
{
for
(
uint16_t
i
=
0
;
i
<
pOption
->
nthreads
;
i
++
)
{
pthread_c
reate
(
&
(
vnodeMgr
.
threads
[
i
]),
NULL
,
loop
,
NULL
);
taosThreadC
reate
(
&
(
vnodeMgr
.
threads
[
i
]),
NULL
,
loop
,
NULL
);
// pthread_setname_np(vnodeMgr.threads[i], "VND Commit Thread");
// pthread_setname_np(vnodeMgr.threads[i], "VND Commit Thread");
}
}
}
else
{
}
else
{
...
@@ -63,28 +63,28 @@ void vnodeCleanup() {
...
@@ -63,28 +63,28 @@ void vnodeCleanup() {
}
}
// Stop commit handler
// Stop commit handler
pthread_mutex_l
ock
(
&
(
vnodeMgr
.
mutex
));
taosThreadMutexL
ock
(
&
(
vnodeMgr
.
mutex
));
vnodeMgr
.
stop
=
true
;
vnodeMgr
.
stop
=
true
;
pthread_cond_b
roadcast
(
&
(
vnodeMgr
.
hasTask
));
taosThreadCondB
roadcast
(
&
(
vnodeMgr
.
hasTask
));
pthread_mutex_u
nlock
(
&
(
vnodeMgr
.
mutex
));
taosThreadMutexU
nlock
(
&
(
vnodeMgr
.
mutex
));
for
(
uint16_t
i
=
0
;
i
<
vnodeMgr
.
nthreads
;
i
++
)
{
for
(
uint16_t
i
=
0
;
i
<
vnodeMgr
.
nthreads
;
i
++
)
{
pthread_j
oin
(
vnodeMgr
.
threads
[
i
],
NULL
);
taosThreadJ
oin
(
vnodeMgr
.
threads
[
i
],
NULL
);
}
}
tfree
(
vnodeMgr
.
threads
);
tfree
(
vnodeMgr
.
threads
);
pthread_cond_d
estroy
(
&
(
vnodeMgr
.
hasTask
));
taosThreadCondD
estroy
(
&
(
vnodeMgr
.
hasTask
));
pthread_mutex_d
estroy
(
&
(
vnodeMgr
.
mutex
));
taosThreadMutexD
estroy
(
&
(
vnodeMgr
.
mutex
));
}
}
int
vnodeScheduleTask
(
SVnodeTask
*
pTask
)
{
int
vnodeScheduleTask
(
SVnodeTask
*
pTask
)
{
pthread_mutex_l
ock
(
&
(
vnodeMgr
.
mutex
));
taosThreadMutexL
ock
(
&
(
vnodeMgr
.
mutex
));
TD_DLIST_APPEND
(
&
(
vnodeMgr
.
queue
),
pTask
);
TD_DLIST_APPEND
(
&
(
vnodeMgr
.
queue
),
pTask
);
pthread_cond_s
ignal
(
&
(
vnodeMgr
.
hasTask
));
taosThreadCondS
ignal
(
&
(
vnodeMgr
.
hasTask
));
pthread_mutex_u
nlock
(
&
(
vnodeMgr
.
mutex
));
taosThreadMutexU
nlock
(
&
(
vnodeMgr
.
mutex
));
return
0
;
return
0
;
}
}
...
@@ -107,15 +107,15 @@ static void* loop(void* arg) {
...
@@ -107,15 +107,15 @@ static void* loop(void* arg) {
SVnodeTask
*
pTask
;
SVnodeTask
*
pTask
;
for
(;;)
{
for
(;;)
{
pthread_mutex_l
ock
(
&
(
vnodeMgr
.
mutex
));
taosThreadMutexL
ock
(
&
(
vnodeMgr
.
mutex
));
for
(;;)
{
for
(;;)
{
pTask
=
TD_DLIST_HEAD
(
&
(
vnodeMgr
.
queue
));
pTask
=
TD_DLIST_HEAD
(
&
(
vnodeMgr
.
queue
));
if
(
pTask
==
NULL
)
{
if
(
pTask
==
NULL
)
{
if
(
vnodeMgr
.
stop
)
{
if
(
vnodeMgr
.
stop
)
{
pthread_mutex_u
nlock
(
&
(
vnodeMgr
.
mutex
));
taosThreadMutexU
nlock
(
&
(
vnodeMgr
.
mutex
));
return
NULL
;
return
NULL
;
}
else
{
}
else
{
pthread_cond_w
ait
(
&
(
vnodeMgr
.
hasTask
),
&
(
vnodeMgr
.
mutex
));
taosThreadCondW
ait
(
&
(
vnodeMgr
.
hasTask
),
&
(
vnodeMgr
.
mutex
));
}
}
}
else
{
}
else
{
TD_DLIST_POP
(
&
(
vnodeMgr
.
queue
),
pTask
);
TD_DLIST_POP
(
&
(
vnodeMgr
.
queue
),
pTask
);
...
@@ -123,7 +123,7 @@ static void* loop(void* arg) {
...
@@ -123,7 +123,7 @@ static void* loop(void* arg) {
}
}
}
}
pthread_mutex_u
nlock
(
&
(
vnodeMgr
.
mutex
));
taosThreadMutexU
nlock
(
&
(
vnodeMgr
.
mutex
));
(
*
(
pTask
->
execute
))(
pTask
->
arg
);
(
*
(
pTask
->
execute
))(
pTask
->
arg
);
free
(
pTask
);
free
(
pTask
);
...
...
source/dnode/vnode/test/tsdbSmaTest.cpp
浏览文件 @
3544df41
...
@@ -14,13 +14,13 @@
...
@@ -14,13 +14,13 @@
*/
*/
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <tsdbDef.h>
#include <taoserror.h>
#include <taoserror.h>
#include <tglobal.h>
#include <tglobal.h>
#include <iostream>
#include <iostream>
#include <metaDef.h>
#include <metaDef.h>
#include <tmsg.h>
#include <tmsg.h>
#include <tsdbDef.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wwrite-strings"
...
...
source/libs/catalog/inc/catalogInt.h
浏览文件 @
3544df41
...
@@ -176,7 +176,7 @@ typedef struct SCatalogMgmt {
...
@@ -176,7 +176,7 @@ typedef struct SCatalogMgmt {
SCtgQNode
*
tail
;
SCtgQNode
*
tail
;
tsem_t
sem
;
tsem_t
sem
;
uint64_t
qRemainNum
;
uint64_t
qRemainNum
;
pthread_t
updateThread
;
TdThread
updateThread
;
SHashObj
*
pCluster
;
//key: clusterId, value: SCatalog*
SHashObj
*
pCluster
;
//key: clusterId, value: SCatalog*
SCatalogStat
stat
;
SCatalogStat
stat
;
SCatalogCfg
cfg
;
SCatalogCfg
cfg
;
...
...
source/libs/catalog/src/catalog.c
浏览文件 @
3544df41
...
@@ -2070,16 +2070,16 @@ void* ctgUpdateThreadFunc(void* param) {
...
@@ -2070,16 +2070,16 @@ void* ctgUpdateThreadFunc(void* param) {
int32_t
ctgStartUpdateThread
()
{
int32_t
ctgStartUpdateThread
()
{
pthread_attr_t
thAttr
;
TdThreadAttr
thAttr
;
pthread_attr_i
nit
(
&
thAttr
);
taosThreadAttrI
nit
(
&
thAttr
);
pthread_attr_setdetachs
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_c
reate
(
&
gCtgMgmt
.
updateThread
,
&
thAttr
,
ctgUpdateThreadFunc
,
NULL
)
!=
0
)
{
if
(
taosThreadC
reate
(
&
gCtgMgmt
.
updateThread
,
&
thAttr
,
ctgUpdateThreadFunc
,
NULL
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
CTG_ERR_RET
(
terrno
);
CTG_ERR_RET
(
terrno
);
}
}
pthread_attr_d
estroy
(
&
thAttr
);
taosThreadAttrD
estroy
(
&
thAttr
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
...
source/libs/catalog/test/catalogTests.cpp
浏览文件 @
3544df41
...
@@ -2094,14 +2094,14 @@ TEST(multiThread, getSetRmSameDbVgroup) {
...
@@ -2094,14 +2094,14 @@ TEST(multiThread, getSetRmSameDbVgroup) {
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
thread1
,
thread2
;
TdThread
thread1
,
thread2
;
pthread_c
reate
(
&
(
thread1
),
&
thattr
,
ctgTestSetSameDbVgroupThread
,
pCtg
);
taosThreadC
reate
(
&
(
thread1
),
&
thattr
,
ctgTestSetSameDbVgroupThread
,
pCtg
);
taosSsleep
(
1
);
taosSsleep
(
1
);
pthread_c
reate
(
&
(
thread2
),
&
thattr
,
ctgTestGetDbVgroupThread
,
pCtg
);
taosThreadC
reate
(
&
(
thread2
),
&
thattr
,
ctgTestGetDbVgroupThread
,
pCtg
);
while
(
true
)
{
while
(
true
)
{
if
(
ctgTestDeadLoop
)
{
if
(
ctgTestDeadLoop
)
{
...
@@ -2146,14 +2146,14 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
...
@@ -2146,14 +2146,14 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
thread1
,
thread2
;
TdThread
thread1
,
thread2
;
pthread_c
reate
(
&
(
thread1
),
&
thattr
,
ctgTestSetDiffDbVgroupThread
,
pCtg
);
taosThreadC
reate
(
&
(
thread1
),
&
thattr
,
ctgTestSetDiffDbVgroupThread
,
pCtg
);
taosSsleep
(
1
);
taosSsleep
(
1
);
pthread_c
reate
(
&
(
thread2
),
&
thattr
,
ctgTestGetDbVgroupThread
,
pCtg
);
taosThreadC
reate
(
&
(
thread2
),
&
thattr
,
ctgTestGetDbVgroupThread
,
pCtg
);
while
(
true
)
{
while
(
true
)
{
if
(
ctgTestDeadLoop
)
{
if
(
ctgTestDeadLoop
)
{
...
@@ -2198,13 +2198,13 @@ TEST(multiThread, ctableMeta) {
...
@@ -2198,13 +2198,13 @@ TEST(multiThread, ctableMeta) {
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
thread1
,
thread2
;
TdThread
thread1
,
thread2
;
pthread_c
reate
(
&
(
thread1
),
&
thattr
,
ctgTestSetCtableMetaThread
,
pCtg
);
taosThreadC
reate
(
&
(
thread1
),
&
thattr
,
ctgTestSetCtableMetaThread
,
pCtg
);
taosSsleep
(
1
);
taosSsleep
(
1
);
pthread_c
reate
(
&
(
thread1
),
&
thattr
,
ctgTestGetCtableMetaThread
,
pCtg
);
taosThreadC
reate
(
&
(
thread1
),
&
thattr
,
ctgTestGetCtableMetaThread
,
pCtg
);
while
(
true
)
{
while
(
true
)
{
if
(
ctgTestDeadLoop
)
{
if
(
ctgTestDeadLoop
)
{
...
...
source/libs/executor/inc/dataSinkInt.h
浏览文件 @
3544df41
...
@@ -29,7 +29,7 @@ struct SDataSinkHandle;
...
@@ -29,7 +29,7 @@ struct SDataSinkHandle;
typedef
struct
SDataSinkManager
{
typedef
struct
SDataSinkManager
{
SDataSinkMgtCfg
cfg
;
SDataSinkMgtCfg
cfg
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
}
SDataSinkManager
;
}
SDataSinkManager
;
typedef
int32_t
(
*
FPutDataBlock
)(
struct
SDataSinkHandle
*
pHandle
,
const
SInputData
*
pInput
,
bool
*
pContinue
);
typedef
int32_t
(
*
FPutDataBlock
)(
struct
SDataSinkHandle
*
pHandle
,
const
SInputData
*
pInput
,
bool
*
pContinue
);
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
3544df41
...
@@ -356,7 +356,7 @@ typedef struct SQInfo {
...
@@ -356,7 +356,7 @@ typedef struct SQInfo {
STaskAttr
query
;
STaskAttr
query
;
void
*
pBuf
;
// allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables;
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
;
tsem_t
ready
;
int32_t
dataReady
;
// denote if query result is ready or not
int32_t
dataReady
;
// denote if query result is ready or not
void
*
rspContext
;
// response context
void
*
rspContext
;
// response context
...
...
source/libs/executor/src/dataDispatcher.c
浏览文件 @
3544df41
...
@@ -43,7 +43,7 @@ typedef struct SDataDispatchHandle {
...
@@ -43,7 +43,7 @@ typedef struct SDataDispatchHandle {
int32_t
status
;
int32_t
status
;
bool
queryEnd
;
bool
queryEnd
;
uint64_t
useconds
;
uint64_t
useconds
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
}
SDataDispatchHandle
;
}
SDataDispatchHandle
;
static
bool
needCompress
(
const
SSDataBlock
*
pData
,
const
SDataBlockDescNode
*
pSchema
)
{
static
bool
needCompress
(
const
SSDataBlock
*
pData
,
const
SDataBlockDescNode
*
pSchema
)
{
...
@@ -126,19 +126,19 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput,
...
@@ -126,19 +126,19 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput,
}
}
static
int32_t
updateStatus
(
SDataDispatchHandle
*
pDispatcher
)
{
static
int32_t
updateStatus
(
SDataDispatchHandle
*
pDispatcher
)
{
pthread_mutex_l
ock
(
&
pDispatcher
->
mutex
);
taosThreadMutexL
ock
(
&
pDispatcher
->
mutex
);
int32_t
blockNums
=
taosQueueSize
(
pDispatcher
->
pDataBlocks
);
int32_t
blockNums
=
taosQueueSize
(
pDispatcher
->
pDataBlocks
);
int32_t
status
=
(
0
==
blockNums
?
DS_BUF_EMPTY
:
int32_t
status
=
(
0
==
blockNums
?
DS_BUF_EMPTY
:
(
blockNums
<
pDispatcher
->
pManager
->
cfg
.
maxDataBlockNumPerQuery
?
DS_BUF_LOW
:
DS_BUF_FULL
));
(
blockNums
<
pDispatcher
->
pManager
->
cfg
.
maxDataBlockNumPerQuery
?
DS_BUF_LOW
:
DS_BUF_FULL
));
pDispatcher
->
status
=
status
;
pDispatcher
->
status
=
status
;
pthread_mutex_u
nlock
(
&
pDispatcher
->
mutex
);
taosThreadMutexU
nlock
(
&
pDispatcher
->
mutex
);
return
status
;
return
status
;
}
}
static
int32_t
getStatus
(
SDataDispatchHandle
*
pDispatcher
)
{
static
int32_t
getStatus
(
SDataDispatchHandle
*
pDispatcher
)
{
pthread_mutex_l
ock
(
&
pDispatcher
->
mutex
);
taosThreadMutexL
ock
(
&
pDispatcher
->
mutex
);
int32_t
status
=
pDispatcher
->
status
;
int32_t
status
=
pDispatcher
->
status
;
pthread_mutex_u
nlock
(
&
pDispatcher
->
mutex
);
taosThreadMutexU
nlock
(
&
pDispatcher
->
mutex
);
return
status
;
return
status
;
}
}
...
@@ -156,10 +156,10 @@ static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput,
...
@@ -156,10 +156,10 @@ static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput,
static
void
endPut
(
struct
SDataSinkHandle
*
pHandle
,
uint64_t
useconds
)
{
static
void
endPut
(
struct
SDataSinkHandle
*
pHandle
,
uint64_t
useconds
)
{
SDataDispatchHandle
*
pDispatcher
=
(
SDataDispatchHandle
*
)
pHandle
;
SDataDispatchHandle
*
pDispatcher
=
(
SDataDispatchHandle
*
)
pHandle
;
pthread_mutex_l
ock
(
&
pDispatcher
->
mutex
);
taosThreadMutexL
ock
(
&
pDispatcher
->
mutex
);
pDispatcher
->
queryEnd
=
true
;
pDispatcher
->
queryEnd
=
true
;
pDispatcher
->
useconds
=
useconds
;
pDispatcher
->
useconds
=
useconds
;
pthread_mutex_u
nlock
(
&
pDispatcher
->
mutex
);
taosThreadMutexU
nlock
(
&
pDispatcher
->
mutex
);
}
}
static
void
getDataLength
(
SDataSinkHandle
*
pHandle
,
int32_t
*
pLen
,
bool
*
pQueryEnd
)
{
static
void
getDataLength
(
SDataSinkHandle
*
pHandle
,
int32_t
*
pLen
,
bool
*
pQueryEnd
)
{
...
@@ -191,11 +191,11 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
...
@@ -191,11 +191,11 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
pOutput
->
compressed
=
pEntry
->
compressed
;
pOutput
->
compressed
=
pEntry
->
compressed
;
tfree
(
pDispatcher
->
nextOutput
.
pData
);
// todo persistent
tfree
(
pDispatcher
->
nextOutput
.
pData
);
// todo persistent
pOutput
->
bufStatus
=
updateStatus
(
pDispatcher
);
pOutput
->
bufStatus
=
updateStatus
(
pDispatcher
);
pthread_mutex_l
ock
(
&
pDispatcher
->
mutex
);
taosThreadMutexL
ock
(
&
pDispatcher
->
mutex
);
pOutput
->
queryEnd
=
pDispatcher
->
queryEnd
;
pOutput
->
queryEnd
=
pDispatcher
->
queryEnd
;
pOutput
->
useconds
=
pDispatcher
->
useconds
;
pOutput
->
useconds
=
pDispatcher
->
useconds
;
pOutput
->
precision
=
pDispatcher
->
pSchema
->
precision
;
pOutput
->
precision
=
pDispatcher
->
pSchema
->
precision
;
pthread_mutex_u
nlock
(
&
pDispatcher
->
mutex
);
taosThreadMutexU
nlock
(
&
pDispatcher
->
mutex
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -209,7 +209,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) {
...
@@ -209,7 +209,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) {
taosFreeQitem
(
pBuf
);
taosFreeQitem
(
pBuf
);
}
}
taosCloseQueue
(
pDispatcher
->
pDataBlocks
);
taosCloseQueue
(
pDispatcher
->
pDataBlocks
);
pthread_mutex_d
estroy
(
&
pDispatcher
->
mutex
);
taosThreadMutexD
estroy
(
&
pDispatcher
->
mutex
);
}
}
int32_t
createDataDispatcher
(
SDataSinkManager
*
pManager
,
const
SDataSinkNode
*
pDataSink
,
DataSinkHandle
*
pHandle
)
{
int32_t
createDataDispatcher
(
SDataSinkManager
*
pManager
,
const
SDataSinkNode
*
pDataSink
,
DataSinkHandle
*
pHandle
)
{
...
@@ -228,7 +228,7 @@ int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pD
...
@@ -228,7 +228,7 @@ int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pD
dispatcher
->
status
=
DS_BUF_EMPTY
;
dispatcher
->
status
=
DS_BUF_EMPTY
;
dispatcher
->
queryEnd
=
false
;
dispatcher
->
queryEnd
=
false
;
dispatcher
->
pDataBlocks
=
taosOpenQueue
();
dispatcher
->
pDataBlocks
=
taosOpenQueue
();
pthread_mutex_i
nit
(
&
dispatcher
->
mutex
,
NULL
);
taosThreadMutexI
nit
(
&
dispatcher
->
mutex
,
NULL
);
if
(
NULL
==
dispatcher
->
pDataBlocks
)
{
if
(
NULL
==
dispatcher
->
pDataBlocks
)
{
terrno
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
...
...
source/libs/executor/src/dataSinkMgt.c
浏览文件 @
3544df41
...
@@ -22,7 +22,7 @@ static SDataSinkManager gDataSinkManager = {0};
...
@@ -22,7 +22,7 @@ static SDataSinkManager gDataSinkManager = {0};
int32_t
dsDataSinkMgtInit
(
SDataSinkMgtCfg
*
cfg
)
{
int32_t
dsDataSinkMgtInit
(
SDataSinkMgtCfg
*
cfg
)
{
gDataSinkManager
.
cfg
=
*
cfg
;
gDataSinkManager
.
cfg
=
*
cfg
;
pthread_mutex_i
nit
(
&
gDataSinkManager
.
mutex
,
NULL
);
taosThreadMutexI
nit
(
&
gDataSinkManager
.
mutex
,
NULL
);
return
0
;
// to avoid compiler eror
return
0
;
// to avoid compiler eror
}
}
...
...
source/libs/executor/src/executorMain.c
浏览文件 @
3544df41
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
#include "query.h"
#include "query.h"
typedef
struct
STaskMgmt
{
typedef
struct
STaskMgmt
{
pthread_mutex_t
lock
;
TdThreadMutex
lock
;
SCacheObj
*
qinfoPool
;
// query handle pool
SCacheObj
*
qinfoPool
;
// query handle pool
int32_t
vgId
;
int32_t
vgId
;
bool
closed
;
bool
closed
;
...
...
source/libs/function/inc/tscript.h
浏览文件 @
3544df41
...
@@ -70,7 +70,7 @@ typedef struct {
...
@@ -70,7 +70,7 @@ typedef struct {
SList *scriptEnvs; //
SList *scriptEnvs; //
int32_t mSize; // pool limit
int32_t mSize; // pool limit
int32_t cSize; // current available size
int32_t cSize; // current available size
pthread_mutex_t
mutex;
TdThreadMutex
mutex;
} ScriptEnvPool;
} ScriptEnvPool;
ScriptCtx* createScriptCtx(char *str, int8_t resType, int16_t resBytes);
ScriptCtx* createScriptCtx(char *str, int8_t resType, int16_t resBytes);
...
...
source/libs/function/src/functionMgt.c
浏览文件 @
3544df41
...
@@ -26,7 +26,7 @@ typedef struct SFuncMgtService {
...
@@ -26,7 +26,7 @@ typedef struct SFuncMgtService {
}
SFuncMgtService
;
}
SFuncMgtService
;
static
SFuncMgtService
gFunMgtService
;
static
SFuncMgtService
gFunMgtService
;
static
pthread_once_t
functionHashTableInit
=
PTHREAD_ONCE_INIT
;
static
TdThreadOnce
functionHashTableInit
=
PTHREAD_ONCE_INIT
;
static
int32_t
initFunctionCode
=
0
;
static
int32_t
initFunctionCode
=
0
;
static
void
doInitFunctionHashTable
()
{
static
void
doInitFunctionHashTable
()
{
...
@@ -45,7 +45,7 @@ static void doInitFunctionHashTable() {
...
@@ -45,7 +45,7 @@ static void doInitFunctionHashTable() {
}
}
int32_t
fmFuncMgtInit
()
{
int32_t
fmFuncMgtInit
()
{
pthread_o
nce
(
&
functionHashTableInit
,
doInitFunctionHashTable
);
taosThreadO
nce
(
&
functionHashTableInit
,
doInitFunctionHashTable
);
return
initFunctionCode
;
return
initFunctionCode
;
}
}
...
...
source/libs/function/src/tscript.c
浏览文件 @
3544df41
...
@@ -333,7 +333,7 @@ void destroyLuaEnv(lua_State *lua) {
...
@@ -333,7 +333,7 @@ void destroyLuaEnv(lua_State *lua) {
int32_t scriptEnvPoolInit() {
int32_t scriptEnvPoolInit() {
const int size = 10; // configure or not
const int size = 10; // configure or not
pool = malloc(sizeof(ScriptEnvPool));
pool = malloc(sizeof(ScriptEnvPool));
pthread_mutex_i
nit(&pool->mutex, NULL);
taosThreadMutexI
nit(&pool->mutex, NULL);
pool->scriptEnvs = tdListNew(sizeof(ScriptEnv *));
pool->scriptEnvs = tdListNew(sizeof(ScriptEnv *));
for (int i = 0; i < size; i++) {
for (int i = 0; i < size; i++) {
...
@@ -359,7 +359,7 @@ void scriptEnvPoolCleanup() {
...
@@ -359,7 +359,7 @@ void scriptEnvPoolCleanup() {
listNodeFree(pNode);
listNodeFree(pNode);
}
}
tdListFree(pool->scriptEnvs);
tdListFree(pool->scriptEnvs);
pthread_mutex_d
estroy(&pool->mutex);
taosThreadMutexD
estroy(&pool->mutex);
free(pool);
free(pool);
}
}
...
@@ -372,9 +372,9 @@ void destroyScriptEnv(ScriptEnv *pEnv) {
...
@@ -372,9 +372,9 @@ void destroyScriptEnv(ScriptEnv *pEnv) {
ScriptEnv* getScriptEnvFromPool() {
ScriptEnv* getScriptEnvFromPool() {
ScriptEnv *pEnv = NULL;
ScriptEnv *pEnv = NULL;
pthread_mutex_l
ock(&pool->mutex);
taosThreadMutexL
ock(&pool->mutex);
if (pool->cSize <= 0) {
if (pool->cSize <= 0) {
pthread_mutex_u
nlock(&pool->mutex);
taosThreadMutexU
nlock(&pool->mutex);
return NULL;
return NULL;
}
}
SListNode *pNode = tdListPopHead(pool->scriptEnvs);
SListNode *pNode = tdListPopHead(pool->scriptEnvs);
...
@@ -384,7 +384,7 @@ ScriptEnv* getScriptEnvFromPool() {
...
@@ -384,7 +384,7 @@ ScriptEnv* getScriptEnvFromPool() {
}
}
pool->cSize--;
pool->cSize--;
pthread_mutex_u
nlock(&pool->mutex);
taosThreadMutexU
nlock(&pool->mutex);
return pEnv;
return pEnv;
}
}
...
@@ -392,11 +392,11 @@ void addScriptEnvToPool(ScriptEnv *pEnv) {
...
@@ -392,11 +392,11 @@ void addScriptEnvToPool(ScriptEnv *pEnv) {
if (pEnv == NULL) {
if (pEnv == NULL) {
return;
return;
}
}
pthread_mutex_l
ock(&pool->mutex);
taosThreadMutexL
ock(&pool->mutex);
lua_settop(pEnv->lua_state, 0);
lua_settop(pEnv->lua_state, 0);
tdListAppend(pool->scriptEnvs, (void *)(&pEnv));
tdListAppend(pool->scriptEnvs, (void *)(&pEnv));
pool->cSize++;
pool->cSize++;
pthread_mutex_u
nlock(&pool->mutex);
taosThreadMutexU
nlock(&pool->mutex);
}
}
bool hasBaseFuncDefinedInScript(lua_State *lua, const char *funcPrefix, int32_t len) {
bool hasBaseFuncDefinedInScript(lua_State *lua, const char *funcPrefix, int32_t len) {
...
...
source/libs/index/inc/indexInt.h
浏览文件 @
3544df41
...
@@ -58,7 +58,7 @@ struct SIndex {
...
@@ -58,7 +58,7 @@ struct SIndex {
char
*
path
;
char
*
path
;
SIndexStat
stat
;
SIndexStat
stat
;
pthread_mutex_t
mtx
;
TdThreadMutex
mtx
;
};
};
struct
SIndexOpts
{
struct
SIndexOpts
{
...
...
source/libs/index/inc/index_cache.h
浏览文件 @
3544df41
...
@@ -43,8 +43,8 @@ typedef struct IndexCache {
...
@@ -43,8 +43,8 @@ typedef struct IndexCache {
int8_t
type
;
int8_t
type
;
uint64_t
suid
;
uint64_t
suid
;
pthread_mutex_t
mtx
;
TdThreadMutex
mtx
;
pthread_cond_t
finished
;
TdThreadCond
finished
;
}
IndexCache
;
}
IndexCache
;
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
...
...
source/libs/index/inc/index_fst.h
浏览文件 @
3544df41
...
@@ -260,7 +260,7 @@ typedef struct Fst {
...
@@ -260,7 +260,7 @@ typedef struct Fst {
FstMeta
*
meta
;
FstMeta
*
meta
;
FstSlice
*
data
;
//
FstSlice
*
data
;
//
FstNode
*
root
;
//
FstNode
*
root
;
//
pthread_mutex_t
mtx
;
TdThreadMutex
mtx
;
}
Fst
;
}
Fst
;
// refactor simple function
// refactor simple function
...
...
source/libs/index/src/index.c
浏览文件 @
3544df41
...
@@ -45,7 +45,7 @@ typedef struct SIdxColInfo {
...
@@ -45,7 +45,7 @@ typedef struct SIdxColInfo {
int
cVersion
;
int
cVersion
;
}
SIdxColInfo
;
}
SIdxColInfo
;
static
pthread_once_t
isInit
=
PTHREAD_ONCE_INIT
;
static
TdThreadOnce
isInit
=
PTHREAD_ONCE_INIT
;
// static void indexInit();
// static void indexInit();
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
term
,
SArray
**
result
);
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
term
,
SArray
**
result
);
...
@@ -61,7 +61,7 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* icache, Iterat
...
@@ -61,7 +61,7 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* icache, Iterat
// int32_t indexSerialKey(ICacheKey* key, char* buf);
// int32_t indexSerialKey(ICacheKey* key, char* buf);
int
indexOpen
(
SIndexOpts
*
opts
,
const
char
*
path
,
SIndex
**
index
)
{
int
indexOpen
(
SIndexOpts
*
opts
,
const
char
*
path
,
SIndex
**
index
)
{
pthread_o
nce
(
&
isInit
,
indexInit
);
taosThreadO
nce
(
&
isInit
,
indexInit
);
SIndex
*
sIdx
=
calloc
(
1
,
sizeof
(
SIndex
));
SIndex
*
sIdx
=
calloc
(
1
,
sizeof
(
SIndex
));
if
(
sIdx
==
NULL
)
{
if
(
sIdx
==
NULL
)
{
return
-
1
;
return
-
1
;
...
@@ -82,7 +82,7 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
...
@@ -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
->
colObj
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
sIdx
->
cVersion
=
1
;
sIdx
->
cVersion
=
1
;
sIdx
->
path
=
tstrdup
(
path
);
sIdx
->
path
=
tstrdup
(
path
);
pthread_mutex_i
nit
(
&
sIdx
->
mtx
,
NULL
);
taosThreadMutexI
nit
(
&
sIdx
->
mtx
,
NULL
);
*
index
=
sIdx
;
*
index
=
sIdx
;
return
0
;
return
0
;
#endif
#endif
...
@@ -112,7 +112,7 @@ void indexClose(SIndex* sIdx) {
...
@@ -112,7 +112,7 @@ void indexClose(SIndex* sIdx) {
iter
=
taosHashIterate
(
sIdx
->
colObj
,
iter
);
iter
=
taosHashIterate
(
sIdx
->
colObj
,
iter
);
}
}
taosHashCleanup
(
sIdx
->
colObj
);
taosHashCleanup
(
sIdx
->
colObj
);
pthread_mutex_d
estroy
(
&
sIdx
->
mtx
);
taosThreadMutexD
estroy
(
&
sIdx
->
mtx
);
indexTFileDestroy
(
sIdx
->
tindex
);
indexTFileDestroy
(
sIdx
->
tindex
);
#endif
#endif
free
(
sIdx
->
path
);
free
(
sIdx
->
path
);
...
@@ -140,7 +140,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
...
@@ -140,7 +140,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
#ifdef USE_INVERTED_INDEX
#ifdef USE_INVERTED_INDEX
// TODO(yihao): reduce the lock range
// TODO(yihao): reduce the lock range
pthread_mutex_l
ock
(
&
index
->
mtx
);
taosThreadMutexL
ock
(
&
index
->
mtx
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
...
@@ -154,7 +154,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
...
@@ -154,7 +154,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
taosHashPut
(
index
->
colObj
,
buf
,
sz
,
&
pCache
,
sizeof
(
void
*
));
taosHashPut
(
index
->
colObj
,
buf
,
sz
,
&
pCache
,
sizeof
(
void
*
));
}
}
}
}
pthread_mutex_u
nlock
(
&
index
->
mtx
);
taosThreadMutexU
nlock
(
&
index
->
mtx
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
...
@@ -333,10 +333,10 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
...
@@ -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
};
.
suid
=
term
->
suid
,
.
colName
=
term
->
colName
,
.
nColName
=
strlen
(
term
->
colName
),
.
colType
=
term
->
colType
};
int32_t
sz
=
indexSerialCacheKey
(
&
key
,
buf
);
int32_t
sz
=
indexSerialCacheKey
(
&
key
,
buf
);
pthread_mutex_l
ock
(
&
sIdx
->
mtx
);
taosThreadMutexL
ock
(
&
sIdx
->
mtx
);
IndexCache
**
pCache
=
taosHashGet
(
sIdx
->
colObj
,
buf
,
sz
);
IndexCache
**
pCache
=
taosHashGet
(
sIdx
->
colObj
,
buf
,
sz
);
cache
=
(
pCache
==
NULL
)
?
NULL
:
*
pCache
;
cache
=
(
pCache
==
NULL
)
?
NULL
:
*
pCache
;
pthread_mutex_u
nlock
(
&
sIdx
->
mtx
);
taosThreadMutexU
nlock
(
&
sIdx
->
mtx
);
*
result
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
*
result
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
// TODO: iterator mem and tidex
// TODO: iterator mem and tidex
...
@@ -564,10 +564,10 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
...
@@ -564,10 +564,10 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
TFileHeader
*
header
=
&
reader
->
header
;
TFileHeader
*
header
=
&
reader
->
header
;
ICacheKey
key
=
{.
suid
=
cache
->
suid
,
.
colName
=
header
->
colName
,
.
nColName
=
strlen
(
header
->
colName
)};
ICacheKey
key
=
{.
suid
=
cache
->
suid
,
.
colName
=
header
->
colName
,
.
nColName
=
strlen
(
header
->
colName
)};
pthread_mutex_l
ock
(
&
sIdx
->
mtx
);
taosThreadMutexL
ock
(
&
sIdx
->
mtx
);
IndexTFile
*
ifile
=
(
IndexTFile
*
)
sIdx
->
tindex
;
IndexTFile
*
ifile
=
(
IndexTFile
*
)
sIdx
->
tindex
;
tfileCachePut
(
ifile
->
cache
,
&
key
,
reader
);
tfileCachePut
(
ifile
->
cache
,
&
key
,
reader
);
pthread_mutex_u
nlock
(
&
sIdx
->
mtx
);
taosThreadMutexU
nlock
(
&
sIdx
->
mtx
);
return
ret
;
return
ret
;
END:
END:
if
(
tw
!=
NULL
)
{
if
(
tw
!=
NULL
)
{
...
...
source/libs/index/src/index_cache.c
浏览文件 @
3544df41
...
@@ -54,8 +54,8 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
...
@@ -54,8 +54,8 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
cache
->
suid
=
suid
;
cache
->
suid
=
suid
;
cache
->
occupiedMem
=
0
;
cache
->
occupiedMem
=
0
;
pthread_mutex_i
nit
(
&
cache
->
mtx
,
NULL
);
taosThreadMutexI
nit
(
&
cache
->
mtx
,
NULL
);
pthread_cond_i
nit
(
&
cache
->
finished
,
NULL
);
taosThreadCondI
nit
(
&
cache
->
finished
,
NULL
);
indexCacheRef
(
cache
);
indexCacheRef
(
cache
);
return
cache
;
return
cache
;
...
@@ -63,10 +63,10 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
...
@@ -63,10 +63,10 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
void
indexCacheDebug
(
IndexCache
*
cache
)
{
void
indexCacheDebug
(
IndexCache
*
cache
)
{
MemTable
*
tbl
=
NULL
;
MemTable
*
tbl
=
NULL
;
pthread_mutex_l
ock
(
&
cache
->
mtx
);
taosThreadMutexL
ock
(
&
cache
->
mtx
);
tbl
=
cache
->
mem
;
tbl
=
cache
->
mem
;
indexMemRef
(
tbl
);
indexMemRef
(
tbl
);
pthread_mutex_u
nlock
(
&
cache
->
mtx
);
taosThreadMutexU
nlock
(
&
cache
->
mtx
);
{
{
SSkipList
*
slt
=
tbl
->
mem
;
SSkipList
*
slt
=
tbl
->
mem
;
...
@@ -85,10 +85,10 @@ void indexCacheDebug(IndexCache* cache) {
...
@@ -85,10 +85,10 @@ void indexCacheDebug(IndexCache* cache) {
}
}
{
{
pthread_mutex_l
ock
(
&
cache
->
mtx
);
taosThreadMutexL
ock
(
&
cache
->
mtx
);
tbl
=
cache
->
imm
;
tbl
=
cache
->
imm
;
indexMemRef
(
tbl
);
indexMemRef
(
tbl
);
pthread_mutex_u
nlock
(
&
cache
->
mtx
);
taosThreadMutexU
nlock
(
&
cache
->
mtx
);
if
(
tbl
!=
NULL
)
{
if
(
tbl
!=
NULL
)
{
SSkipList
*
slt
=
tbl
->
mem
;
SSkipList
*
slt
=
tbl
->
mem
;
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
slt
);
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
slt
);
...
@@ -126,13 +126,13 @@ void indexCacheDestroyImm(IndexCache* cache) {
...
@@ -126,13 +126,13 @@ void indexCacheDestroyImm(IndexCache* cache) {
}
}
MemTable
*
tbl
=
NULL
;
MemTable
*
tbl
=
NULL
;
pthread_mutex_l
ock
(
&
cache
->
mtx
);
taosThreadMutexL
ock
(
&
cache
->
mtx
);
tbl
=
cache
->
imm
;
tbl
=
cache
->
imm
;
cache
->
imm
=
NULL
;
// or throw int bg thread
cache
->
imm
=
NULL
;
// or throw int bg thread
pthread_cond_b
roadcast
(
&
cache
->
finished
);
taosThreadCondB
roadcast
(
&
cache
->
finished
);
pthread_mutex_u
nlock
(
&
cache
->
mtx
);
taosThreadMutexU
nlock
(
&
cache
->
mtx
);
indexMemUnRef
(
tbl
);
indexMemUnRef
(
tbl
);
indexMemUnRef
(
tbl
);
indexMemUnRef
(
tbl
);
...
@@ -146,8 +146,8 @@ void indexCacheDestroy(void* cache) {
...
@@ -146,8 +146,8 @@ void indexCacheDestroy(void* cache) {
indexMemUnRef
(
pCache
->
imm
);
indexMemUnRef
(
pCache
->
imm
);
free
(
pCache
->
colName
);
free
(
pCache
->
colName
);
pthread_mutex_d
estroy
(
&
pCache
->
mtx
);
taosThreadMutexD
estroy
(
&
pCache
->
mtx
);
pthread_cond_d
estroy
(
&
pCache
->
finished
);
taosThreadCondD
estroy
(
&
pCache
->
finished
);
free
(
pCache
);
free
(
pCache
);
}
}
...
@@ -158,7 +158,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
...
@@ -158,7 +158,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
return
NULL
;
return
NULL
;
}
}
pthread_mutex_l
ock
(
&
cache
->
mtx
);
taosThreadMutexL
ock
(
&
cache
->
mtx
);
indexMemRef
(
cache
->
imm
);
indexMemRef
(
cache
->
imm
);
...
@@ -169,7 +169,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
...
@@ -169,7 +169,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
iiter
->
next
=
indexCacheIteratorNext
;
iiter
->
next
=
indexCacheIteratorNext
;
iiter
->
getValue
=
indexCacheIteratorGetValue
;
iiter
->
getValue
=
indexCacheIteratorGetValue
;
pthread_mutex_u
nlock
(
&
cache
->
mtx
);
taosThreadMutexU
nlock
(
&
cache
->
mtx
);
return
iiter
;
return
iiter
;
}
}
...
@@ -200,7 +200,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
...
@@ -200,7 +200,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
break
;
break
;
}
else
if
(
cache
->
imm
!=
NULL
)
{
}
else
if
(
cache
->
imm
!=
NULL
)
{
// TODO: wake up by condition variable
// TODO: wake up by condition variable
pthread_cond_w
ait
(
&
cache
->
finished
,
&
cache
->
mtx
);
taosThreadCondW
ait
(
&
cache
->
finished
,
&
cache
->
mtx
);
}
else
{
}
else
{
indexCacheRef
(
cache
);
indexCacheRef
(
cache
);
cache
->
imm
=
cache
->
mem
;
cache
->
imm
=
cache
->
mem
;
...
@@ -240,7 +240,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
...
@@ -240,7 +240,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
// ugly code, refactor later
// ugly code, refactor later
int64_t
estimate
=
sizeof
(
ct
)
+
strlen
(
ct
->
colVal
);
int64_t
estimate
=
sizeof
(
ct
)
+
strlen
(
ct
->
colVal
);
pthread_mutex_l
ock
(
&
pCache
->
mtx
);
taosThreadMutexL
ock
(
&
pCache
->
mtx
);
pCache
->
occupiedMem
+=
estimate
;
pCache
->
occupiedMem
+=
estimate
;
indexCacheMakeRoomForWrite
(
pCache
);
indexCacheMakeRoomForWrite
(
pCache
);
MemTable
*
tbl
=
pCache
->
mem
;
MemTable
*
tbl
=
pCache
->
mem
;
...
@@ -248,7 +248,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
...
@@ -248,7 +248,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
tSkipListPut
(
tbl
->
mem
,
(
char
*
)
ct
);
tSkipListPut
(
tbl
->
mem
,
(
char
*
)
ct
);
indexMemUnRef
(
tbl
);
indexMemUnRef
(
tbl
);
pthread_mutex_u
nlock
(
&
pCache
->
mtx
);
taosThreadMutexU
nlock
(
&
pCache
->
mtx
);
indexCacheUnRef
(
pCache
);
indexCacheUnRef
(
pCache
);
return
0
;
return
0
;
...
@@ -299,12 +299,12 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result
...
@@ -299,12 +299,12 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
MemTable
*
mem
=
NULL
,
*
imm
=
NULL
;
MemTable
*
mem
=
NULL
,
*
imm
=
NULL
;
pthread_mutex_l
ock
(
&
pCache
->
mtx
);
taosThreadMutexL
ock
(
&
pCache
->
mtx
);
mem
=
pCache
->
mem
;
mem
=
pCache
->
mem
;
imm
=
pCache
->
imm
;
imm
=
pCache
->
imm
;
indexMemRef
(
mem
);
indexMemRef
(
mem
);
indexMemRef
(
imm
);
indexMemRef
(
imm
);
pthread_mutex_u
nlock
(
&
pCache
->
mtx
);
taosThreadMutexU
nlock
(
&
pCache
->
mtx
);
SIndexTerm
*
term
=
query
->
term
;
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
EIndexQueryType
qtype
=
query
->
qType
;
...
...
source/libs/index/src/index_fst.c
浏览文件 @
3544df41
...
@@ -1023,7 +1023,7 @@ Fst* fstCreate(FstSlice* slice) {
...
@@ -1023,7 +1023,7 @@ Fst* fstCreate(FstSlice* slice) {
*
s
=
fstSliceCopy
(
slice
,
0
,
FST_SLICE_LEN
(
slice
)
-
1
);
*
s
=
fstSliceCopy
(
slice
,
0
,
FST_SLICE_LEN
(
slice
)
-
1
);
fst
->
data
=
s
;
fst
->
data
=
s
;
pthread_mutex_i
nit
(
&
fst
->
mtx
,
NULL
);
taosThreadMutexI
nit
(
&
fst
->
mtx
,
NULL
);
return
fst
;
return
fst
;
FST_CREAT_FAILED:
FST_CREAT_FAILED:
...
@@ -1037,14 +1037,14 @@ void fstDestroy(Fst* fst) {
...
@@ -1037,14 +1037,14 @@ void fstDestroy(Fst* fst) {
free
(
fst
->
meta
);
free
(
fst
->
meta
);
fstSliceDestroy
(
fst
->
data
);
fstSliceDestroy
(
fst
->
data
);
free
(
fst
->
data
);
free
(
fst
->
data
);
pthread_mutex_d
estroy
(
&
fst
->
mtx
);
taosThreadMutexD
estroy
(
&
fst
->
mtx
);
}
}
free
(
fst
);
free
(
fst
);
}
}
bool
fstGet
(
Fst
*
fst
,
FstSlice
*
b
,
Output
*
out
)
{
bool
fstGet
(
Fst
*
fst
,
FstSlice
*
b
,
Output
*
out
)
{
// dec lock range
// dec lock range
//
pthread_mutex_l
ock(&fst->mtx);
//
taosThreadMutexL
ock(&fst->mtx);
FstNode
*
root
=
fstGetRoot
(
fst
);
FstNode
*
root
=
fstGetRoot
(
fst
);
Output
tOut
=
0
;
Output
tOut
=
0
;
int32_t
len
;
int32_t
len
;
...
@@ -1057,7 +1057,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
...
@@ -1057,7 +1057,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
uint8_t
inp
=
data
[
i
];
uint8_t
inp
=
data
[
i
];
Output
res
=
0
;
Output
res
=
0
;
if
(
false
==
fstNodeFindInput
(
root
,
inp
,
&
res
))
{
if
(
false
==
fstNodeFindInput
(
root
,
inp
,
&
res
))
{
//
pthread_mutex_u
nlock(&fst->mtx);
//
taosThreadMutexU
nlock(&fst->mtx);
return
false
;
return
false
;
}
}
...
@@ -1068,7 +1068,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
...
@@ -1068,7 +1068,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
taosArrayPush
(
nodes
,
&
root
);
taosArrayPush
(
nodes
,
&
root
);
}
}
if
(
!
FST_NODE_IS_FINAL
(
root
))
{
if
(
!
FST_NODE_IS_FINAL
(
root
))
{
//
pthread_mutex_u
nlock(&fst->mtx);
//
taosThreadMutexU
nlock(&fst->mtx);
return
false
;
return
false
;
}
else
{
}
else
{
tOut
=
tOut
+
FST_NODE_FINAL_OUTPUT
(
root
);
tOut
=
tOut
+
FST_NODE_FINAL_OUTPUT
(
root
);
...
@@ -1080,7 +1080,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
...
@@ -1080,7 +1080,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
}
}
taosArrayDestroy
(
nodes
);
taosArrayDestroy
(
nodes
);
// fst->root = NULL;
// fst->root = NULL;
//
pthread_mutex_u
nlock(&fst->mtx);
//
taosThreadMutexU
nlock(&fst->mtx);
*
out
=
tOut
;
*
out
=
tOut
;
return
true
;
return
true
;
}
}
...
...
source/libs/monitor/inc/monInt.h
浏览文件 @
3544df41
...
@@ -48,7 +48,7 @@ typedef struct SMonInfo {
...
@@ -48,7 +48,7 @@ typedef struct SMonInfo {
}
SMonInfo
;
}
SMonInfo
;
typedef
struct
{
typedef
struct
{
pthread_mutex_t
lock
;
TdThreadMutex
lock
;
SArray
*
logs
;
// array of SMonLogItem
SArray
*
logs
;
// array of SMonLogItem
int32_t
maxLogs
;
int32_t
maxLogs
;
const
char
*
server
;
const
char
*
server
;
...
...
source/libs/monitor/src/monitor.c
浏览文件 @
3544df41
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
static
SMonitor
tsMonitor
=
{
0
};
static
SMonitor
tsMonitor
=
{
0
};
void
monRecordLog
(
int64_t
ts
,
ELogLevel
level
,
const
char
*
content
)
{
void
monRecordLog
(
int64_t
ts
,
ELogLevel
level
,
const
char
*
content
)
{
pthread_mutex_l
ock
(
&
tsMonitor
.
lock
);
taosThreadMutexL
ock
(
&
tsMonitor
.
lock
);
int32_t
size
=
taosArrayGetSize
(
tsMonitor
.
logs
);
int32_t
size
=
taosArrayGetSize
(
tsMonitor
.
logs
);
if
(
size
<
tsMonitor
.
maxLogs
)
{
if
(
size
<
tsMonitor
.
maxLogs
)
{
SMonLogItem
item
=
{.
ts
=
ts
,
.
level
=
level
};
SMonLogItem
item
=
{.
ts
=
ts
,
.
level
=
level
};
...
@@ -32,7 +32,7 @@ void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
...
@@ -32,7 +32,7 @@ void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
tstrncpy
(
pItem
->
content
,
content
,
MON_LOG_LEN
);
tstrncpy
(
pItem
->
content
,
content
,
MON_LOG_LEN
);
}
}
}
}
pthread_mutex_u
nlock
(
&
tsMonitor
.
lock
);
taosThreadMutexU
nlock
(
&
tsMonitor
.
lock
);
}
}
int32_t
monInit
(
const
SMonCfg
*
pCfg
)
{
int32_t
monInit
(
const
SMonCfg
*
pCfg
)
{
...
@@ -48,7 +48,7 @@ int32_t monInit(const SMonCfg *pCfg) {
...
@@ -48,7 +48,7 @@ int32_t monInit(const SMonCfg *pCfg) {
tsMonitor
.
comp
=
pCfg
->
comp
;
tsMonitor
.
comp
=
pCfg
->
comp
;
tsLogFp
=
monRecordLog
;
tsLogFp
=
monRecordLog
;
tsMonitor
.
state
.
time
=
taosGetTimestampMs
();
tsMonitor
.
state
.
time
=
taosGetTimestampMs
();
pthread_mutex_i
nit
(
&
tsMonitor
.
lock
,
NULL
);
taosThreadMutexI
nit
(
&
tsMonitor
.
lock
,
NULL
);
return
0
;
return
0
;
}
}
...
@@ -56,7 +56,7 @@ void monCleanup() {
...
@@ -56,7 +56,7 @@ void monCleanup() {
tsLogFp
=
NULL
;
tsLogFp
=
NULL
;
taosArrayDestroy
(
tsMonitor
.
logs
);
taosArrayDestroy
(
tsMonitor
.
logs
);
tsMonitor
.
logs
=
NULL
;
tsMonitor
.
logs
=
NULL
;
pthread_mutex_d
estroy
(
&
tsMonitor
.
lock
);
taosThreadMutexD
estroy
(
&
tsMonitor
.
lock
);
}
}
SMonInfo
*
monCreateMonitorInfo
()
{
SMonInfo
*
monCreateMonitorInfo
()
{
...
@@ -66,10 +66,10 @@ SMonInfo *monCreateMonitorInfo() {
...
@@ -66,10 +66,10 @@ SMonInfo *monCreateMonitorInfo() {
return
NULL
;
return
NULL
;
}
}
pthread_mutex_l
ock
(
&
tsMonitor
.
lock
);
taosThreadMutexL
ock
(
&
tsMonitor
.
lock
);
pMonitor
->
logs
=
taosArrayDup
(
tsMonitor
.
logs
);
pMonitor
->
logs
=
taosArrayDup
(
tsMonitor
.
logs
);
taosArrayClear
(
tsMonitor
.
logs
);
taosArrayClear
(
tsMonitor
.
logs
);
pthread_mutex_u
nlock
(
&
tsMonitor
.
lock
);
taosThreadMutexU
nlock
(
&
tsMonitor
.
lock
);
pMonitor
->
pJson
=
tjsonCreateObject
();
pMonitor
->
pJson
=
tjsonCreateObject
();
if
(
pMonitor
->
pJson
==
NULL
||
pMonitor
->
logs
==
NULL
)
{
if
(
pMonitor
->
pJson
==
NULL
||
pMonitor
->
logs
==
NULL
)
{
...
...
source/libs/parser/src/parTokenizer.c
浏览文件 @
3544df41
...
@@ -266,10 +266,10 @@ static void doInitKeywordsTable(void) {
...
@@ -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
)
{
static
int32_t
tKeywordCode
(
const
char
*
z
,
int
n
)
{
pthread_o
nce
(
&
keywordsHashTableInit
,
doInitKeywordsTable
);
taosThreadO
nce
(
&
keywordsHashTableInit
,
doInitKeywordsTable
);
char
key
[
512
]
=
{
0
};
char
key
[
512
]
=
{
0
};
if
(
n
>
tListLen
(
key
))
{
// too long token, can not be any other token type
if
(
n
>
tListLen
(
key
))
{
// too long token, can not be any other token type
...
...
source/libs/qworker/test/qworkerTests.cpp
浏览文件 @
3544df41
...
@@ -1030,15 +1030,15 @@ TEST(seqTest, multithreadRand) {
...
@@ -1030,15 +1030,15 @@ TEST(seqTest, multithreadRand) {
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
ASSERT_EQ(code, 0);
pthread_attr_t
thattr;
TdThreadAttr
thattr;
pthread_attr_i
nit(&thattr);
taosThreadAttrI
nit(&thattr);
pthread_t
t1,t2,t3,t4,t5;
TdThread
t1,t2,t3,t4,t5;
pthread_c
reate(&(t1), &thattr, queryThread, mgmt);
taosThreadC
reate(&(t1), &thattr, queryThread, mgmt);
pthread_c
reate(&(t2), &thattr, readyThread, NULL);
taosThreadC
reate(&(t2), &thattr, readyThread, NULL);
pthread_c
reate(&(t3), &thattr, fetchThread, NULL);
taosThreadC
reate(&(t3), &thattr, fetchThread, NULL);
pthread_c
reate(&(t4), &thattr, dropThread, NULL);
taosThreadC
reate(&(t4), &thattr, dropThread, NULL);
pthread_c
reate(&(t5), &thattr, statusThread, NULL);
taosThreadC
reate(&(t5), &thattr, statusThread, NULL);
while (true) {
while (true) {
if (qwtTestDeadLoop) {
if (qwtTestDeadLoop) {
...
@@ -1089,13 +1089,13 @@ TEST(rcTest, shortExecshortDelay) {
...
@@ -1089,13 +1089,13 @@ TEST(rcTest, shortExecshortDelay) {
tsem_init
(
&
qwtTestQuerySem
,
0
,
0
);
tsem_init
(
&
qwtTestQuerySem
,
0
,
0
);
tsem_init
(
&
qwtTestFetchSem
,
0
,
0
);
tsem_init
(
&
qwtTestFetchSem
,
0
,
0
);
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
t1
,
t2
,
t3
,
t4
,
t5
;
TdThread
t1
,
t2
,
t3
,
t4
,
t5
;
pthread_c
reate
(
&
(
t1
),
&
thattr
,
qwtclientThread
,
mgmt
);
taosThreadC
reate
(
&
(
t1
),
&
thattr
,
qwtclientThread
,
mgmt
);
pthread_c
reate
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
mgmt
);
taosThreadC
reate
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
mgmt
);
pthread_c
reate
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
mgmt
);
taosThreadC
reate
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
mgmt
);
while
(
true
)
{
while
(
true
)
{
if
(
qwtTestDeadLoop
)
{
if
(
qwtTestDeadLoop
)
{
...
@@ -1170,13 +1170,13 @@ TEST(rcTest, longExecshortDelay) {
...
@@ -1170,13 +1170,13 @@ TEST(rcTest, longExecshortDelay) {
tsem_init
(
&
qwtTestQuerySem
,
0
,
0
);
tsem_init
(
&
qwtTestQuerySem
,
0
,
0
);
tsem_init
(
&
qwtTestFetchSem
,
0
,
0
);
tsem_init
(
&
qwtTestFetchSem
,
0
,
0
);
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
t1
,
t2
,
t3
,
t4
,
t5
;
TdThread
t1
,
t2
,
t3
,
t4
,
t5
;
pthread_c
reate
(
&
(
t1
),
&
thattr
,
qwtclientThread
,
mgmt
);
taosThreadC
reate
(
&
(
t1
),
&
thattr
,
qwtclientThread
,
mgmt
);
pthread_c
reate
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
mgmt
);
taosThreadC
reate
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
mgmt
);
pthread_c
reate
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
mgmt
);
taosThreadC
reate
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
mgmt
);
while
(
true
)
{
while
(
true
)
{
if
(
qwtTestDeadLoop
)
{
if
(
qwtTestDeadLoop
)
{
...
@@ -1253,13 +1253,13 @@ TEST(rcTest, shortExeclongDelay) {
...
@@ -1253,13 +1253,13 @@ TEST(rcTest, shortExeclongDelay) {
tsem_init
(
&
qwtTestQuerySem
,
0
,
0
);
tsem_init
(
&
qwtTestQuerySem
,
0
,
0
);
tsem_init
(
&
qwtTestFetchSem
,
0
,
0
);
tsem_init
(
&
qwtTestFetchSem
,
0
,
0
);
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
t1
,
t2
,
t3
,
t4
,
t5
;
TdThread
t1
,
t2
,
t3
,
t4
,
t5
;
pthread_c
reate
(
&
(
t1
),
&
thattr
,
qwtclientThread
,
mgmt
);
taosThreadC
reate
(
&
(
t1
),
&
thattr
,
qwtclientThread
,
mgmt
);
pthread_c
reate
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
mgmt
);
taosThreadC
reate
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
mgmt
);
pthread_c
reate
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
mgmt
);
taosThreadC
reate
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
mgmt
);
while
(
true
)
{
while
(
true
)
{
if
(
qwtTestDeadLoop
)
{
if
(
qwtTestDeadLoop
)
{
...
@@ -1332,13 +1332,13 @@ TEST(rcTest, dropTest) {
...
@@ -1332,13 +1332,13 @@ TEST(rcTest, dropTest) {
tsem_init(&qwtTestQuerySem, 0, 0);
tsem_init(&qwtTestQuerySem, 0, 0);
tsem_init(&qwtTestFetchSem, 0, 0);
tsem_init(&qwtTestFetchSem, 0, 0);
pthread_attr_t
thattr;
TdThreadAttr
thattr;
pthread_attr_i
nit(&thattr);
taosThreadAttrI
nit(&thattr);
pthread_t
t1,t2,t3,t4,t5;
TdThread
t1,t2,t3,t4,t5;
pthread_c
reate(&(t1), &thattr, clientThread, mgmt);
taosThreadC
reate(&(t1), &thattr, clientThread, mgmt);
pthread_c
reate(&(t2), &thattr, queryQueueThread, mgmt);
taosThreadC
reate(&(t2), &thattr, queryQueueThread, mgmt);
pthread_c
reate(&(t3), &thattr, fetchQueueThread, mgmt);
taosThreadC
reate(&(t3), &thattr, fetchQueueThread, mgmt);
while (true) {
while (true) {
if (qwtTestDeadLoop) {
if (qwtTestDeadLoop) {
...
...
source/libs/scheduler/test/schedulerTests.cpp
浏览文件 @
3544df41
...
@@ -684,11 +684,11 @@ TEST(queryTest, normalCase) {
...
@@ -684,11 +684,11 @@ TEST(queryTest, normalCase) {
pIter
=
taosHashIterate
(
pJob
->
execTasks
,
pIter
);
pIter
=
taosHashIterate
(
pJob
->
execTasks
,
pIter
);
}
}
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
thread1
;
TdThread
thread1
;
pthread_c
reate
(
&
(
thread1
),
&
thattr
,
schtCreateFetchRspThread
,
&
job
);
taosThreadC
reate
(
&
(
thread1
),
&
thattr
,
schtCreateFetchRspThread
,
&
job
);
void
*
data
=
NULL
;
void
*
data
=
NULL
;
code
=
schedulerFetchRows
(
job
,
&
data
);
code
=
schedulerFetchRows
(
job
,
&
data
);
...
@@ -780,11 +780,11 @@ TEST(queryTest, flowCtrlCase) {
...
@@ -780,11 +780,11 @@ TEST(queryTest, flowCtrlCase) {
}
}
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
thread1
;
TdThread
thread1
;
pthread_c
reate
(
&
(
thread1
),
&
thattr
,
schtCreateFetchRspThread
,
&
job
);
taosThreadC
reate
(
&
(
thread1
),
&
thattr
,
schtCreateFetchRspThread
,
&
job
);
void
*
data
=
NULL
;
void
*
data
=
NULL
;
code
=
schedulerFetchRows
(
job
,
&
data
);
code
=
schedulerFetchRows
(
job
,
&
data
);
...
@@ -834,11 +834,11 @@ TEST(insertTest, normalCase) {
...
@@ -834,11 +834,11 @@ TEST(insertTest, normalCase) {
schtSetPlanToString
();
schtSetPlanToString
();
schtSetAsyncSendMsgToServer
();
schtSetAsyncSendMsgToServer
();
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
thread1
;
TdThread
thread1
;
pthread_c
reate
(
&
(
thread1
),
&
thattr
,
schtSendRsp
,
&
insertJobRefId
);
taosThreadC
reate
(
&
(
thread1
),
&
thattr
,
schtSendRsp
,
&
insertJobRefId
);
SQueryResult
res
=
{
0
};
SQueryResult
res
=
{
0
};
code
=
schedulerExecJob
(
mockPointer
,
qnodeList
,
&
dag
,
&
insertJobRefId
,
"insert into tb values(now,1)"
,
&
res
);
code
=
schedulerExecJob
(
mockPointer
,
qnodeList
,
&
dag
,
&
insertJobRefId
,
"insert into tb values(now,1)"
,
&
res
);
...
@@ -851,13 +851,13 @@ TEST(insertTest, normalCase) {
...
@@ -851,13 +851,13 @@ TEST(insertTest, normalCase) {
}
}
TEST
(
multiThread
,
forceFree
)
{
TEST
(
multiThread
,
forceFree
)
{
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_t
thread1
,
thread2
,
thread3
;
TdThread
thread1
,
thread2
,
thread3
;
pthread_c
reate
(
&
(
thread1
),
&
thattr
,
schtRunJobThread
,
NULL
);
taosThreadC
reate
(
&
(
thread1
),
&
thattr
,
schtRunJobThread
,
NULL
);
pthread_c
reate
(
&
(
thread2
),
&
thattr
,
schtFreeJobThread
,
NULL
);
taosThreadC
reate
(
&
(
thread2
),
&
thattr
,
schtFreeJobThread
,
NULL
);
pthread_c
reate
(
&
(
thread3
),
&
thattr
,
schtFetchRspThread
,
NULL
);
taosThreadC
reate
(
&
(
thread3
),
&
thattr
,
schtFetchRspThread
,
NULL
);
while
(
true
)
{
while
(
true
)
{
if
(
schtTestDeadLoop
)
{
if
(
schtTestDeadLoop
)
{
...
...
source/libs/sync/inc/syncIO.h
浏览文件 @
3544df41
...
@@ -35,7 +35,7 @@ extern "C" {
...
@@ -35,7 +35,7 @@ extern "C" {
typedef
struct
SSyncIO
{
typedef
struct
SSyncIO
{
STaosQueue
*
pMsgQ
;
STaosQueue
*
pMsgQ
;
STaosQset
*
pQset
;
STaosQset
*
pQset
;
pthread_t
consumerTid
;
TdThread
consumerTid
;
void
*
serverRpc
;
void
*
serverRpc
;
void
*
clientRpc
;
void
*
clientRpc
;
...
...
source/libs/sync/src/syncIO.c
浏览文件 @
3544df41
...
@@ -211,7 +211,7 @@ static int32_t syncIOStartInternal(SSyncIO *io) {
...
@@ -211,7 +211,7 @@ static int32_t syncIOStartInternal(SSyncIO *io) {
// start consumer thread
// start consumer thread
{
{
if
(
pthread_c
reate
(
&
io
->
consumerTid
,
NULL
,
syncIOConsumerFunc
,
io
)
!=
0
)
{
if
(
taosThreadC
reate
(
&
io
->
consumerTid
,
NULL
,
syncIOConsumerFunc
,
io
)
!=
0
)
{
sError
(
"failed to create sync consumer thread since %s"
,
strerror
(
errno
));
sError
(
"failed to create sync consumer thread since %s"
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
...
@@ -228,7 +228,7 @@ static int32_t syncIOStartInternal(SSyncIO *io) {
...
@@ -228,7 +228,7 @@ static int32_t syncIOStartInternal(SSyncIO *io) {
static
int32_t
syncIOStopInternal
(
SSyncIO
*
io
)
{
static
int32_t
syncIOStopInternal
(
SSyncIO
*
io
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
atomic_store_8
(
&
io
->
isStart
,
0
);
atomic_store_8
(
&
io
->
isStart
,
0
);
pthread_j
oin
(
io
->
consumerTid
,
NULL
);
taosThreadJ
oin
(
io
->
consumerTid
,
NULL
);
taosTmrCleanUp
(
io
->
timerMgr
);
taosTmrCleanUp
(
io
->
timerMgr
);
return
ret
;
return
ret
;
}
}
...
...
source/libs/tdb/src/db/tdbPCache.c
浏览文件 @
3544df41
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
struct
SPCache
{
struct
SPCache
{
int
pageSize
;
int
pageSize
;
int
cacheSize
;
int
cacheSize
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
int
nFree
;
int
nFree
;
SPage
*
pFree
;
SPage
*
pFree
;
int
nPage
;
int
nPage
;
...
@@ -118,13 +118,13 @@ void tdbPCacheRelease(SPage *pPage) {
...
@@ -118,13 +118,13 @@ void tdbPCacheRelease(SPage *pPage) {
}
}
}
}
static
void
tdbPCacheInitLock
(
SPCache
*
pCache
)
{
pthread_mutex_i
nit
(
&
(
pCache
->
mutex
),
NULL
);
}
static
void
tdbPCacheInitLock
(
SPCache
*
pCache
)
{
taosThreadMutexI
nit
(
&
(
pCache
->
mutex
),
NULL
);
}
static
void
tdbPCacheClearLock
(
SPCache
*
pCache
)
{
pthread_mutex_d
estroy
(
&
(
pCache
->
mutex
));
}
static
void
tdbPCacheClearLock
(
SPCache
*
pCache
)
{
taosThreadMutexD
estroy
(
&
(
pCache
->
mutex
));
}
static
void
tdbPCacheLock
(
SPCache
*
pCache
)
{
pthread_mutex_l
ock
(
&
(
pCache
->
mutex
));
}
static
void
tdbPCacheLock
(
SPCache
*
pCache
)
{
taosThreadMutexL
ock
(
&
(
pCache
->
mutex
));
}
static
void
tdbPCacheUnlock
(
SPCache
*
pCache
)
{
pthread_mutex_u
nlock
(
&
(
pCache
->
mutex
));
}
static
void
tdbPCacheUnlock
(
SPCache
*
pCache
)
{
taosThreadMutexU
nlock
(
&
(
pCache
->
mutex
));
}
static
bool
tdbPCacheLocked
(
SPCache
*
pCache
)
{
static
bool
tdbPCacheLocked
(
SPCache
*
pCache
)
{
assert
(
0
);
assert
(
0
);
...
...
source/libs/tdb/src/inc/tdbPage.h
浏览文件 @
3544df41
...
@@ -53,7 +53,7 @@ typedef struct __attribute__((__packed__)) {
...
@@ -53,7 +53,7 @@ typedef struct __attribute__((__packed__)) {
}
SPageFtr
;
}
SPageFtr
;
struct
SPage
{
struct
SPage
{
pthread_spinlock_t
lock
;
TdThreadSpinlock
lock
;
u8
*
pData
;
u8
*
pData
;
int
pageSize
;
int
pageSize
;
SPageMethods
*
pPageMethods
;
SPageMethods
*
pPageMethods
;
...
@@ -101,10 +101,10 @@ struct SPage {
...
@@ -101,10 +101,10 @@ struct SPage {
#define P_LOCK_BUSY 1
#define P_LOCK_BUSY 1
#define P_LOCK_FAIL -1
#define P_LOCK_FAIL -1
#define TDB_INIT_PAGE_LOCK(pPage)
pthread_spin_i
nit(&((pPage)->lock), 0)
#define TDB_INIT_PAGE_LOCK(pPage)
taosThreadSpinI
nit(&((pPage)->lock), 0)
#define TDB_DESTROY_PAGE_LOCK(pPage)
pthread_spin_d
estroy(&((pPage)->lock))
#define TDB_DESTROY_PAGE_LOCK(pPage)
taosThreadSpinD
estroy(&((pPage)->lock))
#define TDB_LOCK_PAGE(pPage)
pthread_spin_l
ock(&((pPage)->lock))
#define TDB_LOCK_PAGE(pPage)
taosThreadSpinL
ock(&((pPage)->lock))
#define TDB_UNLOCK_PAGE(pPage)
pthread_spin_u
nlock(&((pPage)->lock))
#define TDB_UNLOCK_PAGE(pPage)
taosThreadSpinU
nlock(&((pPage)->lock))
#define TDB_TRY_LOCK_PAGE(pPage) \
#define TDB_TRY_LOCK_PAGE(pPage) \
({ \
({ \
int ret; \
int ret; \
...
...
source/libs/tfs/inc/tfsInt.h
浏览文件 @
3544df41
...
@@ -41,7 +41,7 @@ typedef struct {
...
@@ -41,7 +41,7 @@ typedef struct {
}
STfsDisk
;
}
STfsDisk
;
typedef
struct
{
typedef
struct
{
pthread_spinlock_t
lock
;
TdThreadSpinlock
lock
;
int32_t
level
;
int32_t
level
;
int32_t
nextid
;
// next disk id to allocate
int32_t
nextid
;
// next disk id to allocate
int32_t
ndisk
;
// # of disks mounted to this tier
int32_t
ndisk
;
// # of disks mounted to this tier
...
@@ -64,7 +64,7 @@ typedef struct STfsDir {
...
@@ -64,7 +64,7 @@ typedef struct STfsDir {
}
STfsDir
;
}
STfsDir
;
typedef
struct
STfs
{
typedef
struct
STfs
{
pthread_spinlock_t
lock
;
TdThreadSpinlock
lock
;
SDiskSize
size
;
SDiskSize
size
;
int32_t
nlevel
;
int32_t
nlevel
;
STfsTier
tiers
[
TFS_MAX_TIERS
];
STfsTier
tiers
[
TFS_MAX_TIERS
];
...
@@ -82,11 +82,11 @@ void tfsUpdateTierSize(STfsTier *pTier);
...
@@ -82,11 +82,11 @@ void tfsUpdateTierSize(STfsTier *pTier);
int32_t
tfsAllocDiskOnTier
(
STfsTier
*
pTier
);
int32_t
tfsAllocDiskOnTier
(
STfsTier
*
pTier
);
void
tfsPosNextId
(
STfsTier
*
pTier
);
void
tfsPosNextId
(
STfsTier
*
pTier
);
#define tfsLockTier(pTier)
pthread_spin_l
ock(&(pTier)->lock)
#define tfsLockTier(pTier)
taosThreadSpinL
ock(&(pTier)->lock)
#define tfsUnLockTier(pTier)
pthread_spin_u
nlock(&(pTier)->lock)
#define tfsUnLockTier(pTier)
taosThreadSpinU
nlock(&(pTier)->lock)
#define tfsLock(pTfs)
pthread_spin_l
ock(&(pTfs)->lock)
#define tfsLock(pTfs)
taosThreadSpinL
ock(&(pTfs)->lock)
#define tfsUnLock(pTfs)
pthread_spin_u
nlock(&(pTfs)->lock)
#define tfsUnLock(pTfs)
taosThreadSpinU
nlock(&(pTfs)->lock)
#define TFS_TIER_AT(pTfs, level) (&(pTfs)->tiers[level])
#define TFS_TIER_AT(pTfs, level) (&(pTfs)->tiers[level])
#define TFS_DISK_AT(pTfs, did) ((pTfs)->tiers[(did).level].disks[(did).id])
#define TFS_DISK_AT(pTfs, did) ((pTfs)->tiers[(did).level].disks[(did).id])
...
...
source/libs/tfs/src/tfs.c
浏览文件 @
3544df41
...
@@ -36,7 +36,7 @@ STfs *tfsOpen(SDiskCfg *pCfg, int32_t ndisk) {
...
@@ -36,7 +36,7 @@ STfs *tfsOpen(SDiskCfg *pCfg, int32_t ndisk) {
return
NULL
;
return
NULL
;
}
}
if
(
pthread_spin_i
nit
(
&
pTfs
->
lock
,
0
)
!=
0
)
{
if
(
taosThreadSpinI
nit
(
&
pTfs
->
lock
,
0
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tfsClose
(
pTfs
);
tfsClose
(
pTfs
);
return
NULL
;
return
NULL
;
...
@@ -85,7 +85,7 @@ void tfsClose(STfs *pTfs) {
...
@@ -85,7 +85,7 @@ void tfsClose(STfs *pTfs) {
}
}
taosHashCleanup
(
pTfs
->
hash
);
taosHashCleanup
(
pTfs
->
hash
);
pthread_spin_d
estroy
(
&
pTfs
->
lock
);
taosThreadSpinD
estroy
(
&
pTfs
->
lock
);
free
(
pTfs
);
free
(
pTfs
);
}
}
...
...
source/libs/tfs/src/tfsTier.c
浏览文件 @
3544df41
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
int32_t
tfsInitTier
(
STfsTier
*
pTier
,
int32_t
level
)
{
int32_t
tfsInitTier
(
STfsTier
*
pTier
,
int32_t
level
)
{
memset
(
pTier
,
0
,
sizeof
(
STfsTier
));
memset
(
pTier
,
0
,
sizeof
(
STfsTier
));
if
(
pthread_spin_i
nit
(
&
pTier
->
lock
,
0
)
!=
0
)
{
if
(
taosThreadSpinI
nit
(
&
pTier
->
lock
,
0
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
}
}
...
@@ -34,7 +34,7 @@ void tfsDestroyTier(STfsTier *pTier) {
...
@@ -34,7 +34,7 @@ void tfsDestroyTier(STfsTier *pTier) {
}
}
pTier
->
ndisk
=
0
;
pTier
->
ndisk
=
0
;
pthread_spin_d
estroy
(
&
pTier
->
lock
);
taosThreadSpinD
estroy
(
&
pTier
->
lock
);
}
}
STfsDisk
*
tfsMountDiskToTier
(
STfsTier
*
pTier
,
SDiskCfg
*
pCfg
)
{
STfsDisk
*
tfsMountDiskToTier
(
STfsTier
*
pTier
,
SDiskCfg
*
pCfg
)
{
...
...
source/libs/transport/inc/transComm.h
浏览文件 @
3544df41
...
@@ -230,7 +230,7 @@ typedef void (*AsyncCB)(uv_async_t* handle);
...
@@ -230,7 +230,7 @@ typedef void (*AsyncCB)(uv_async_t* handle);
typedef
struct
{
typedef
struct
{
void
*
pThrd
;
void
*
pThrd
;
queue
qmsg
;
queue
qmsg
;
pthread_mutex_t
mtx
;
// protect qmsg;
TdThreadMutex
mtx
;
// protect qmsg;
}
SAsyncItem
;
}
SAsyncItem
;
typedef
struct
{
typedef
struct
{
...
...
source/libs/transport/inc/transportInt.h
浏览文件 @
3544df41
...
@@ -70,7 +70,7 @@ typedef struct {
...
@@ -70,7 +70,7 @@ typedef struct {
void
*
tmrCtrl
;
// handle to timer
void
*
tmrCtrl
;
// handle to timer
SHashObj
*
hash
;
// handle returned by hash utility
SHashObj
*
hash
;
// handle returned by hash utility
void
*
tcphandle
;
// returned handle from TCP initialization
void
*
tcphandle
;
// returned handle from TCP initialization
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
}
SRpcInfo
;
}
SRpcInfo
;
#endif // USE_LIBUV
#endif // USE_LIBUV
...
...
source/libs/transport/src/rpcCache.c
浏览文件 @
3544df41
...
@@ -39,7 +39,7 @@ typedef struct {
...
@@ -39,7 +39,7 @@ typedef struct {
int
total
;
int
total
;
int
*
count
;
int
*
count
;
int64_t
keepTimer
;
int64_t
keepTimer
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
void
(
*
cleanFp
)(
void
*
);
void
(
*
cleanFp
)(
void
*
);
void
*
tmrCtrl
;
void
*
tmrCtrl
;
void
*
pTimer
;
void
*
pTimer
;
...
@@ -85,7 +85,7 @@ void *rpcOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl,
...
@@ -85,7 +85,7 @@ void *rpcOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl,
pCache
->
lockedBy
=
calloc
(
sizeof
(
int64_t
),
maxSessions
);
pCache
->
lockedBy
=
calloc
(
sizeof
(
int64_t
),
maxSessions
);
taosTmrReset
(
rpcCleanConnCache
,
(
int32_t
)(
pCache
->
keepTimer
*
2
),
pCache
,
pCache
->
tmrCtrl
,
&
pCache
->
pTimer
);
taosTmrReset
(
rpcCleanConnCache
,
(
int32_t
)(
pCache
->
keepTimer
*
2
),
pCache
,
pCache
->
tmrCtrl
,
&
pCache
->
pTimer
);
pthread_mutex_i
nit
(
&
pCache
->
mutex
,
NULL
);
taosThreadMutexI
nit
(
&
pCache
->
mutex
,
NULL
);
return
pCache
;
return
pCache
;
}
}
...
@@ -96,7 +96,7 @@ void rpcCloseConnCache(void *handle) {
...
@@ -96,7 +96,7 @@ void rpcCloseConnCache(void *handle) {
pCache
=
(
SConnCache
*
)
handle
;
pCache
=
(
SConnCache
*
)
handle
;
if
(
pCache
==
NULL
||
pCache
->
maxSessions
==
0
)
return
;
if
(
pCache
==
NULL
||
pCache
->
maxSessions
==
0
)
return
;
pthread_mutex_l
ock
(
&
pCache
->
mutex
);
taosThreadMutexL
ock
(
&
pCache
->
mutex
);
taosTmrStopA
(
&
(
pCache
->
pTimer
));
taosTmrStopA
(
&
(
pCache
->
pTimer
));
...
@@ -106,9 +106,9 @@ void rpcCloseConnCache(void *handle) {
...
@@ -106,9 +106,9 @@ void rpcCloseConnCache(void *handle) {
tfree
(
pCache
->
count
);
tfree
(
pCache
->
count
);
tfree
(
pCache
->
lockedBy
);
tfree
(
pCache
->
lockedBy
);
pthread_mutex_u
nlock
(
&
pCache
->
mutex
);
taosThreadMutexU
nlock
(
&
pCache
->
mutex
);
pthread_mutex_d
estroy
(
&
pCache
->
mutex
);
taosThreadMutexD
estroy
(
&
pCache
->
mutex
);
memset
(
pCache
,
0
,
sizeof
(
SConnCache
));
memset
(
pCache
,
0
,
sizeof
(
SConnCache
));
free
(
pCache
);
free
(
pCache
);
...
@@ -220,7 +220,7 @@ static void rpcCleanConnCache(void *handle, void *tmrId) {
...
@@ -220,7 +220,7 @@ static void rpcCleanConnCache(void *handle, void *tmrId) {
if
(
pCache
==
NULL
||
pCache
->
maxSessions
==
0
)
return
;
if
(
pCache
==
NULL
||
pCache
->
maxSessions
==
0
)
return
;
if
(
pCache
->
pTimer
!=
tmrId
)
return
;
if
(
pCache
->
pTimer
!=
tmrId
)
return
;
pthread_mutex_l
ock
(
&
pCache
->
mutex
);
taosThreadMutexL
ock
(
&
pCache
->
mutex
);
uint64_t
time
=
taosGetTimestampMs
();
uint64_t
time
=
taosGetTimestampMs
();
for
(
hash
=
0
;
hash
<
pCache
->
maxSessions
;
++
hash
)
{
for
(
hash
=
0
;
hash
<
pCache
->
maxSessions
;
++
hash
)
{
...
@@ -232,7 +232,7 @@ static void rpcCleanConnCache(void *handle, void *tmrId) {
...
@@ -232,7 +232,7 @@ static void rpcCleanConnCache(void *handle, void *tmrId) {
// tTrace("timer, total connections in cache:%d", pCache->total);
// tTrace("timer, total connections in cache:%d", pCache->total);
taosTmrReset
(
rpcCleanConnCache
,
(
int32_t
)(
pCache
->
keepTimer
*
2
),
pCache
,
pCache
->
tmrCtrl
,
&
pCache
->
pTimer
);
taosTmrReset
(
rpcCleanConnCache
,
(
int32_t
)(
pCache
->
keepTimer
*
2
),
pCache
,
pCache
->
tmrCtrl
,
&
pCache
->
pTimer
);
pthread_mutex_u
nlock
(
&
pCache
->
mutex
);
taosThreadMutexU
nlock
(
&
pCache
->
mutex
);
}
}
static
void
rpcRemoveExpiredNodes
(
SConnCache
*
pCache
,
SConnHash
*
pNode
,
int
hash
,
uint64_t
time
)
{
static
void
rpcRemoveExpiredNodes
(
SConnCache
*
pCache
,
SConnHash
*
pNode
,
int
hash
,
uint64_t
time
)
{
...
...
source/libs/transport/src/rpcMain.c
浏览文件 @
3544df41
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
*/
*/
#include "lz4.h"
#include "lz4.h"
#include "transportInt.h"
#include "os.h"
#include "os.h"
#include "rpcCache.h"
#include "rpcCache.h"
#include "rpcHead.h"
#include "rpcHead.h"
...
@@ -27,13 +28,12 @@
...
@@ -27,13 +28,12 @@
#include "tmd5.h"
#include "tmd5.h"
#include "tmempool.h"
#include "tmempool.h"
#include "tmsg.h"
#include "tmsg.h"
#include "transportInt.h"
#include "tref.h"
#include "tref.h"
#include "trpc.h"
#include "trpc.h"
#include "ttimer.h"
#include "ttimer.h"
#include "tutil.h"
#include "tutil.h"
static
pthread_once_t
tsRpcInitOnce
=
PTHREAD_ONCE_INIT
;
static
TdThreadOnce
tsRpcInitOnce
=
PTHREAD_ONCE_INIT
;
int
tsRpcMaxUdpSize
=
15000
;
// bytes
int
tsRpcMaxUdpSize
=
15000
;
// bytes
int
tsProgressTimer
=
100
;
int
tsProgressTimer
=
100
;
...
@@ -72,7 +72,7 @@ typedef struct {
...
@@ -72,7 +72,7 @@ typedef struct {
void
*
tcphandle
;
// returned handle from TCP initialization
void
*
tcphandle
;
// returned handle from TCP initialization
void
*
udphandle
;
// returned handle from UDP initialization
void
*
udphandle
;
// returned handle from UDP initialization
void
*
pCache
;
// connection cache
void
*
pCache
;
// connection cache
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
struct
SRpcConn
*
connList
;
// connection list
struct
SRpcConn
*
connList
;
// connection list
}
SRpcInfo
;
}
SRpcInfo
;
...
@@ -143,7 +143,7 @@ typedef struct SRpcConn {
...
@@ -143,7 +143,7 @@ typedef struct SRpcConn {
static
int
tsRpcRefId
=
-
1
;
static
int
tsRpcRefId
=
-
1
;
static
int32_t
tsRpcNum
=
0
;
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
// server:0 client:1 tcp:2 udp:0
#define RPC_CONN_UDPS 0
#define RPC_CONN_UDPS 0
...
@@ -223,7 +223,7 @@ static void rpcInitImp(void) {
...
@@ -223,7 +223,7 @@ static void rpcInitImp(void) {
}
}
int32_t
rpcInit
()
{
int32_t
rpcInit
()
{
pthread_o
nce
(
&
tsRpcInitOnce
,
rpcInitImp
);
taosThreadO
nce
(
&
tsRpcInitOnce
,
rpcInitImp
);
return
0
;
return
0
;
}
}
...
@@ -238,7 +238,7 @@ void rpcCleanup(void) {
...
@@ -238,7 +238,7 @@ void rpcCleanup(void) {
void
*
rpcOpen
(
const
SRpcInit
*
pInit
)
{
void
*
rpcOpen
(
const
SRpcInit
*
pInit
)
{
SRpcInfo
*
pRpc
;
SRpcInfo
*
pRpc
;
//
pthread_o
nce(&tsRpcInit, rpcInit);
//
taosThreadO
nce(&tsRpcInit, rpcInit);
pRpc
=
(
SRpcInfo
*
)
calloc
(
1
,
sizeof
(
SRpcInfo
));
pRpc
=
(
SRpcInfo
*
)
calloc
(
1
,
sizeof
(
SRpcInfo
));
if
(
pRpc
==
NULL
)
return
NULL
;
if
(
pRpc
==
NULL
)
return
NULL
;
...
@@ -307,7 +307,7 @@ void *rpcOpen(const SRpcInit *pInit) {
...
@@ -307,7 +307,7 @@ void *rpcOpen(const SRpcInit *pInit) {
}
}
}
}
pthread_mutex_i
nit
(
&
pRpc
->
mutex
,
NULL
);
taosThreadMutexI
nit
(
&
pRpc
->
mutex
,
NULL
);
pRpc
->
tcphandle
=
(
*
taosInitConn
[
pRpc
->
connType
|
RPC_CONN_TCP
])(
0
,
pRpc
->
localPort
,
pRpc
->
label
,
pRpc
->
numOfThreads
,
pRpc
->
tcphandle
=
(
*
taosInitConn
[
pRpc
->
connType
|
RPC_CONN_TCP
])(
0
,
pRpc
->
localPort
,
pRpc
->
label
,
pRpc
->
numOfThreads
,
rpcProcessMsgFromPeer
,
pRpc
);
rpcProcessMsgFromPeer
,
pRpc
);
...
@@ -1672,7 +1672,7 @@ static void rpcDecRef(SRpcInfo *pRpc) {
...
@@ -1672,7 +1672,7 @@ static void rpcDecRef(SRpcInfo *pRpc) {
taosIdPoolCleanUp
(
pRpc
->
idPool
);
taosIdPoolCleanUp
(
pRpc
->
idPool
);
tfree
(
pRpc
->
connList
);
tfree
(
pRpc
->
connList
);
pthread_mutex_d
estroy
(
&
pRpc
->
mutex
);
taosThreadMutexD
estroy
(
&
pRpc
->
mutex
);
tDebug
(
"%s rpc resources are released"
,
pRpc
->
label
);
tDebug
(
"%s rpc resources are released"
,
pRpc
->
label
);
tfree
(
pRpc
);
tfree
(
pRpc
);
...
...
source/libs/transport/src/rpcTcp.c
浏览文件 @
3544df41
...
@@ -35,9 +35,9 @@ typedef struct SFdObj {
...
@@ -35,9 +35,9 @@ typedef struct SFdObj {
}
SFdObj
;
}
SFdObj
;
typedef
struct
SThreadObj
{
typedef
struct
SThreadObj
{
pthread_t
thread
;
TdThread
thread
;
SFdObj
*
pHead
;
SFdObj
*
pHead
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
uint32_t
ip
;
uint32_t
ip
;
bool
stop
;
bool
stop
;
TdEpollPtr
pEpoll
;
TdEpollPtr
pEpoll
;
...
@@ -65,7 +65,7 @@ typedef struct {
...
@@ -65,7 +65,7 @@ typedef struct {
int
numOfThreads
;
int
numOfThreads
;
void
*
shandle
;
void
*
shandle
;
SThreadObj
**
pThreadObj
;
SThreadObj
**
pThreadObj
;
pthread_t
thread
;
TdThread
thread
;
}
SServerObj
;
}
SServerObj
;
static
void
*
taosProcessTcpData
(
void
*
param
);
static
void
*
taosProcessTcpData
(
void
*
param
);
...
@@ -101,9 +101,9 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
...
@@ -101,9 +101,9 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
}
}
int
code
=
0
;
int
code
=
0
;
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
// initialize parameters in case it may encounter error later
// initialize parameters in case it may encounter error later
for
(
int
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
...
@@ -129,7 +129,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
...
@@ -129,7 +129,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
// initialize mutex, thread, fd which may fail
// initialize mutex, thread, fd which may fail
for
(
int
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
pThreadObj
=
pServerObj
->
pThreadObj
[
i
];
pThreadObj
=
pServerObj
->
pThreadObj
[
i
];
code
=
pthread_mutex_i
nit
(
&
(
pThreadObj
->
mutex
),
NULL
);
code
=
taosThreadMutexI
nit
(
&
(
pThreadObj
->
mutex
),
NULL
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
tError
(
"%s failed to init TCP process data mutex(%s)"
,
label
,
strerror
(
errno
));
tError
(
"%s failed to init TCP process data mutex(%s)"
,
label
,
strerror
(
errno
));
break
;
break
;
...
@@ -142,7 +142,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
...
@@ -142,7 +142,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
break
;
break
;
}
}
code
=
pthread_c
reate
(
&
(
pThreadObj
->
thread
),
&
thattr
,
taosProcessTcpData
,
(
void
*
)(
pThreadObj
));
code
=
taosThreadC
reate
(
&
(
pThreadObj
->
thread
),
&
thattr
,
taosProcessTcpData
,
(
void
*
)(
pThreadObj
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
tError
(
"%s failed to create TCP process data thread(%s)"
,
label
,
strerror
(
errno
));
tError
(
"%s failed to create TCP process data thread(%s)"
,
label
,
strerror
(
errno
));
break
;
break
;
...
@@ -155,7 +155,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
...
@@ -155,7 +155,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
if
(
pServerObj
->
pSocketServer
==
NULL
)
code
=
-
1
;
if
(
pServerObj
->
pSocketServer
==
NULL
)
code
=
-
1
;
if
(
code
==
0
)
{
if
(
code
==
0
)
{
code
=
pthread_c
reate
(
&
pServerObj
->
thread
,
&
thattr
,
taosAcceptTcpConnection
,
(
void
*
)
pServerObj
);
code
=
taosThreadC
reate
(
&
pServerObj
->
thread
,
&
thattr
,
taosAcceptTcpConnection
,
(
void
*
)
pServerObj
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
tError
(
"%s failed to create TCP accept thread(%s)"
,
label
,
strerror
(
code
));
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
...
@@ -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
);
tDebug
(
"%s TCP server is initialized, ip:0x%x port:%hu numOfThreads:%d"
,
label
,
ip
,
port
,
numOfThreads
);
}
}
pthread_attr_d
estroy
(
&
thattr
);
taosThreadAttrD
estroy
(
&
thattr
);
return
(
void
*
)
pServerObj
;
return
(
void
*
)
pServerObj
;
}
}
...
@@ -178,16 +178,16 @@ static void taosStopTcpThread(SThreadObj *pThreadObj) {
...
@@ -178,16 +178,16 @@ static void taosStopTcpThread(SThreadObj *pThreadObj) {
return
;
return
;
}
}
// save thread into local variable and signal thread to stop
// save thread into local variable and signal thread to stop
pthread_t
thread
=
pThreadObj
->
thread
;
TdThread
thread
=
pThreadObj
->
thread
;
if
(
!
taosCheckPthreadValid
(
thread
))
{
if
(
!
taosCheckPthreadValid
(
thread
))
{
return
;
return
;
}
}
pThreadObj
->
stop
=
true
;
pThreadObj
->
stop
=
true
;
if
(
taosComparePthread
(
thread
,
pthread_s
elf
()))
{
if
(
taosComparePthread
(
thread
,
taosThreadS
elf
()))
{
pthread_detach
(
pthread_s
elf
());
pthread_detach
(
taosThreadS
elf
());
return
;
return
;
}
}
pthread_j
oin
(
thread
,
NULL
);
taosThreadJ
oin
(
thread
,
NULL
);
}
}
void
taosStopTcpServer
(
void
*
handle
)
{
void
taosStopTcpServer
(
void
*
handle
)
{
...
@@ -200,10 +200,10 @@ void taosStopTcpServer(void *handle) {
...
@@ -200,10 +200,10 @@ void taosStopTcpServer(void *handle) {
taosShutDownSocketServerRD
(
pServerObj
->
pSocketServer
);
taosShutDownSocketServerRD
(
pServerObj
->
pSocketServer
);
}
}
if
(
taosCheckPthreadValid
(
pServerObj
->
thread
))
{
if
(
taosCheckPthreadValid
(
pServerObj
->
thread
))
{
if
(
taosComparePthread
(
pServerObj
->
thread
,
pthread_s
elf
()))
{
if
(
taosComparePthread
(
pServerObj
->
thread
,
taosThreadS
elf
()))
{
pthread_detach
(
pthread_s
elf
());
pthread_detach
(
taosThreadS
elf
());
}
else
{
}
else
{
pthread_j
oin
(
pServerObj
->
thread
,
NULL
);
taosThreadJ
oin
(
pServerObj
->
thread
,
NULL
);
}
}
}
}
...
@@ -307,9 +307,9 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
...
@@ -307,9 +307,9 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
}
}
int
code
=
0
;
int
code
=
0
;
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
for
(
int
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
SThreadObj
*
pThreadObj
=
(
SThreadObj
*
)
calloc
(
1
,
sizeof
(
SThreadObj
));
SThreadObj
*
pThreadObj
=
(
SThreadObj
*
)
calloc
(
1
,
sizeof
(
SThreadObj
));
...
@@ -318,7 +318,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
...
@@ -318,7 +318,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
for
(
int
j
=
0
;
j
<
i
;
++
j
)
free
(
pClientObj
->
pThreadObj
[
j
]);
for
(
int
j
=
0
;
j
<
i
;
++
j
)
free
(
pClientObj
->
pThreadObj
[
j
]);
free
(
pClientObj
);
free
(
pClientObj
);
pthread_attr_d
estroy
(
&
thattr
);
taosThreadAttrD
estroy
(
&
thattr
);
return
NULL
;
return
NULL
;
}
}
pClientObj
->
pThreadObj
[
i
]
=
pThreadObj
;
pClientObj
->
pThreadObj
[
i
]
=
pThreadObj
;
...
@@ -333,7 +333,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
...
@@ -333,7 +333,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
// initialize mutex, thread, fd which may fail
// initialize mutex, thread, fd which may fail
for
(
int
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
SThreadObj
*
pThreadObj
=
pClientObj
->
pThreadObj
[
i
];
SThreadObj
*
pThreadObj
=
pClientObj
->
pThreadObj
[
i
];
code
=
pthread_mutex_i
nit
(
&
(
pThreadObj
->
mutex
),
NULL
);
code
=
taosThreadMutexI
nit
(
&
(
pThreadObj
->
mutex
),
NULL
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
tError
(
"%s failed to init TCP process data mutex(%s)"
,
label
,
strerror
(
errno
));
tError
(
"%s failed to init TCP process data mutex(%s)"
,
label
,
strerror
(
errno
));
break
;
break
;
...
@@ -346,7 +346,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
...
@@ -346,7 +346,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread
break
;
break
;
}
}
code
=
pthread_c
reate
(
&
(
pThreadObj
->
thread
),
&
thattr
,
taosProcessTcpData
,
(
void
*
)(
pThreadObj
));
code
=
taosThreadC
reate
(
&
(
pThreadObj
->
thread
),
&
thattr
,
taosProcessTcpData
,
(
void
*
)(
pThreadObj
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
tError
(
"%s failed to create TCP process data thread(%s)"
,
label
,
strerror
(
errno
));
tError
(
"%s failed to create TCP process data thread(%s)"
,
label
,
strerror
(
errno
));
break
;
break
;
...
@@ -578,7 +578,7 @@ static void *taosProcessTcpData(void *param) {
...
@@ -578,7 +578,7 @@ static void *taosProcessTcpData(void *param) {
taosReportBrokenLink
(
pFdObj
);
taosReportBrokenLink
(
pFdObj
);
}
}
pthread_mutex_d
estroy
(
&
(
pThreadObj
->
mutex
));
taosThreadMutexD
estroy
(
&
(
pThreadObj
->
mutex
));
tDebug
(
"%s TCP thread exits ..."
,
pThreadObj
->
label
);
tDebug
(
"%s TCP thread exits ..."
,
pThreadObj
->
label
);
tfree
(
pThreadObj
);
tfree
(
pThreadObj
);
...
@@ -607,12 +607,12 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, TdSocketPtr pSocket) {
...
@@ -607,12 +607,12 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, TdSocketPtr pSocket) {
}
}
// notify the data process, add into the FdObj list
// notify the data process, add into the FdObj list
pthread_mutex_l
ock
(
&
(
pThreadObj
->
mutex
));
taosThreadMutexL
ock
(
&
(
pThreadObj
->
mutex
));
pFdObj
->
next
=
pThreadObj
->
pHead
;
pFdObj
->
next
=
pThreadObj
->
pHead
;
if
(
pThreadObj
->
pHead
)
(
pThreadObj
->
pHead
)
->
prev
=
pFdObj
;
if
(
pThreadObj
->
pHead
)
(
pThreadObj
->
pHead
)
->
prev
=
pFdObj
;
pThreadObj
->
pHead
=
pFdObj
;
pThreadObj
->
pHead
=
pFdObj
;
pThreadObj
->
numOfFds
++
;
pThreadObj
->
numOfFds
++
;
pthread_mutex_u
nlock
(
&
(
pThreadObj
->
mutex
));
taosThreadMutexU
nlock
(
&
(
pThreadObj
->
mutex
));
return
pFdObj
;
return
pFdObj
;
}
}
...
@@ -622,10 +622,10 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
...
@@ -622,10 +622,10 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
if
(
pFdObj
->
signature
!=
pFdObj
)
return
;
if
(
pFdObj
->
signature
!=
pFdObj
)
return
;
SThreadObj
*
pThreadObj
=
pFdObj
->
pThreadObj
;
SThreadObj
*
pThreadObj
=
pFdObj
->
pThreadObj
;
pthread_mutex_l
ock
(
&
pThreadObj
->
mutex
);
taosThreadMutexL
ock
(
&
pThreadObj
->
mutex
);
if
(
pFdObj
->
signature
==
NULL
)
{
if
(
pFdObj
->
signature
==
NULL
)
{
pthread_mutex_u
nlock
(
&
pThreadObj
->
mutex
);
taosThreadMutexU
nlock
(
&
pThreadObj
->
mutex
);
return
;
return
;
}
}
...
@@ -648,7 +648,7 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
...
@@ -648,7 +648,7 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
(
pFdObj
->
next
)
->
prev
=
pFdObj
->
prev
;
(
pFdObj
->
next
)
->
prev
=
pFdObj
->
prev
;
}
}
pthread_mutex_u
nlock
(
&
pThreadObj
->
mutex
);
taosThreadMutexU
nlock
(
&
pThreadObj
->
mutex
);
tDebug
(
"%s %p TCP connection is closed, FD:%p numOfFds:%d"
,
pThreadObj
->
label
,
pFdObj
->
thandle
,
pFdObj
,
pThreadObj
->
numOfFds
);
tDebug
(
"%s %p TCP connection is closed, FD:%p numOfFds:%d"
,
pThreadObj
->
label
,
pFdObj
->
thandle
,
pFdObj
,
pThreadObj
->
numOfFds
);
...
...
source/libs/transport/src/rpcUdp.c
浏览文件 @
3544df41
...
@@ -35,7 +35,7 @@ typedef struct {
...
@@ -35,7 +35,7 @@ typedef struct {
uint16_t
port
;
// peer port
uint16_t
port
;
// peer port
uint16_t
localPort
;
// local port
uint16_t
localPort
;
// local port
char
label
[
TSDB_LABEL_LEN
];
// copy from udpConnSet;
char
label
[
TSDB_LABEL_LEN
];
// copy from udpConnSet;
pthread_t
thread
;
TdThread
thread
;
void
*
hash
;
void
*
hash
;
void
*
shandle
;
// handle passed by upper layer during server initialization
void
*
shandle
;
// handle passed by upper layer during server initialization
void
*
pSet
;
void
*
pSet
;
...
@@ -77,9 +77,9 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
...
@@ -77,9 +77,9 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
pSet
->
threads
=
threads
;
pSet
->
threads
=
threads
;
tstrncpy
(
pSet
->
label
,
label
,
sizeof
(
pSet
->
label
));
tstrncpy
(
pSet
->
label
,
label
,
sizeof
(
pSet
->
label
));
pthread_attr_t
thAttr
;
TdThreadAttr
thAttr
;
pthread_attr_i
nit
(
&
thAttr
);
taosThreadAttrI
nit
(
&
thAttr
);
pthread_attr_setdetachs
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
int
i
;
int
i
;
uint16_t
ownPort
;
uint16_t
ownPort
;
...
@@ -111,14 +111,14 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
...
@@ -111,14 +111,14 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
pConn
->
index
=
i
;
pConn
->
index
=
i
;
pConn
->
pSet
=
pSet
;
pConn
->
pSet
=
pSet
;
int
code
=
pthread_c
reate
(
&
pConn
->
thread
,
&
thAttr
,
taosRecvUdpData
,
pConn
);
int
code
=
taosThreadC
reate
(
&
pConn
->
thread
,
&
thAttr
,
taosRecvUdpData
,
pConn
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
tError
(
"%s failed to create thread to process UDP data(%s)"
,
label
,
strerror
(
errno
));
tError
(
"%s failed to create thread to process UDP data(%s)"
,
label
,
strerror
(
errno
));
break
;
break
;
}
}
}
}
pthread_attr_d
estroy
(
&
thAttr
);
taosThreadAttrD
estroy
(
&
thAttr
);
if
(
i
!=
threads
)
{
if
(
i
!=
threads
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
@@ -146,7 +146,7 @@ void taosStopUdpConnection(void *handle) {
...
@@ -146,7 +146,7 @@ void taosStopUdpConnection(void *handle) {
for
(
int
i
=
0
;
i
<
pSet
->
threads
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pSet
->
threads
;
++
i
)
{
pConn
=
pSet
->
udpConn
+
i
;
pConn
=
pSet
->
udpConn
+
i
;
if
(
taosCheckPthreadValid
(
pConn
->
thread
))
{
if
(
taosCheckPthreadValid
(
pConn
->
thread
))
{
pthread_j
oin
(
pConn
->
thread
,
NULL
);
taosThreadJ
oin
(
pConn
->
thread
,
NULL
);
}
}
tfree
(
pConn
->
buffer
);
tfree
(
pConn
->
buffer
);
// tTrace("%s UDP thread is closed, index:%d", pConn->label, i);
// tTrace("%s UDP thread is closed, index:%d", pConn->label, i);
...
...
source/libs/transport/src/thttp.c
浏览文件 @
3544df41
...
@@ -14,10 +14,13 @@
...
@@ -14,10 +14,13 @@
*/
*/
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#ifdef USE_UV
#include <uv.h>
#endif
#include "zlib.h"
#include "thttp.h"
#include "thttp.h"
#include "taoserror.h"
#include "taoserror.h"
#include "tlog.h"
#include "tlog.h"
#include "zlib.h"
static
int32_t
taosBuildHttpHeader
(
const
char
*
server
,
int32_t
contLen
,
char
*
pHead
,
int32_t
headLen
,
static
int32_t
taosBuildHttpHeader
(
const
char
*
server
,
int32_t
contLen
,
char
*
pHead
,
int32_t
headLen
,
EHttpCompFlag
flag
)
{
EHttpCompFlag
flag
)
{
...
@@ -111,7 +114,6 @@ _OVER:
...
@@ -111,7 +114,6 @@ _OVER:
}
}
#ifdef USE_UV
#ifdef USE_UV
#include <uv.h>
static
void
clientConnCb
(
uv_connect_t
*
req
,
int32_t
status
)
{
static
void
clientConnCb
(
uv_connect_t
*
req
,
int32_t
status
)
{
if
(
status
<
0
)
{
if
(
status
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
status
);
terrno
=
TAOS_SYSTEM_ERROR
(
status
);
...
...
source/libs/transport/src/transCli.c
浏览文件 @
3544df41
...
@@ -56,7 +56,7 @@ typedef struct SCliMsg {
...
@@ -56,7 +56,7 @@ typedef struct SCliMsg {
}
SCliMsg
;
}
SCliMsg
;
typedef
struct
SCliThrdObj
{
typedef
struct
SCliThrdObj
{
pthread_t
thread
;
TdThread
thread
;
uv_loop_t
*
loop
;
uv_loop_t
*
loop
;
SAsyncPool
*
asyncPool
;
SAsyncPool
*
asyncPool
;
uv_timer_t
timer
;
uv_timer_t
timer
;
...
@@ -64,7 +64,7 @@ typedef struct SCliThrdObj {
...
@@ -64,7 +64,7 @@ typedef struct SCliThrdObj {
// msg queue
// msg queue
queue
msg
;
queue
msg
;
pthread_mutex_t
msgMtx
;
TdThreadMutex
msgMtx
;
uint64_t
nextTimeout
;
// next timeout
uint64_t
nextTimeout
;
// next timeout
void
*
pTransInst
;
//
void
*
pTransInst
;
//
...
@@ -668,9 +668,9 @@ static void cliAsyncCb(uv_async_t* handle) {
...
@@ -668,9 +668,9 @@ static void cliAsyncCb(uv_async_t* handle) {
// batch process to avoid to lock/unlock frequently
// batch process to avoid to lock/unlock frequently
queue
wq
;
queue
wq
;
pthread_mutex_l
ock
(
&
item
->
mtx
);
taosThreadMutexL
ock
(
&
item
->
mtx
);
QUEUE_MOVE
(
&
item
->
qmsg
,
&
wq
);
QUEUE_MOVE
(
&
item
->
qmsg
,
&
wq
);
pthread_mutex_u
nlock
(
&
item
->
mtx
);
taosThreadMutexU
nlock
(
&
item
->
mtx
);
int
count
=
0
;
int
count
=
0
;
while
(
!
QUEUE_IS_EMPTY
(
&
wq
))
{
while
(
!
QUEUE_IS_EMPTY
(
&
wq
))
{
...
@@ -710,7 +710,7 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
...
@@ -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
->
nextTimeout
=
taosGetTimestampMs
()
+
CONN_PERSIST_TIME
(
pTransInst
->
idleTime
);
pThrd
->
pTransInst
=
shandle
;
pThrd
->
pTransInst
=
shandle
;
int
err
=
pthread_c
reate
(
&
pThrd
->
thread
,
NULL
,
cliWorkThread
,
(
void
*
)(
pThrd
));
int
err
=
taosThreadC
reate
(
&
pThrd
->
thread
,
NULL
,
cliWorkThread
,
(
void
*
)(
pThrd
));
if
(
err
==
0
)
{
if
(
err
==
0
)
{
tDebug
(
"success to create tranport-cli thread %d"
,
i
);
tDebug
(
"success to create tranport-cli thread %d"
,
i
);
}
}
...
@@ -739,7 +739,7 @@ static SCliThrdObj* createThrdObj() {
...
@@ -739,7 +739,7 @@ static SCliThrdObj* createThrdObj() {
SCliThrdObj
*
pThrd
=
(
SCliThrdObj
*
)
calloc
(
1
,
sizeof
(
SCliThrdObj
));
SCliThrdObj
*
pThrd
=
(
SCliThrdObj
*
)
calloc
(
1
,
sizeof
(
SCliThrdObj
));
QUEUE_INIT
(
&
pThrd
->
msg
);
QUEUE_INIT
(
&
pThrd
->
msg
);
pthread_mutex_i
nit
(
&
pThrd
->
msgMtx
,
NULL
);
taosThreadMutexI
nit
(
&
pThrd
->
msgMtx
,
NULL
);
pThrd
->
loop
=
(
uv_loop_t
*
)
malloc
(
sizeof
(
uv_loop_t
));
pThrd
->
loop
=
(
uv_loop_t
*
)
malloc
(
sizeof
(
uv_loop_t
));
uv_loop_init
(
pThrd
->
loop
);
uv_loop_init
(
pThrd
->
loop
);
...
@@ -759,8 +759,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd) {
...
@@ -759,8 +759,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd) {
return
;
return
;
}
}
uv_stop
(
pThrd
->
loop
);
uv_stop
(
pThrd
->
loop
);
pthread_j
oin
(
pThrd
->
thread
,
NULL
);
taosThreadJ
oin
(
pThrd
->
thread
,
NULL
);
pthread_mutex_d
estroy
(
&
pThrd
->
msgMtx
);
taosThreadMutexD
estroy
(
&
pThrd
->
msgMtx
);
transDestroyAsyncPool
(
pThrd
->
asyncPool
);
transDestroyAsyncPool
(
pThrd
->
asyncPool
);
uv_timer_stop
(
&
pThrd
->
timer
);
uv_timer_stop
(
&
pThrd
->
timer
);
...
...
source/libs/transport/src/transComm.c
浏览文件 @
3544df41
...
@@ -186,7 +186,7 @@ SAsyncPool* transCreateAsyncPool(uv_loop_t* loop, int sz, void* arg, AsyncCB cb)
...
@@ -186,7 +186,7 @@ SAsyncPool* transCreateAsyncPool(uv_loop_t* loop, int sz, void* arg, AsyncCB cb)
SAsyncItem
*
item
=
calloc
(
1
,
sizeof
(
SAsyncItem
));
SAsyncItem
*
item
=
calloc
(
1
,
sizeof
(
SAsyncItem
));
item
->
pThrd
=
arg
;
item
->
pThrd
=
arg
;
QUEUE_INIT
(
&
item
->
qmsg
);
QUEUE_INIT
(
&
item
->
qmsg
);
pthread_mutex_i
nit
(
&
item
->
mtx
,
NULL
);
taosThreadMutexI
nit
(
&
item
->
mtx
,
NULL
);
async
->
data
=
item
;
async
->
data
=
item
;
}
}
...
@@ -197,7 +197,7 @@ void transDestroyAsyncPool(SAsyncPool* pool) {
...
@@ -197,7 +197,7 @@ void transDestroyAsyncPool(SAsyncPool* pool) {
uv_async_t
*
async
=
&
(
pool
->
asyncs
[
i
]);
uv_async_t
*
async
=
&
(
pool
->
asyncs
[
i
]);
SAsyncItem
*
item
=
async
->
data
;
SAsyncItem
*
item
=
async
->
data
;
pthread_mutex_d
estroy
(
&
item
->
mtx
);
taosThreadMutexD
estroy
(
&
item
->
mtx
);
free
(
item
);
free
(
item
);
}
}
free
(
pool
->
asyncs
);
free
(
pool
->
asyncs
);
...
@@ -214,9 +214,9 @@ int transSendAsync(SAsyncPool* pool, queue* q) {
...
@@ -214,9 +214,9 @@ int transSendAsync(SAsyncPool* pool, queue* q) {
SAsyncItem
*
item
=
async
->
data
;
SAsyncItem
*
item
=
async
->
data
;
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
pthread_mutex_l
ock
(
&
item
->
mtx
);
taosThreadMutexL
ock
(
&
item
->
mtx
);
QUEUE_PUSH
(
&
item
->
qmsg
,
q
);
QUEUE_PUSH
(
&
item
->
qmsg
,
q
);
pthread_mutex_u
nlock
(
&
item
->
mtx
);
taosThreadMutexU
nlock
(
&
item
->
mtx
);
int64_t
el
=
taosGetTimestampUs
()
-
st
;
int64_t
el
=
taosGetTimestampUs
()
-
st
;
if
(
el
>
50
)
{
if
(
el
>
50
)
{
// tInfo("lock and unlock cost: %d", (int)el);
// tInfo("lock and unlock cost: %d", (int)el);
...
...
source/libs/transport/src/transSrv.c
浏览文件 @
3544df41
...
@@ -62,13 +62,13 @@ typedef struct SSrvMsg {
...
@@ -62,13 +62,13 @@ typedef struct SSrvMsg {
}
SSrvMsg
;
}
SSrvMsg
;
typedef
struct
SWorkThrdObj
{
typedef
struct
SWorkThrdObj
{
pthread_t
thread
;
TdThread
thread
;
uv_pipe_t
*
pipe
;
uv_pipe_t
*
pipe
;
uv_os_fd_t
fd
;
uv_os_fd_t
fd
;
uv_loop_t
*
loop
;
uv_loop_t
*
loop
;
SAsyncPool
*
asyncPool
;
SAsyncPool
*
asyncPool
;
queue
msg
;
queue
msg
;
pthread_mutex_t
msgMtx
;
TdThreadMutex
msgMtx
;
queue
conn
;
queue
conn
;
void
*
pTransInst
;
void
*
pTransInst
;
...
@@ -76,7 +76,7 @@ typedef struct SWorkThrdObj {
...
@@ -76,7 +76,7 @@ typedef struct SWorkThrdObj {
}
SWorkThrdObj
;
}
SWorkThrdObj
;
typedef
struct
SServerObj
{
typedef
struct
SServerObj
{
pthread_t
thread
;
TdThread
thread
;
uv_tcp_t
server
;
uv_tcp_t
server
;
uv_loop_t
*
loop
;
uv_loop_t
*
loop
;
...
@@ -476,9 +476,9 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
...
@@ -476,9 +476,9 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
queue
wq
;
queue
wq
;
// batch process to avoid to lock/unlock frequently
// batch process to avoid to lock/unlock frequently
pthread_mutex_l
ock
(
&
item
->
mtx
);
taosThreadMutexL
ock
(
&
item
->
mtx
);
QUEUE_MOVE
(
&
item
->
qmsg
,
&
wq
);
QUEUE_MOVE
(
&
item
->
qmsg
,
&
wq
);
pthread_mutex_u
nlock
(
&
item
->
mtx
);
taosThreadMutexU
nlock
(
&
item
->
mtx
);
while
(
!
QUEUE_IS_EMPTY
(
&
wq
))
{
while
(
!
QUEUE_IS_EMPTY
(
&
wq
))
{
queue
*
head
=
QUEUE_HEAD
(
&
wq
);
queue
*
head
=
QUEUE_HEAD
(
&
wq
);
...
@@ -622,7 +622,7 @@ static bool addHandleToWorkloop(void* arg) {
...
@@ -622,7 +622,7 @@ static bool addHandleToWorkloop(void* arg) {
pThrd
->
pipe
->
data
=
pThrd
;
pThrd
->
pipe
->
data
=
pThrd
;
QUEUE_INIT
(
&
pThrd
->
msg
);
QUEUE_INIT
(
&
pThrd
->
msg
);
pthread_mutex_i
nit
(
&
pThrd
->
msgMtx
,
NULL
);
taosThreadMutexI
nit
(
&
pThrd
->
msgMtx
,
NULL
);
// conn set
// conn set
QUEUE_INIT
(
&
pThrd
->
conn
);
QUEUE_INIT
(
&
pThrd
->
conn
);
...
@@ -771,7 +771,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
...
@@ -771,7 +771,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
if
(
false
==
addHandleToWorkloop
(
thrd
))
{
if
(
false
==
addHandleToWorkloop
(
thrd
))
{
goto
End
;
goto
End
;
}
}
int
err
=
pthread_c
reate
(
&
(
thrd
->
thread
),
NULL
,
workerThread
,
(
void
*
)(
thrd
));
int
err
=
taosThreadC
reate
(
&
(
thrd
->
thread
),
NULL
,
workerThread
,
(
void
*
)(
thrd
));
if
(
err
==
0
)
{
if
(
err
==
0
)
{
tDebug
(
"sucess to create worker-thread %d"
,
i
);
tDebug
(
"sucess to create worker-thread %d"
,
i
);
// printf("thread %d create\n", i);
// printf("thread %d create\n", i);
...
@@ -783,7 +783,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
...
@@ -783,7 +783,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
if
(
false
==
addHandleToAcceptloop
(
srv
))
{
if
(
false
==
addHandleToAcceptloop
(
srv
))
{
goto
End
;
goto
End
;
}
}
int
err
=
pthread_c
reate
(
&
srv
->
thread
,
NULL
,
acceptThread
,
(
void
*
)
srv
);
int
err
=
taosThreadC
reate
(
&
srv
->
thread
,
NULL
,
acceptThread
,
(
void
*
)
srv
);
if
(
err
==
0
)
{
if
(
err
==
0
)
{
tDebug
(
"success to create accept-thread"
);
tDebug
(
"success to create accept-thread"
);
}
else
{
}
else
{
...
@@ -850,7 +850,7 @@ void destroyWorkThrd(SWorkThrdObj* pThrd) {
...
@@ -850,7 +850,7 @@ void destroyWorkThrd(SWorkThrdObj* pThrd) {
if
(
pThrd
==
NULL
)
{
if
(
pThrd
==
NULL
)
{
return
;
return
;
}
}
pthread_j
oin
(
pThrd
->
thread
,
NULL
);
taosThreadJ
oin
(
pThrd
->
thread
,
NULL
);
free
(
pThrd
->
loop
);
free
(
pThrd
->
loop
);
transDestroyAsyncPool
(
pThrd
->
asyncPool
);
transDestroyAsyncPool
(
pThrd
->
asyncPool
);
free
(
pThrd
);
free
(
pThrd
);
...
@@ -872,7 +872,7 @@ void transCloseServer(void* arg) {
...
@@ -872,7 +872,7 @@ void transCloseServer(void* arg) {
tDebug
(
"send quit msg to accept thread"
);
tDebug
(
"send quit msg to accept thread"
);
uv_async_send
(
srv
->
pAcceptAsync
);
uv_async_send
(
srv
->
pAcceptAsync
);
pthread_j
oin
(
srv
->
thread
,
NULL
);
taosThreadJ
oin
(
srv
->
thread
,
NULL
);
free
(
srv
->
pThreadObj
);
free
(
srv
->
pThreadObj
);
free
(
srv
->
pAcceptAsync
);
free
(
srv
->
pAcceptAsync
);
...
...
source/libs/transport/test/rclient.c
浏览文件 @
3544df41
...
@@ -30,7 +30,7 @@ typedef struct {
...
@@ -30,7 +30,7 @@ typedef struct {
int
msgSize
;
int
msgSize
;
tsem_t
rspSem
;
tsem_t
rspSem
;
tsem_t
*
pOverSem
;
tsem_t
*
pOverSem
;
pthread_t
thread
;
TdThread
thread
;
void
*
pRpc
;
void
*
pRpc
;
}
SInfo
;
}
SInfo
;
static
void
processResponse
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
static
void
processResponse
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
...
@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
...
@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
char
secret
[
20
]
=
"mypassword"
;
char
secret
[
20
]
=
"mypassword"
;
struct
timeval
systemTime
;
struct
timeval
systemTime
;
int64_t
startTime
,
endTime
;
int64_t
startTime
,
endTime
;
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
// server info
// server info
epSet
.
inUse
=
0
;
epSet
.
inUse
=
0
;
...
@@ -186,8 +186,8 @@ int main(int argc, char *argv[]) {
...
@@ -186,8 +186,8 @@ int main(int argc, char *argv[]) {
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
for
(
int
i
=
0
;
i
<
appThreads
;
++
i
)
{
for
(
int
i
=
0
;
i
<
appThreads
;
++
i
)
{
pInfo
->
index
=
i
;
pInfo
->
index
=
i
;
...
@@ -196,7 +196,7 @@ int main(int argc, char *argv[]) {
...
@@ -196,7 +196,7 @@ int main(int argc, char *argv[]) {
pInfo
->
msgSize
=
msgSize
;
pInfo
->
msgSize
=
msgSize
;
tsem_init
(
&
pInfo
->
rspSem
,
0
,
0
);
tsem_init
(
&
pInfo
->
rspSem
,
0
,
0
);
pInfo
->
pRpc
=
pRpc
;
pInfo
->
pRpc
=
pRpc
;
pthread_c
reate
(
&
pInfo
->
thread
,
&
thattr
,
sendRequest
,
pInfo
);
taosThreadC
reate
(
&
pInfo
->
thread
,
&
thattr
,
sendRequest
,
pInfo
);
pInfo
++
;
pInfo
++
;
}
}
...
...
source/libs/transport/test/rsclient.c
浏览文件 @
3544df41
...
@@ -29,7 +29,7 @@ typedef struct {
...
@@ -29,7 +29,7 @@ typedef struct {
int
msgSize
;
int
msgSize
;
tsem_t
rspSem
;
tsem_t
rspSem
;
tsem_t
*
pOverSem
;
tsem_t
*
pOverSem
;
pthread_t
thread
;
TdThread
thread
;
void
*
pRpc
;
void
*
pRpc
;
}
SInfo
;
}
SInfo
;
...
@@ -80,7 +80,7 @@ int main(int argc, char *argv[]) {
...
@@ -80,7 +80,7 @@ int main(int argc, char *argv[]) {
char
secret
[
TSDB_KEY_LEN
]
=
"mypassword"
;
char
secret
[
TSDB_KEY_LEN
]
=
"mypassword"
;
struct
timeval
systemTime
;
struct
timeval
systemTime
;
int64_t
startTime
,
endTime
;
int64_t
startTime
,
endTime
;
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
// server info
// server info
epSet
.
numOfEps
=
1
;
epSet
.
numOfEps
=
1
;
...
@@ -163,8 +163,8 @@ int main(int argc, char *argv[]) {
...
@@ -163,8 +163,8 @@ int main(int argc, char *argv[]) {
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
for
(
int
i
=
0
;
i
<
appThreads
;
++
i
)
{
for
(
int
i
=
0
;
i
<
appThreads
;
++
i
)
{
pInfo
->
index
=
i
;
pInfo
->
index
=
i
;
...
@@ -173,7 +173,7 @@ int main(int argc, char *argv[]) {
...
@@ -173,7 +173,7 @@ int main(int argc, char *argv[]) {
pInfo
->
msgSize
=
msgSize
;
pInfo
->
msgSize
=
msgSize
;
tsem_init
(
&
pInfo
->
rspSem
,
0
,
0
);
tsem_init
(
&
pInfo
->
rspSem
,
0
,
0
);
pInfo
->
pRpc
=
pRpc
;
pInfo
->
pRpc
=
pRpc
;
pthread_c
reate
(
&
pInfo
->
thread
,
&
thattr
,
sendRequest
,
pInfo
);
taosThreadC
reate
(
&
pInfo
->
thread
,
&
thattr
,
sendRequest
,
pInfo
);
pInfo
++
;
pInfo
++
;
}
}
...
...
source/libs/transport/test/syncClient.c
浏览文件 @
3544df41
...
@@ -30,7 +30,7 @@ typedef struct {
...
@@ -30,7 +30,7 @@ typedef struct {
int
msgSize
;
int
msgSize
;
tsem_t
rspSem
;
tsem_t
rspSem
;
tsem_t
*
pOverSem
;
tsem_t
*
pOverSem
;
pthread_t
thread
;
TdThread
thread
;
void
*
pRpc
;
void
*
pRpc
;
}
SInfo
;
}
SInfo
;
static
void
processResponse
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
static
void
processResponse
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
...
@@ -105,7 +105,7 @@ int main(int argc, char *argv[]) {
...
@@ -105,7 +105,7 @@ int main(int argc, char *argv[]) {
char
secret
[
20
]
=
"mypassword"
;
char
secret
[
20
]
=
"mypassword"
;
struct
timeval
systemTime
;
struct
timeval
systemTime
;
int64_t
startTime
,
endTime
;
int64_t
startTime
,
endTime
;
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
// server info
// server info
epSet
.
inUse
=
0
;
epSet
.
inUse
=
0
;
...
@@ -186,8 +186,8 @@ int main(int argc, char *argv[]) {
...
@@ -186,8 +186,8 @@ int main(int argc, char *argv[]) {
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
for
(
int
i
=
0
;
i
<
appThreads
;
++
i
)
{
for
(
int
i
=
0
;
i
<
appThreads
;
++
i
)
{
pInfo
->
index
=
i
;
pInfo
->
index
=
i
;
...
@@ -196,7 +196,7 @@ int main(int argc, char *argv[]) {
...
@@ -196,7 +196,7 @@ int main(int argc, char *argv[]) {
pInfo
->
msgSize
=
msgSize
;
pInfo
->
msgSize
=
msgSize
;
tsem_init
(
&
pInfo
->
rspSem
,
0
,
0
);
tsem_init
(
&
pInfo
->
rspSem
,
0
,
0
);
pInfo
->
pRpc
=
pRpc
;
pInfo
->
pRpc
=
pRpc
;
pthread_c
reate
(
&
pInfo
->
thread
,
&
thattr
,
sendRequest
,
pInfo
);
taosThreadC
reate
(
&
pInfo
->
thread
,
&
thattr
,
sendRequest
,
pInfo
);
pInfo
++
;
pInfo
++
;
}
}
...
...
source/libs/transport/test/uv.c
浏览文件 @
3544df41
#include <assert.h>
#include <assert.h>
#include <
pthread
.h>
#include <
uv
.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include "task.h"
#include "task.h"
#include <uv.h>
#define NUM_OF_THREAD 1
#define NUM_OF_THREAD 1
#define TIMEOUT 10000
#define TIMEOUT 10000
typedef
struct
SThreadObj
{
typedef
struct
SThreadObj
{
pthread_t
thread
;
TdThread
thread
;
uv_pipe_t
*
pipe
;
uv_pipe_t
*
pipe
;
uv_loop_t
*
loop
;
uv_loop_t
*
loop
;
uv_async_t
*
workerAsync
;
//
uv_async_t
*
workerAsync
;
//
...
@@ -183,7 +182,7 @@ int main() {
...
@@ -183,7 +182,7 @@ int main() {
server
->
pThreadObj
[
i
]
->
fd
=
fds
[
0
];
server
->
pThreadObj
[
i
]
->
fd
=
fds
[
0
];
server
->
pThreadObj
[
i
]
->
pipe
=
&
(
server
->
pipe
[
i
][
1
]);
// init read
server
->
pThreadObj
[
i
]
->
pipe
=
&
(
server
->
pipe
[
i
][
1
]);
// init read
int
err
=
pthread_c
reate
(
&
(
server
->
pThreadObj
[
i
]
->
thread
),
NULL
,
int
err
=
taosThreadC
reate
(
&
(
server
->
pThreadObj
[
i
]
->
thread
),
NULL
,
worker_thread
,
(
void
*
)(
server
->
pThreadObj
[
i
]));
worker_thread
,
(
void
*
)(
server
->
pThreadObj
[
i
]));
if
(
err
==
0
)
{
if
(
err
==
0
)
{
printf
(
"thread %d create
\n
"
,
i
);
printf
(
"thread %d create
\n
"
,
i
);
...
...
source/libs/wal/src/walMgmt.c
浏览文件 @
3544df41
...
@@ -25,7 +25,7 @@ typedef struct {
...
@@ -25,7 +25,7 @@ typedef struct {
int8_t
inited
;
int8_t
inited
;
uint32_t
seq
;
uint32_t
seq
;
int32_t
refSetId
;
int32_t
refSetId
;
pthread_t
thread
;
TdThread
thread
;
}
SWalMgmt
;
}
SWalMgmt
;
static
SWalMgmt
tsWal
=
{
0
,
.
seq
=
1
};
static
SWalMgmt
tsWal
=
{
0
,
.
seq
=
1
};
...
@@ -101,7 +101,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
...
@@ -101,7 +101,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
pWal
->
writeHead
.
head
.
headVer
=
WAL_HEAD_VER
;
pWal
->
writeHead
.
head
.
headVer
=
WAL_HEAD_VER
;
pWal
->
writeHead
.
magic
=
WAL_MAGIC
;
pWal
->
writeHead
.
magic
=
WAL_MAGIC
;
if
(
pthread_mutex_i
nit
(
&
pWal
->
mutex
,
NULL
)
<
0
)
{
if
(
taosThreadMutexI
nit
(
&
pWal
->
mutex
,
NULL
)
<
0
)
{
taosArrayDestroy
(
pWal
->
fileInfoSet
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
free
(
pWal
);
free
(
pWal
);
return
NULL
;
return
NULL
;
...
@@ -109,7 +109,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
...
@@ -109,7 +109,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
pWal
->
refId
=
taosAddRef
(
tsWal
.
refSetId
,
pWal
);
pWal
->
refId
=
taosAddRef
(
tsWal
.
refSetId
,
pWal
);
if
(
pWal
->
refId
<
0
)
{
if
(
pWal
->
refId
<
0
)
{
pthread_mutex_d
estroy
(
&
pWal
->
mutex
);
taosThreadMutexD
estroy
(
&
pWal
->
mutex
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
free
(
pWal
);
free
(
pWal
);
return
NULL
;
return
NULL
;
...
@@ -119,7 +119,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
...
@@ -119,7 +119,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
if
(
walCheckAndRepairMeta
(
pWal
)
<
0
)
{
if
(
walCheckAndRepairMeta
(
pWal
)
<
0
)
{
taosRemoveRef
(
tsWal
.
refSetId
,
pWal
->
refId
);
taosRemoveRef
(
tsWal
.
refSetId
,
pWal
->
refId
);
pthread_mutex_d
estroy
(
&
pWal
->
mutex
);
taosThreadMutexD
estroy
(
&
pWal
->
mutex
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
free
(
pWal
);
free
(
pWal
);
return
NULL
;
return
NULL
;
...
@@ -156,7 +156,7 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
...
@@ -156,7 +156,7 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
}
}
void
walClose
(
SWal
*
pWal
)
{
void
walClose
(
SWal
*
pWal
)
{
pthread_mutex_l
ock
(
&
pWal
->
mutex
);
taosThreadMutexL
ock
(
&
pWal
->
mutex
);
taosCloseFile
(
&
pWal
->
pWriteLogTFile
);
taosCloseFile
(
&
pWal
->
pWriteLogTFile
);
pWal
->
pWriteLogTFile
=
NULL
;
pWal
->
pWriteLogTFile
=
NULL
;
taosCloseFile
(
&
pWal
->
pWriteIdxTFile
);
taosCloseFile
(
&
pWal
->
pWriteIdxTFile
);
...
@@ -164,7 +164,7 @@ void walClose(SWal *pWal) {
...
@@ -164,7 +164,7 @@ void walClose(SWal *pWal) {
walSaveMeta
(
pWal
);
walSaveMeta
(
pWal
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
pWal
->
fileInfoSet
=
NULL
;
pWal
->
fileInfoSet
=
NULL
;
pthread_mutex_u
nlock
(
&
pWal
->
mutex
);
taosThreadMutexU
nlock
(
&
pWal
->
mutex
);
taosRemoveRef
(
tsWal
.
refSetId
,
pWal
->
refId
);
taosRemoveRef
(
tsWal
.
refSetId
,
pWal
->
refId
);
}
}
...
@@ -173,7 +173,7 @@ static void walFreeObj(void *wal) {
...
@@ -173,7 +173,7 @@ static void walFreeObj(void *wal) {
SWal
*
pWal
=
wal
;
SWal
*
pWal
=
wal
;
wDebug
(
"vgId:%d, wal:%p is freed"
,
pWal
->
cfg
.
vgId
,
pWal
);
wDebug
(
"vgId:%d, wal:%p is freed"
,
pWal
->
cfg
.
vgId
,
pWal
);
pthread_mutex_d
estroy
(
&
pWal
->
mutex
);
taosThreadMutexD
estroy
(
&
pWal
->
mutex
);
tfree
(
pWal
);
tfree
(
pWal
);
}
}
...
@@ -223,17 +223,17 @@ static void *walThreadFunc(void *param) {
...
@@ -223,17 +223,17 @@ static void *walThreadFunc(void *param) {
}
}
static
int32_t
walCreateThread
()
{
static
int32_t
walCreateThread
()
{
pthread_attr_t
thAttr
;
TdThreadAttr
thAttr
;
pthread_attr_i
nit
(
&
thAttr
);
taosThreadAttrI
nit
(
&
thAttr
);
pthread_attr_setdetachs
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_c
reate
(
&
tsWal
.
thread
,
&
thAttr
,
walThreadFunc
,
NULL
)
!=
0
)
{
if
(
taosThreadC
reate
(
&
tsWal
.
thread
,
&
thAttr
,
walThreadFunc
,
NULL
)
!=
0
)
{
wError
(
"failed to create wal thread since %s"
,
strerror
(
errno
));
wError
(
"failed to create wal thread since %s"
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
}
}
pthread_attr_d
estroy
(
&
thAttr
);
taosThreadAttrD
estroy
(
&
thAttr
);
wDebug
(
"wal thread is launched, thread:0x%08"
PRIx64
,
taosGetPthreadId
(
tsWal
.
thread
));
wDebug
(
"wal thread is launched, thread:0x%08"
PRIx64
,
taosGetPthreadId
(
tsWal
.
thread
));
return
0
;
return
0
;
...
@@ -243,7 +243,7 @@ static void walStopThread() {
...
@@ -243,7 +243,7 @@ static void walStopThread() {
atomic_store_8
(
&
tsWal
.
stop
,
1
);
atomic_store_8
(
&
tsWal
.
stop
,
1
);
if
(
taosCheckPthreadValid
(
tsWal
.
thread
))
{
if
(
taosCheckPthreadValid
(
tsWal
.
thread
))
{
pthread_j
oin
(
tsWal
.
thread
,
NULL
);
taosThreadJ
oin
(
tsWal
.
thread
,
NULL
);
}
}
wDebug
(
"wal thread is stopped"
);
wDebug
(
"wal thread is stopped"
);
...
...
source/libs/wal/src/walWrite.c
浏览文件 @
3544df41
...
@@ -38,7 +38,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
...
@@ -38,7 +38,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
terrno
=
TSDB_CODE_WAL_INVALID_VER
;
terrno
=
TSDB_CODE_WAL_INVALID_VER
;
return
-
1
;
return
-
1
;
}
}
pthread_mutex_l
ock
(
&
pWal
->
mutex
);
taosThreadMutexL
ock
(
&
pWal
->
mutex
);
// find correct file
// find correct file
if
(
ver
<
walGetLastFileFirstVer
(
pWal
))
{
if
(
ver
<
walGetLastFileFirstVer
(
pWal
))
{
...
@@ -65,20 +65,20 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
...
@@ -65,20 +65,20 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
// TODO:change to deserialize function
// TODO:change to deserialize function
if
(
pIdxTFile
==
NULL
)
{
if
(
pIdxTFile
==
NULL
)
{
pthread_mutex_u
nlock
(
&
pWal
->
mutex
);
taosThreadMutexU
nlock
(
&
pWal
->
mutex
);
return
-
1
;
return
-
1
;
}
}
int64_t
idxOff
=
walGetVerIdxOffset
(
pWal
,
ver
);
int64_t
idxOff
=
walGetVerIdxOffset
(
pWal
,
ver
);
code
=
taosLSeekFile
(
pIdxTFile
,
idxOff
,
SEEK_SET
);
code
=
taosLSeekFile
(
pIdxTFile
,
idxOff
,
SEEK_SET
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
pthread_mutex_u
nlock
(
&
pWal
->
mutex
);
taosThreadMutexU
nlock
(
&
pWal
->
mutex
);
return
-
1
;
return
-
1
;
}
}
// read idx file and get log file pos
// read idx file and get log file pos
// TODO:change to deserialize function
// TODO:change to deserialize function
SWalIdxEntry
entry
;
SWalIdxEntry
entry
;
if
(
taosReadFile
(
pIdxTFile
,
&
entry
,
sizeof
(
SWalIdxEntry
))
!=
sizeof
(
SWalIdxEntry
))
{
if
(
taosReadFile
(
pIdxTFile
,
&
entry
,
sizeof
(
SWalIdxEntry
))
!=
sizeof
(
SWalIdxEntry
))
{
pthread_mutex_u
nlock
(
&
pWal
->
mutex
);
taosThreadMutexU
nlock
(
&
pWal
->
mutex
);
return
-
1
;
return
-
1
;
}
}
ASSERT
(
entry
.
ver
==
ver
);
ASSERT
(
entry
.
ver
==
ver
);
...
@@ -87,13 +87,13 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
...
@@ -87,13 +87,13 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
TdFilePtr
pLogTFile
=
taosOpenFile
(
fnameStr
,
TD_FILE_WRITE
|
TD_FILE_READ
);
TdFilePtr
pLogTFile
=
taosOpenFile
(
fnameStr
,
TD_FILE_WRITE
|
TD_FILE_READ
);
if
(
pLogTFile
==
NULL
)
{
if
(
pLogTFile
==
NULL
)
{
// TODO
// TODO
pthread_mutex_u
nlock
(
&
pWal
->
mutex
);
taosThreadMutexU
nlock
(
&
pWal
->
mutex
);
return
-
1
;
return
-
1
;
}
}
code
=
taosLSeekFile
(
pLogTFile
,
entry
.
offset
,
SEEK_SET
);
code
=
taosLSeekFile
(
pLogTFile
,
entry
.
offset
,
SEEK_SET
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
// TODO
// TODO
pthread_mutex_u
nlock
(
&
pWal
->
mutex
);
taosThreadMutexU
nlock
(
&
pWal
->
mutex
);
return
-
1
;
return
-
1
;
}
}
// validate offset
// validate offset
...
@@ -127,7 +127,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
...
@@ -127,7 +127,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
((
SWalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
fileSize
=
entry
.
offset
;
((
SWalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
fileSize
=
entry
.
offset
;
// unlock
// unlock
pthread_mutex_u
nlock
(
&
pWal
->
mutex
);
taosThreadMutexU
nlock
(
&
pWal
->
mutex
);
return
0
;
return
0
;
}
}
...
@@ -283,7 +283,7 @@ int64_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in
...
@@ -283,7 +283,7 @@ int64_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in
ASSERT
(
pWal
->
writeCur
>=
0
);
ASSERT
(
pWal
->
writeCur
>=
0
);
pthread_mutex_l
ock
(
&
pWal
->
mutex
);
taosThreadMutexL
ock
(
&
pWal
->
mutex
);
if
(
pWal
->
pWriteIdxTFile
==
NULL
||
pWal
->
pWriteLogTFile
==
NULL
)
{
if
(
pWal
->
pWriteIdxTFile
==
NULL
||
pWal
->
pWriteLogTFile
==
NULL
)
{
walSetWrite
(
pWal
);
walSetWrite
(
pWal
);
...
@@ -327,7 +327,7 @@ int64_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in
...
@@ -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
)
->
lastVer
=
index
;
walGetCurFileInfo
(
pWal
)
->
fileSize
+=
sizeof
(
SWalHead
)
+
bodyLen
;
walGetCurFileInfo
(
pWal
)
->
fileSize
+=
sizeof
(
SWalHead
)
+
bodyLen
;
pthread_mutex_u
nlock
(
&
pWal
->
mutex
);
taosThreadMutexU
nlock
(
&
pWal
->
mutex
);
return
0
;
return
0
;
}
}
...
...
source/os/src/osFile.c
浏览文件 @
3544df41
...
@@ -57,7 +57,7 @@ typedef int32_t SocketFd;
...
@@ -57,7 +57,7 @@ typedef int32_t SocketFd;
typedef
int32_t
FileFd
;
typedef
int32_t
FileFd
;
typedef
struct
TdFile
{
typedef
struct
TdFile
{
pthread_rwlock_t
rwlock
;
TdThreadRwlock
rwlock
;
int
refId
;
int
refId
;
FileFd
fd
;
FileFd
fd
;
FILE
*
fp
;
FILE
*
fp
;
...
@@ -275,7 +275,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
...
@@ -275,7 +275,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
return
NULL
;
return
NULL
;
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_i
nit
(
&
(
pFile
->
rwlock
),
NULL
);
taosThreadRwlockI
nit
(
&
(
pFile
->
rwlock
),
NULL
);
#endif
#endif
pFile
->
fd
=
fd
;
pFile
->
fd
=
fd
;
pFile
->
fp
=
fp
;
pFile
->
fp
=
fp
;
...
@@ -292,7 +292,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
...
@@ -292,7 +292,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
return
0
;
return
0
;
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_w
rlock
(
&
((
*
ppFile
)
->
rwlock
));
taosThreadRwlockW
rlock
(
&
((
*
ppFile
)
->
rwlock
));
#endif
#endif
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
||
(
*
ppFile
)
->
fd
==
-
1
)
{
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
||
(
*
ppFile
)
->
fd
==
-
1
)
{
return
0
;
return
0
;
...
@@ -309,8 +309,8 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
...
@@ -309,8 +309,8 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
}
}
(
*
ppFile
)
->
refId
=
0
;
(
*
ppFile
)
->
refId
=
0
;
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_u
nlock
(
&
((
*
ppFile
)
->
rwlock
));
taosThreadRwlockU
nlock
(
&
((
*
ppFile
)
->
rwlock
));
pthread_rwlock_d
estroy
(
&
((
*
ppFile
)
->
rwlock
));
taosThreadRwlockD
estroy
(
&
((
*
ppFile
)
->
rwlock
));
#endif
#endif
free
(
*
ppFile
);
free
(
*
ppFile
);
*
ppFile
=
NULL
;
*
ppFile
=
NULL
;
...
@@ -323,7 +323,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
...
@@ -323,7 +323,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
return
0
;
return
0
;
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_r
dlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockR
dlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
assert
(
pFile
->
fd
>=
0
);
assert
(
pFile
->
fd
>=
0
);
int64_t
leftbytes
=
count
;
int64_t
leftbytes
=
count
;
...
@@ -337,13 +337,13 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
...
@@ -337,13 +337,13 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
continue
;
continue
;
}
else
{
}
else
{
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_u
nlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockU
nlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
return
-
1
;
return
-
1
;
}
}
}
else
if
(
readbytes
==
0
)
{
}
else
if
(
readbytes
==
0
)
{
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_u
nlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockU
nlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
return
(
int64_t
)(
count
-
leftbytes
);
return
(
int64_t
)(
count
-
leftbytes
);
}
}
...
@@ -353,7 +353,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
...
@@ -353,7 +353,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_u
nlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockU
nlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
return
count
;
return
count
;
}
}
...
@@ -363,12 +363,12 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
...
@@ -363,12 +363,12 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
return
0
;
return
0
;
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_r
dlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockR
dlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
assert
(
pFile
->
fd
>=
0
);
assert
(
pFile
->
fd
>=
0
);
int64_t
ret
=
pread
(
pFile
->
fd
,
buf
,
count
,
offset
);
int64_t
ret
=
pread
(
pFile
->
fd
,
buf
,
count
,
offset
);
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_u
nlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockU
nlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
return
ret
;
return
ret
;
}
}
...
@@ -378,7 +378,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
...
@@ -378,7 +378,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
return
0
;
return
0
;
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_w
rlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockW
rlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
assert
(
pFile
->
fd
>=
0
);
assert
(
pFile
->
fd
>=
0
);
...
@@ -393,7 +393,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
...
@@ -393,7 +393,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
continue
;
continue
;
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_u
nlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockU
nlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
return
-
1
;
return
-
1
;
}
}
...
@@ -402,7 +402,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
...
@@ -402,7 +402,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_u
nlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockU
nlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
return
count
;
return
count
;
}
}
...
@@ -412,12 +412,12 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
...
@@ -412,12 +412,12 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
return
0
;
return
0
;
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_r
dlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockR
dlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
assert
(
pFile
->
fd
>=
0
);
assert
(
pFile
->
fd
>=
0
);
int64_t
ret
=
lseek
(
pFile
->
fd
,
(
long
)
offset
,
whence
);
int64_t
ret
=
lseek
(
pFile
->
fd
,
(
long
)
offset
,
whence
);
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
pthread_rwlock_u
nlock
(
&
(
pFile
->
rwlock
));
taosThreadRwlockU
nlock
(
&
(
pFile
->
rwlock
));
#endif
#endif
return
ret
;
return
ret
;
}
}
...
...
source/os/src/osSemaphore.c
浏览文件 @
3544df41
...
@@ -24,11 +24,11 @@
...
@@ -24,11 +24,11 @@
#include <windows.h>
#include <windows.h>
bool
taosCheckPthreadValid
(
pthread_t
thread
)
{
return
thread
.
p
!=
NULL
;
}
bool
taosCheckPthreadValid
(
TdThread
thread
)
{
return
thread
.
p
!=
NULL
;
}
void
taosResetPthread
(
pthread_t
*
thread
)
{
thread
->
p
=
0
;
}
void
taosResetPthread
(
TdThread
*
thread
)
{
thread
->
p
=
0
;
}
int64_t
taosGetPthreadId
(
pthread_t
thread
)
{
int64_t
taosGetPthreadId
(
TdThread
thread
)
{
#ifdef PTW32_VERSION
#ifdef PTW32_VERSION
return
pthread_getw32threadid_np
(
thread
);
return
pthread_getw32threadid_np
(
thread
);
#else
#else
...
@@ -38,7 +38,7 @@ int64_t taosGetPthreadId(pthread_t thread) {
...
@@ -38,7 +38,7 @@ int64_t taosGetPthreadId(pthread_t thread) {
int64_t
taosGetSelfPthreadId
()
{
return
GetCurrentThreadId
();
}
int64_t
taosGetSelfPthreadId
()
{
return
GetCurrentThreadId
();
}
bool
taosComparePthread
(
pthread_t
first
,
pthread_t
second
)
{
return
first
.
p
==
second
.
p
;
}
bool
taosComparePthread
(
TdThread
first
,
TdThread
second
)
{
return
first
.
p
==
second
.
p
;
}
int32_t
taosGetPId
()
{
return
GetCurrentProcessId
();
}
int32_t
taosGetPId
()
{
return
GetCurrentProcessId
();
}
...
@@ -84,10 +84,9 @@ int32_t tsem_wait(tsem_t* sem) {
...
@@ -84,10 +84,9 @@ int32_t tsem_wait(tsem_t* sem) {
#include <mach/mach_init.h>
#include <mach/mach_init.h>
#include <mach/semaphore.h>
#include <mach/semaphore.h>
#include <mach/task.h>
#include <mach/task.h>
#include <pthread.h>
static
pthread_t
sem_thread
;
static
TdThread
sem_thread
;
static
pthread_once_t
sem_once
;
static
TdThreadOnce
sem_once
;
static
task_t
sem_port
;
static
task_t
sem_port
;
static
volatile
int
sem_inited
=
0
;
static
volatile
int
sem_inited
=
0
;
static
semaphore_t
sem_exit
;
static
semaphore_t
sem_exit
;
...
@@ -110,7 +109,7 @@ static void *sem_thread_routine(void *arg) {
...
@@ -110,7 +109,7 @@ static void *sem_thread_routine(void *arg) {
static
void
once_init
(
void
)
{
static
void
once_init
(
void
)
{
int
r
=
0
;
int
r
=
0
;
r
=
pthread_c
reate
(
&
sem_thread
,
NULL
,
sem_thread_routine
,
NULL
);
r
=
taosThreadC
reate
(
&
sem_thread
,
NULL
,
sem_thread_routine
,
NULL
);
if
(
r
)
{
if
(
r
)
{
fprintf
(
stderr
,
"==%s[%d]%s()==failed to create thread
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
fprintf
(
stderr
,
"==%s[%d]%s()==failed to create thread
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
return
;
return
;
...
@@ -123,8 +122,8 @@ static void once_init(void) {
...
@@ -123,8 +122,8 @@ static void once_init(void) {
struct
tsem_s
{
struct
tsem_s
{
#ifdef SEM_USE_PTHREAD
#ifdef SEM_USE_PTHREAD
pthread_mutex_t
lock
;
TdThreadMutex
lock
;
pthread_cond_t
cond
;
TdThreadCond
cond
;
volatile
int64_t
val
;
volatile
int64_t
val
;
#elif defined(SEM_USE_POSIX)
#elif defined(SEM_USE_POSIX)
size_t
id
;
size_t
id
;
...
@@ -151,12 +150,12 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
...
@@ -151,12 +150,12 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
}
}
#ifdef SEM_USE_PTHREAD
#ifdef SEM_USE_PTHREAD
int
r
=
pthread_mutex_i
nit
(
&
p
->
lock
,
NULL
);
int
r
=
taosThreadMutexI
nit
(
&
p
->
lock
,
NULL
);
do
{
do
{
if
(
r
)
break
;
if
(
r
)
break
;
r
=
pthread_cond_i
nit
(
&
p
->
cond
,
NULL
);
r
=
taosThreadCondI
nit
(
&
p
->
cond
,
NULL
);
if
(
r
)
{
if
(
r
)
{
pthread_mutex_d
estroy
(
&
p
->
lock
);
taosThreadMutexD
estroy
(
&
p
->
lock
);
break
;
break
;
}
}
p
->
val
=
value
;
p
->
val
=
value
;
...
@@ -186,7 +185,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
...
@@ -186,7 +185,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
abort
();
abort
();
}
while
(
p
->
sem
==
SEM_FAILED
);
}
while
(
p
->
sem
==
SEM_FAILED
);
#elif defined(SEM_USE_SEM)
#elif defined(SEM_USE_SEM)
pthread_o
nce
(
&
sem_once
,
once_init
);
taosThreadO
nce
(
&
sem_once
,
once_init
);
if
(
sem_inited
!=
1
)
{
if
(
sem_inited
!=
1
)
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal resource init failed
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal resource init failed
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
errno
=
ENOMEM
;
errno
=
ENOMEM
;
...
@@ -224,18 +223,18 @@ int tsem_wait(tsem_t *sem) {
...
@@ -224,18 +223,18 @@ int tsem_wait(tsem_t *sem) {
abort
();
abort
();
}
}
#ifdef SEM_USE_PTHREAD
#ifdef SEM_USE_PTHREAD
if
(
pthread_mutex_l
ock
(
&
p
->
lock
))
{
if
(
taosThreadMutexL
ock
(
&
p
->
lock
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
p
->
val
-=
1
;
p
->
val
-=
1
;
if
(
p
->
val
<
0
)
{
if
(
p
->
val
<
0
)
{
if
(
pthread_cond_w
ait
(
&
p
->
cond
,
&
p
->
lock
))
{
if
(
taosThreadCondW
ait
(
&
p
->
cond
,
&
p
->
lock
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
}
}
if
(
pthread_mutex_u
nlock
(
&
p
->
lock
))
{
if
(
taosThreadMutexU
nlock
(
&
p
->
lock
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
...
@@ -260,18 +259,18 @@ int tsem_post(tsem_t *sem) {
...
@@ -260,18 +259,18 @@ int tsem_post(tsem_t *sem) {
abort
();
abort
();
}
}
#ifdef SEM_USE_PTHREAD
#ifdef SEM_USE_PTHREAD
if
(
pthread_mutex_l
ock
(
&
p
->
lock
))
{
if
(
taosThreadMutexL
ock
(
&
p
->
lock
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
p
->
val
+=
1
;
p
->
val
+=
1
;
if
(
p
->
val
<=
0
)
{
if
(
p
->
val
<=
0
)
{
if
(
pthread_cond_s
ignal
(
&
p
->
cond
))
{
if
(
taosThreadCondS
ignal
(
&
p
->
cond
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
}
}
if
(
pthread_mutex_u
nlock
(
&
p
->
lock
))
{
if
(
taosThreadMutexU
nlock
(
&
p
->
lock
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
...
@@ -299,20 +298,20 @@ int tsem_destroy(tsem_t *sem) {
...
@@ -299,20 +298,20 @@ int tsem_destroy(tsem_t *sem) {
return
0
;
return
0
;
}
}
#ifdef SEM_USE_PTHREAD
#ifdef SEM_USE_PTHREAD
if
(
pthread_mutex_l
ock
(
&
p
->
lock
))
{
if
(
taosThreadMutexL
ock
(
&
p
->
lock
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
p
->
valid
=
0
;
p
->
valid
=
0
;
if
(
pthread_cond_d
estroy
(
&
p
->
cond
))
{
if
(
taosThreadCondD
estroy
(
&
p
->
cond
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
if
(
pthread_mutex_u
nlock
(
&
p
->
lock
))
{
if
(
taosThreadMutexU
nlock
(
&
p
->
lock
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
if
(
pthread_mutex_d
estroy
(
&
p
->
lock
))
{
if
(
taosThreadMutexD
estroy
(
&
p
->
lock
))
{
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
fprintf
(
stderr
,
"==%s[%d]%s():[%p]==internal logic error
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
,
sem
);
abort
();
abort
();
}
}
...
@@ -338,23 +337,23 @@ int tsem_destroy(tsem_t *sem) {
...
@@ -338,23 +337,23 @@ int tsem_destroy(tsem_t *sem) {
return
0
;
return
0
;
}
}
bool
taosCheckPthreadValid
(
pthread_t
thread
)
{
bool
taosCheckPthreadValid
(
TdThread
thread
)
{
uint64_t
id
=
0
;
uint64_t
id
=
0
;
int
r
=
pthread_t
hreadid_np
(
thread
,
&
id
);
int
r
=
TdThread
hreadid_np
(
thread
,
&
id
);
return
r
?
false
:
true
;
return
r
?
false
:
true
;
}
}
int64_t
taosGetSelfPthreadId
()
{
int64_t
taosGetSelfPthreadId
()
{
uint64_t
id
;
uint64_t
id
;
pthread_t
hreadid_np
(
0
,
&
id
);
TdThread
hreadid_np
(
0
,
&
id
);
return
(
int64_t
)
id
;
return
(
int64_t
)
id
;
}
}
int64_t
taosGetPthreadId
(
pthread_t
thread
)
{
return
(
int64_t
)
thread
;
}
int64_t
taosGetPthreadId
(
TdThread
thread
)
{
return
(
int64_t
)
thread
;
}
void
taosResetPthread
(
pthread_t
*
thread
)
{
*
thread
=
NULL
;
}
void
taosResetPthread
(
TdThread
*
thread
)
{
*
thread
=
NULL
;
}
bool
taosComparePthread
(
pthread_t
first
,
pthread_t
second
)
{
return
pthread_e
qual
(
first
,
second
)
?
true
:
false
;
}
bool
taosComparePthread
(
TdThread
first
,
TdThread
second
)
{
return
taosThreadE
qual
(
first
,
second
)
?
true
:
false
;
}
int32_t
taosGetPId
()
{
return
(
int32_t
)
getpid
();
}
int32_t
taosGetPId
()
{
return
(
int32_t
)
getpid
();
}
...
@@ -378,7 +377,7 @@ int32_t taosGetAppName(char *name, int32_t *len) {
...
@@ -378,7 +377,7 @@ int32_t taosGetAppName(char *name, int32_t *len) {
#include <sys/syscall.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <unistd.h>
bool
taosCheckPthreadValid
(
pthread_t
thread
)
{
return
thread
!=
0
;
}
bool
taosCheckPthreadValid
(
TdThread
thread
)
{
return
thread
!=
0
;
}
int64_t
taosGetSelfPthreadId
()
{
int64_t
taosGetSelfPthreadId
()
{
static
__thread
int
id
=
0
;
static
__thread
int
id
=
0
;
...
@@ -387,9 +386,9 @@ int64_t taosGetSelfPthreadId() {
...
@@ -387,9 +386,9 @@ int64_t taosGetSelfPthreadId() {
return
id
;
return
id
;
}
}
int64_t
taosGetPthreadId
(
pthread_t
thread
)
{
return
(
int64_t
)
thread
;
}
int64_t
taosGetPthreadId
(
TdThread
thread
)
{
return
(
int64_t
)
thread
;
}
void
taosResetPthread
(
pthread_t
*
thread
)
{
*
thread
=
0
;
}
void
taosResetPthread
(
TdThread
*
thread
)
{
*
thread
=
0
;
}
bool
taosComparePthread
(
pthread_t
first
,
pthread_t
second
)
{
return
first
==
second
;
}
bool
taosComparePthread
(
TdThread
first
,
TdThread
second
)
{
return
first
==
second
;
}
int32_t
taosGetPId
()
{
return
getpid
();
}
int32_t
taosGetPId
()
{
return
getpid
();
}
int32_t
taosGetAppName
(
char
*
name
,
int32_t
*
len
)
{
int32_t
taosGetAppName
(
char
*
name
,
int32_t
*
len
)
{
...
...
source/os/src/osSocket.c
浏览文件 @
3544df41
...
@@ -52,7 +52,7 @@ typedef SocketFd EpollFd;
...
@@ -52,7 +52,7 @@ typedef SocketFd EpollFd;
typedef
struct
TdSocketServer
{
typedef
struct
TdSocketServer
{
#if SOCKET_WITH_LOCK
#if SOCKET_WITH_LOCK
pthread_rwlock_t
rwlock
;
TdThreadRwlock
rwlock
;
#endif
#endif
int
refId
;
int
refId
;
SocketFd
fd
;
SocketFd
fd
;
...
@@ -60,7 +60,7 @@ typedef struct TdSocketServer {
...
@@ -60,7 +60,7 @@ typedef struct TdSocketServer {
typedef
struct
TdSocket
{
typedef
struct
TdSocket
{
#if SOCKET_WITH_LOCK
#if SOCKET_WITH_LOCK
pthread_rwlock_t
rwlock
;
TdThreadRwlock
rwlock
;
#endif
#endif
int
refId
;
int
refId
;
SocketFd
fd
;
SocketFd
fd
;
...
@@ -68,7 +68,7 @@ typedef struct TdSocket {
...
@@ -68,7 +68,7 @@ typedef struct TdSocket {
typedef
struct
TdEpoll
{
typedef
struct
TdEpoll
{
#if SOCKET_WITH_LOCK
#if SOCKET_WITH_LOCK
pthread_rwlock_t
rwlock
;
TdThreadRwlock
rwlock
;
#endif
#endif
int
refId
;
int
refId
;
EpollFd
fd
;
EpollFd
fd
;
...
@@ -775,7 +775,7 @@ void taosBlockSIGPIPE() {
...
@@ -775,7 +775,7 @@ void taosBlockSIGPIPE() {
sigset_t
signal_mask
;
sigset_t
signal_mask
;
sigemptyset
(
&
signal_mask
);
sigemptyset
(
&
signal_mask
);
sigaddset
(
&
signal_mask
,
SIGPIPE
);
sigaddset
(
&
signal_mask
,
SIGPIPE
);
int32_t
rc
=
pthread_s
igmask
(
SIG_BLOCK
,
&
signal_mask
,
NULL
);
int32_t
rc
=
taosThreadS
igmask
(
SIG_BLOCK
,
&
signal_mask
,
NULL
);
if
(
rc
!=
0
)
{
if
(
rc
!=
0
)
{
// printf("failed to block SIGPIPE");
// printf("failed to block SIGPIPE");
}
}
...
@@ -893,7 +893,7 @@ void taosSetMaskSIGPIPE() {
...
@@ -893,7 +893,7 @@ void taosSetMaskSIGPIPE() {
sigset_t
signal_mask
;
sigset_t
signal_mask
;
sigemptyset
(
&
signal_mask
);
sigemptyset
(
&
signal_mask
);
sigaddset
(
&
signal_mask
,
SIGPIPE
);
sigaddset
(
&
signal_mask
,
SIGPIPE
);
int32_t
rc
=
pthread_s
igmask
(
SIG_SETMASK
,
&
signal_mask
,
NULL
);
int32_t
rc
=
taosThreadS
igmask
(
SIG_SETMASK
,
&
signal_mask
,
NULL
);
if
(
rc
!=
0
)
{
if
(
rc
!=
0
)
{
// printf("failed to setmask SIGPIPE");
// printf("failed to setmask SIGPIPE");
}
}
...
...
source/os/src/osThread.c
0 → 100644
浏览文件 @
3544df41
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#include "os.h"
// int32_t taosThreadSetnameNp(TdThread thread, const char *name) {
// return pthread_setname_np(thread,name);
// }
int32_t
taosThreadSpinInit
(
TdThreadSpinlock
*
lock
,
int
pshared
)
{
return
pthread_spin_init
(
lock
,
pshared
);
}
int32_t
taosThreadMutexInit
(
TdThreadMutex
*
mutex
,
const
TdThreadMutexAttr
*
attr
)
{
return
pthread_mutex_init
(
mutex
,
attr
);
}
int32_t
taosThreadSpinDestroy
(
TdThreadSpinlock
*
lock
)
{
return
pthread_spin_destroy
(
lock
);
}
int32_t
taosThreadMutexDestroy
(
TdThreadMutex
*
mutex
)
{
return
pthread_mutex_destroy
(
mutex
);
}
int32_t
taosThreadSpinLock
(
TdThreadSpinlock
*
lock
)
{
return
pthread_spin_lock
(
lock
);
}
int32_t
taosThreadMutexLock
(
TdThreadMutex
*
mutex
)
{
return
pthread_mutex_lock
(
mutex
);
}
int32_t
taosThreadSpinUnlock
(
TdThreadSpinlock
*
lock
)
{
return
pthread_spin_unlock
(
lock
);
}
int32_t
taosThreadMutexUnlock
(
TdThreadMutex
*
mutex
)
{
return
pthread_mutex_unlock
(
mutex
);
}
int32_t
taosThreadRwlockRdlock
(
TdThreadRwlock
*
rwlock
)
{
return
pthread_rwlock_rdlock
(
rwlock
);
}
int32_t
taosThreadRwlockWrlock
(
TdThreadRwlock
*
rwlock
)
{
return
pthread_rwlock_wrlock
(
rwlock
);
}
int32_t
taosThreadRwlockUnlock
(
TdThreadRwlock
*
rwlock
)
{
return
pthread_rwlock_unlock
(
rwlock
);
}
void
taosThreadTestCancel
(
void
)
{
return
pthread_testcancel
();
}
int32_t
taosThreadAttrInit
(
TdThreadAttr
*
attr
)
{
return
pthread_attr_init
(
attr
);
}
int32_t
taosThreadCreate
(
TdThread
*
tid
,
const
TdThreadAttr
*
attr
,
void
*
(
*
start
)(
void
*
),
void
*
arg
)
{
return
pthread_create
(
tid
,
attr
,
start
,
arg
);
}
int32_t
taosThreadOnce
(
TdThreadOnce
*
onceControl
,
void
(
*
initRoutine
)(
void
))
{
return
pthread_once
(
onceControl
,
initRoutine
);
}
int32_t
taosThreadAttrSetDetachState
(
TdThreadAttr
*
attr
,
int32_t
detachState
)
{
return
pthread_attr_setdetachstate
(
attr
,
detachState
);
}
int32_t
taosThreadAttrDestroy
(
TdThreadAttr
*
attr
)
{
return
pthread_attr_destroy
(
attr
);
}
int32_t
taosThreadJoin
(
TdThread
thread
,
void
**
pValue
)
{
return
pthread_join
(
thread
,
pValue
);
}
int32_t
taosThreadRwlockInit
(
TdThreadRwlock
*
rwlock
,
const
TdThreadRwlockAttr
*
attr
)
{
return
pthread_rwlock_init
(
rwlock
,
attr
);
}
int32_t
taosThreadRwlockDestroy
(
TdThreadRwlock
*
rwlock
)
{
return
pthread_rwlock_destroy
(
rwlock
);
}
int32_t
taosThreadCondSignal
(
TdThreadCond
*
cond
)
{
return
pthread_cond_signal
(
cond
);
}
int32_t
taosThreadCondInit
(
TdThreadCond
*
cond
,
const
TdThreadCondAttr
*
attr
)
{
return
pthread_cond_init
(
cond
,
attr
);
}
int32_t
taosThreadCondBroadcast
(
TdThreadCond
*
cond
)
{
return
pthread_cond_broadcast
(
cond
);
}
int32_t
taosThreadCondDestroy
(
TdThreadCond
*
cond
)
{
return
pthread_cond_destroy
(
cond
);
}
int32_t
taosThreadCondWait
(
TdThreadCond
*
cond
,
TdThreadMutex
*
mutex
)
{
return
pthread_cond_wait
(
cond
,
mutex
);
}
TdThread
taosThreadSelf
(
void
)
{
return
pthread_self
();
}
// int32_t taosThreadGetW32ThreadIdNp(TdThread thread) {
// return pthread_getw32threadid_np(thread);
// }
int32_t
taosThreadEqual
(
TdThread
t1
,
TdThread
t2
)
{
return
pthread_equal
(
t1
,
t2
);
}
int32_t
taosThreadSigmask
(
int
how
,
sigset_t
const
*
set
,
sigset_t
*
oset
)
{
return
pthread_sigmask
(
how
,
set
,
oset
);
}
int32_t
taosThreadCancel
(
TdThread
thread
)
{
return
pthread_cancel
(
thread
);
}
int32_t
taosThreadKill
(
TdThread
thread
,
int
sig
)
{
return
pthread_kill
(
thread
,
sig
);
}
\ No newline at end of file
source/os/src/osTimer.c
浏览文件 @
3544df41
...
@@ -44,7 +44,7 @@ static MMRESULT timerId;
...
@@ -44,7 +44,7 @@ static MMRESULT timerId;
static
void
(
*
timer_callback
)(
int
);
static
void
(
*
timer_callback
)(
int
);
static
int
timer_ms
=
0
;
static
int
timer_ms
=
0
;
static
pthread_t
timer_thread
;
static
TdThread
timer_thread
;
static
int
timer_kq
=
-
1
;
static
int
timer_kq
=
-
1
;
static
volatile
int
timer_stop
=
0
;
static
volatile
int
timer_stop
=
0
;
...
@@ -83,7 +83,7 @@ static void taosDeleteTimer(void *tharg) {
...
@@ -83,7 +83,7 @@ static void taosDeleteTimer(void *tharg) {
timer_delete
(
*
pTimer
);
timer_delete
(
*
pTimer
);
}
}
static
pthread_t
timerThread
;
static
TdThread
timerThread
;
static
timer_t
timerId
;
static
timer_t
timerId
;
static
volatile
bool
stopTimer
=
false
;
static
volatile
bool
stopTimer
=
false
;
static
void
*
taosProcessAlarmSignal
(
void
*
tharg
)
{
static
void
*
taosProcessAlarmSignal
(
void
*
tharg
)
{
...
@@ -112,7 +112,7 @@ static void * taosProcessAlarmSignal(void *tharg) {
...
@@ -112,7 +112,7 @@ static void * taosProcessAlarmSignal(void *tharg) {
// printf("Failed to create timer");
// printf("Failed to create timer");
}
}
pthread_cleanup_p
ush
(
taosDeleteTimer
,
&
timerId
);
taosThreadCleanupP
ush
(
taosDeleteTimer
,
&
timerId
);
struct
itimerspec
ts
;
struct
itimerspec
ts
;
ts
.
it_value
.
tv_sec
=
0
;
ts
.
it_value
.
tv_sec
=
0
;
...
@@ -136,7 +136,7 @@ static void * taosProcessAlarmSignal(void *tharg) {
...
@@ -136,7 +136,7 @@ static void * taosProcessAlarmSignal(void *tharg) {
callback
(
0
);
callback
(
0
);
}
}
pthread_cleanup_p
op
(
1
);
taosThreadCleanupP
op
(
1
);
return
NULL
;
return
NULL
;
}
}
...
@@ -165,7 +165,7 @@ int taosInitTimer(void (*callback)(int), int ms) {
...
@@ -165,7 +165,7 @@ int taosInitTimer(void (*callback)(int), int ms) {
abort
();
abort
();
}
}
r
=
pthread_c
reate
(
&
timer_thread
,
NULL
,
timer_routine
,
NULL
);
r
=
taosThreadC
reate
(
&
timer_thread
,
NULL
,
timer_routine
,
NULL
);
if
(
r
)
{
if
(
r
)
{
fprintf
(
stderr
,
"==%s[%d]%s()==failed to create timer thread
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
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
// since no caller of this func checks the return value for the moment
...
@@ -174,10 +174,10 @@ int taosInitTimer(void (*callback)(int), int ms) {
...
@@ -174,10 +174,10 @@ int taosInitTimer(void (*callback)(int), int ms) {
return
0
;
return
0
;
#else
#else
stopTimer
=
false
;
stopTimer
=
false
;
pthread_attr_t
tattr
;
TdThreadAttr
tattr
;
pthread_attr_i
nit
(
&
tattr
);
taosThreadAttrI
nit
(
&
tattr
);
int
code
=
pthread_c
reate
(
&
timerThread
,
&
tattr
,
taosProcessAlarmSignal
,
callback
);
int
code
=
taosThreadC
reate
(
&
timerThread
,
&
tattr
,
taosProcessAlarmSignal
,
callback
);
pthread_attr_d
estroy
(
&
tattr
);
taosThreadAttrD
estroy
(
&
tattr
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
// printf("failed to create timer thread");
// printf("failed to create timer thread");
return
-
1
;
return
-
1
;
...
@@ -195,7 +195,7 @@ void taosUninitTimer() {
...
@@ -195,7 +195,7 @@ void taosUninitTimer() {
#elif defined(_TD_DARWIN_64)
#elif defined(_TD_DARWIN_64)
int
r
=
0
;
int
r
=
0
;
timer_stop
=
1
;
timer_stop
=
1
;
r
=
pthread_j
oin
(
timer_thread
,
NULL
);
r
=
taosThreadJ
oin
(
timer_thread
,
NULL
);
if
(
r
)
{
if
(
r
)
{
fprintf
(
stderr
,
"==%s[%d]%s()==failed to join timer thread
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
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
// since no caller of this func checks the return value for the moment
...
@@ -207,7 +207,7 @@ void taosUninitTimer() {
...
@@ -207,7 +207,7 @@ void taosUninitTimer() {
stopTimer
=
true
;
stopTimer
=
true
;
// printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread));
// printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread));
pthread_j
oin
(
timerThread
,
NULL
);
taosThreadJ
oin
(
timerThread
,
NULL
);
#endif
#endif
}
}
...
...
source/os/src/osTimezone.c
浏览文件 @
3544df41
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "os.h"
#include "os.h"
...
...
source/util/CMakeLists.txt
浏览文件 @
3544df41
...
@@ -5,10 +5,6 @@ target_include_directories(
...
@@ -5,10 +5,6 @@ target_include_directories(
util
util
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/util"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/util"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
IF
(
${
TD_WINDOWS
}
)
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/contrib/pthread-win32"
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/contrib/gnuregex"
ENDIF
()
)
)
target_link_libraries
(
target_link_libraries
(
util
util
...
...
source/util/src/tcache.c
浏览文件 @
3544df41
...
@@ -22,9 +22,9 @@
...
@@ -22,9 +22,9 @@
#define CACHE_MAX_CAPACITY 1024*1024*16
#define CACHE_MAX_CAPACITY 1024*1024*16
#define CACHE_DEFAULT_CAPACITY 1024*4
#define CACHE_DEFAULT_CAPACITY 1024*4
static
pthread_t
cacheRefreshWorker
=
{
0
};
static
TdThread
cacheRefreshWorker
=
{
0
};
static
pthread_once_t
cacheThreadInit
=
PTHREAD_ONCE_INIT
;
static
TdThreadOnce
cacheThreadInit
=
PTHREAD_ONCE_INIT
;
static
pthread_mutex_t
guard
=
PTHREAD_MUTEX_INITIALIZER
;
static
TdThreadMutex
guard
=
PTHREAD_MUTEX_INITIALIZER
;
static
SArray
*
pCacheArrayList
=
NULL
;
static
SArray
*
pCacheArrayList
=
NULL
;
static
bool
stopRefreshWorker
=
false
;
static
bool
stopRefreshWorker
=
false
;
static
bool
refreshWorkerNormalStopped
=
false
;
static
bool
refreshWorkerNormalStopped
=
false
;
...
@@ -90,13 +90,13 @@ struct SCacheObj {
...
@@ -90,13 +90,13 @@ struct SCacheObj {
STrashElem
*
pTrash
;
STrashElem
*
pTrash
;
uint8_t
deleting
;
// set the deleting flag to stop refreshing ASAP.
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.
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
int64_t
checkTick
;
// tick used to record the check times of the refresh threads
#if defined(LINUX)
#if defined(LINUX)
pthread_rwlock_t
lock
;
TdThreadRwlock
lock
;
#else
#else
pthread_mutex_t
lock
;
TdThreadMutex
lock
;
#endif
#endif
};
};
...
@@ -109,33 +109,33 @@ typedef struct SCacheObjTravSup {
...
@@ -109,33 +109,33 @@ typedef struct SCacheObjTravSup {
static
FORCE_INLINE
void
__trashcan_wr_lock
(
SCacheObj
*
pCacheObj
)
{
static
FORCE_INLINE
void
__trashcan_wr_lock
(
SCacheObj
*
pCacheObj
)
{
#if defined(LINUX)
#if defined(LINUX)
pthread_rwlock_w
rlock
(
&
pCacheObj
->
lock
);
taosThreadRwlockW
rlock
(
&
pCacheObj
->
lock
);
#else
#else
pthread_mutex_l
ock
(
&
pCacheObj
->
lock
);
taosThreadMutexL
ock
(
&
pCacheObj
->
lock
);
#endif
#endif
}
}
static
FORCE_INLINE
void
__trashcan_unlock
(
SCacheObj
*
pCacheObj
)
{
static
FORCE_INLINE
void
__trashcan_unlock
(
SCacheObj
*
pCacheObj
)
{
#if defined(LINUX)
#if defined(LINUX)
pthread_rwlock_u
nlock
(
&
pCacheObj
->
lock
);
taosThreadRwlockU
nlock
(
&
pCacheObj
->
lock
);
#else
#else
pthread_mutex_u
nlock
(
&
pCacheObj
->
lock
);
taosThreadMutexU
nlock
(
&
pCacheObj
->
lock
);
#endif
#endif
}
}
static
FORCE_INLINE
int32_t
__trashcan_lock_init
(
SCacheObj
*
pCacheObj
)
{
static
FORCE_INLINE
int32_t
__trashcan_lock_init
(
SCacheObj
*
pCacheObj
)
{
#if defined(LINUX)
#if defined(LINUX)
return
pthread_rwlock_i
nit
(
&
pCacheObj
->
lock
,
NULL
);
return
taosThreadRwlockI
nit
(
&
pCacheObj
->
lock
,
NULL
);
#else
#else
return
pthread_mutex_i
nit
(
&
pCacheObj
->
lock
,
NULL
);
return
taosThreadMutexI
nit
(
&
pCacheObj
->
lock
,
NULL
);
#endif
#endif
}
}
static
FORCE_INLINE
void
__trashcan_lock_destroy
(
SCacheObj
*
pCacheObj
)
{
static
FORCE_INLINE
void
__trashcan_lock_destroy
(
SCacheObj
*
pCacheObj
)
{
#if defined(LINUX)
#if defined(LINUX)
pthread_rwlock_d
estroy
(
&
pCacheObj
->
lock
);
taosThreadRwlockD
estroy
(
&
pCacheObj
->
lock
);
#else
#else
pthread_mutex_d
estroy
(
&
pCacheObj
->
lock
);
taosThreadMutexD
estroy
(
&
pCacheObj
->
lock
);
#endif
#endif
}
}
...
@@ -154,20 +154,20 @@ static void *taosCacheTimedRefresh(void *handle);
...
@@ -154,20 +154,20 @@ static void *taosCacheTimedRefresh(void *handle);
static
void
doInitRefreshThread
(
void
)
{
static
void
doInitRefreshThread
(
void
)
{
pCacheArrayList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
pCacheArrayList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
pthread_c
reate
(
&
cacheRefreshWorker
,
&
thattr
,
taosCacheTimedRefresh
,
NULL
);
taosThreadC
reate
(
&
cacheRefreshWorker
,
&
thattr
,
taosCacheTimedRefresh
,
NULL
);
pthread_attr_d
estroy
(
&
thattr
);
taosThreadAttrD
estroy
(
&
thattr
);
}
}
pthread_t
doRegisterCacheObj
(
SCacheObj
*
pCacheObj
)
{
TdThread
doRegisterCacheObj
(
SCacheObj
*
pCacheObj
)
{
pthread_o
nce
(
&
cacheThreadInit
,
doInitRefreshThread
);
taosThreadO
nce
(
&
cacheThreadInit
,
doInitRefreshThread
);
pthread_mutex_l
ock
(
&
guard
);
taosThreadMutexL
ock
(
&
guard
);
taosArrayPush
(
pCacheArrayList
,
&
pCacheObj
);
taosArrayPush
(
pCacheArrayList
,
&
pCacheObj
);
pthread_mutex_u
nlock
(
&
guard
);
taosThreadMutexU
nlock
(
&
guard
);
return
cacheRefreshWorker
;
return
cacheRefreshWorker
;
}
}
...
@@ -836,19 +836,19 @@ void *taosCacheTimedRefresh(void *handle) {
...
@@ -836,19 +836,19 @@ void *taosCacheTimedRefresh(void *handle) {
goto
_end
;
goto
_end
;
}
}
pthread_mutex_l
ock
(
&
guard
);
taosThreadMutexL
ock
(
&
guard
);
size_t
size
=
taosArrayGetSize
(
pCacheArrayList
);
size_t
size
=
taosArrayGetSize
(
pCacheArrayList
);
pthread_mutex_u
nlock
(
&
guard
);
taosThreadMutexU
nlock
(
&
guard
);
count
+=
1
;
count
+=
1
;
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
pthread_mutex_l
ock
(
&
guard
);
taosThreadMutexL
ock
(
&
guard
);
SCacheObj
*
pCacheObj
=
taosArrayGetP
(
pCacheArrayList
,
i
);
SCacheObj
*
pCacheObj
=
taosArrayGetP
(
pCacheArrayList
,
i
);
if
(
pCacheObj
==
NULL
)
{
if
(
pCacheObj
==
NULL
)
{
uError
(
"object is destroyed. ignore and try next"
);
uError
(
"object is destroyed. ignore and try next"
);
pthread_mutex_u
nlock
(
&
guard
);
taosThreadMutexU
nlock
(
&
guard
);
continue
;
continue
;
}
}
...
@@ -860,11 +860,11 @@ void *taosCacheTimedRefresh(void *handle) {
...
@@ -860,11 +860,11 @@ void *taosCacheTimedRefresh(void *handle) {
uDebug
(
"%s is destroying, remove it from refresh list, remain cache obj:%"
PRIzu
,
pCacheObj
->
name
,
size
);
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.
pCacheObj
->
deleting
=
0
;
// reset the deleting flag to enable pCacheObj to continue releasing resources.
pthread_mutex_u
nlock
(
&
guard
);
taosThreadMutexU
nlock
(
&
guard
);
continue
;
continue
;
}
}
pthread_mutex_u
nlock
(
&
guard
);
taosThreadMutexU
nlock
(
&
guard
);
if
((
count
%
pCacheObj
->
checkTick
)
!=
0
)
{
if
((
count
%
pCacheObj
->
checkTick
)
!=
0
)
{
continue
;
continue
;
...
@@ -892,7 +892,7 @@ _end:
...
@@ -892,7 +892,7 @@ _end:
taosArrayDestroy
(
pCacheArrayList
);
taosArrayDestroy
(
pCacheArrayList
);
pCacheArrayList
=
NULL
;
pCacheArrayList
=
NULL
;
pthread_mutex_d
estroy
(
&
guard
);
taosThreadMutexD
estroy
(
&
guard
);
refreshWorkerNormalStopped
=
true
;
refreshWorkerNormalStopped
=
true
;
uDebug
(
"cache refresh thread quits"
);
uDebug
(
"cache refresh thread quits"
);
...
...
source/util/src/terror.c
浏览文件 @
3544df41
...
@@ -436,14 +436,14 @@ static int32_t taosCompareTaosError(const void* a, const void* b) {
...
@@ -436,14 +436,14 @@ static int32_t taosCompareTaosError(const void* a, const void* b) {
return
0
;
return
0
;
}
}
static
pthread_once_t
tsErrorInit
=
PTHREAD_ONCE_INIT
;
static
TdThreadOnce
tsErrorInit
=
PTHREAD_ONCE_INIT
;
static
void
tsSortError
(
void
)
{
static
void
tsSortError
(
void
)
{
qsort
(
errors
,
sizeof
(
errors
)
/
sizeof
(
errors
[
0
]),
sizeof
(
errors
[
0
]),
taosCompareTaosError
);
qsort
(
errors
,
sizeof
(
errors
)
/
sizeof
(
errors
[
0
]),
sizeof
(
errors
[
0
]),
taosCompareTaosError
);
}
}
const
char
*
tstrerror
(
int32_t
err
)
{
const
char
*
tstrerror
(
int32_t
err
)
{
pthread_o
nce
(
&
tsErrorInit
,
tsSortError
);
taosThreadO
nce
(
&
tsErrorInit
,
tsSortError
);
// this is a system errno
// this is a system errno
if
((
err
&
0x00ff0000
)
==
0x00ff0000
)
{
if
((
err
&
0x00ff0000
)
==
0x00ff0000
)
{
...
...
source/util/src/tidpool.c
浏览文件 @
3544df41
...
@@ -31,7 +31,7 @@ void *taosInitIdPool(int32_t maxId) {
...
@@ -31,7 +31,7 @@ void *taosInitIdPool(int32_t maxId) {
pIdPool
->
numOfFree
=
maxId
;
pIdPool
->
numOfFree
=
maxId
;
pIdPool
->
freeSlot
=
0
;
pIdPool
->
freeSlot
=
0
;
pthread_mutex_i
nit
(
&
pIdPool
->
mutex
,
NULL
);
taosThreadMutexI
nit
(
&
pIdPool
->
mutex
,
NULL
);
uDebug
(
"pool:%p is setup, maxId:%d"
,
pIdPool
,
pIdPool
->
maxId
);
uDebug
(
"pool:%p is setup, maxId:%d"
,
pIdPool
,
pIdPool
->
maxId
);
...
@@ -42,7 +42,7 @@ int32_t taosAllocateId(id_pool_t *pIdPool) {
...
@@ -42,7 +42,7 @@ int32_t taosAllocateId(id_pool_t *pIdPool) {
if
(
pIdPool
==
NULL
)
return
-
1
;
if
(
pIdPool
==
NULL
)
return
-
1
;
int32_t
slot
=
-
1
;
int32_t
slot
=
-
1
;
pthread_mutex_l
ock
(
&
pIdPool
->
mutex
);
taosThreadMutexL
ock
(
&
pIdPool
->
mutex
);
if
(
pIdPool
->
numOfFree
>
0
)
{
if
(
pIdPool
->
numOfFree
>
0
)
{
for
(
int32_t
i
=
0
;
i
<
pIdPool
->
maxId
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pIdPool
->
maxId
;
++
i
)
{
...
@@ -56,14 +56,14 @@ int32_t taosAllocateId(id_pool_t *pIdPool) {
...
@@ -56,14 +56,14 @@ int32_t taosAllocateId(id_pool_t *pIdPool) {
}
}
}
}
pthread_mutex_u
nlock
(
&
pIdPool
->
mutex
);
taosThreadMutexU
nlock
(
&
pIdPool
->
mutex
);
return
slot
+
1
;
return
slot
+
1
;
}
}
void
taosFreeId
(
id_pool_t
*
pIdPool
,
int32_t
id
)
{
void
taosFreeId
(
id_pool_t
*
pIdPool
,
int32_t
id
)
{
if
(
pIdPool
==
NULL
)
return
;
if
(
pIdPool
==
NULL
)
return
;
pthread_mutex_l
ock
(
&
pIdPool
->
mutex
);
taosThreadMutexL
ock
(
&
pIdPool
->
mutex
);
int32_t
slot
=
(
id
-
1
)
%
pIdPool
->
maxId
;
int32_t
slot
=
(
id
-
1
)
%
pIdPool
->
maxId
;
if
(
pIdPool
->
freeList
[
slot
])
{
if
(
pIdPool
->
freeList
[
slot
])
{
...
@@ -71,7 +71,7 @@ void taosFreeId(id_pool_t *pIdPool, int32_t id) {
...
@@ -71,7 +71,7 @@ void taosFreeId(id_pool_t *pIdPool, int32_t id) {
pIdPool
->
numOfFree
++
;
pIdPool
->
numOfFree
++
;
}
}
pthread_mutex_u
nlock
(
&
pIdPool
->
mutex
);
taosThreadMutexU
nlock
(
&
pIdPool
->
mutex
);
}
}
void
taosIdPoolCleanUp
(
id_pool_t
*
pIdPool
)
{
void
taosIdPoolCleanUp
(
id_pool_t
*
pIdPool
)
{
...
@@ -81,7 +81,7 @@ void taosIdPoolCleanUp(id_pool_t *pIdPool) {
...
@@ -81,7 +81,7 @@ void taosIdPoolCleanUp(id_pool_t *pIdPool) {
if
(
pIdPool
->
freeList
)
free
(
pIdPool
->
freeList
);
if
(
pIdPool
->
freeList
)
free
(
pIdPool
->
freeList
);
pthread_mutex_d
estroy
(
&
pIdPool
->
mutex
);
taosThreadMutexD
estroy
(
&
pIdPool
->
mutex
);
memset
(
pIdPool
,
0
,
sizeof
(
id_pool_t
));
memset
(
pIdPool
,
0
,
sizeof
(
id_pool_t
));
...
@@ -89,16 +89,16 @@ void taosIdPoolCleanUp(id_pool_t *pIdPool) {
...
@@ -89,16 +89,16 @@ void taosIdPoolCleanUp(id_pool_t *pIdPool) {
}
}
int32_t
taosIdPoolNumOfUsed
(
id_pool_t
*
pIdPool
)
{
int32_t
taosIdPoolNumOfUsed
(
id_pool_t
*
pIdPool
)
{
pthread_mutex_l
ock
(
&
pIdPool
->
mutex
);
taosThreadMutexL
ock
(
&
pIdPool
->
mutex
);
int32_t
ret
=
pIdPool
->
maxId
-
pIdPool
->
numOfFree
;
int32_t
ret
=
pIdPool
->
maxId
-
pIdPool
->
numOfFree
;
pthread_mutex_u
nlock
(
&
pIdPool
->
mutex
);
taosThreadMutexU
nlock
(
&
pIdPool
->
mutex
);
return
ret
;
return
ret
;
}
}
bool
taosIdPoolMarkStatus
(
id_pool_t
*
pIdPool
,
int32_t
id
)
{
bool
taosIdPoolMarkStatus
(
id_pool_t
*
pIdPool
,
int32_t
id
)
{
bool
ret
=
false
;
bool
ret
=
false
;
pthread_mutex_l
ock
(
&
pIdPool
->
mutex
);
taosThreadMutexL
ock
(
&
pIdPool
->
mutex
);
int32_t
slot
=
(
id
-
1
)
%
pIdPool
->
maxId
;
int32_t
slot
=
(
id
-
1
)
%
pIdPool
->
maxId
;
if
(
!
pIdPool
->
freeList
[
slot
])
{
if
(
!
pIdPool
->
freeList
[
slot
])
{
...
@@ -109,7 +109,7 @@ bool taosIdPoolMarkStatus(id_pool_t *pIdPool, int32_t id) {
...
@@ -109,7 +109,7 @@ bool taosIdPoolMarkStatus(id_pool_t *pIdPool, int32_t id) {
ret
=
false
;
ret
=
false
;
}
}
pthread_mutex_u
nlock
(
&
pIdPool
->
mutex
);
taosThreadMutexU
nlock
(
&
pIdPool
->
mutex
);
return
ret
;
return
ret
;
}
}
...
@@ -123,7 +123,7 @@ int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) {
...
@@ -123,7 +123,7 @@ int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) {
return
-
1
;
return
-
1
;
}
}
pthread_mutex_l
ock
(
&
pIdPool
->
mutex
);
taosThreadMutexL
ock
(
&
pIdPool
->
mutex
);
memcpy
(
idList
,
pIdPool
->
freeList
,
sizeof
(
bool
)
*
pIdPool
->
maxId
);
memcpy
(
idList
,
pIdPool
->
freeList
,
sizeof
(
bool
)
*
pIdPool
->
maxId
);
pIdPool
->
numOfFree
+=
(
maxId
-
pIdPool
->
maxId
);
pIdPool
->
numOfFree
+=
(
maxId
-
pIdPool
->
maxId
);
...
@@ -133,15 +133,15 @@ int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) {
...
@@ -133,15 +133,15 @@ int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) {
pIdPool
->
freeList
=
idList
;
pIdPool
->
freeList
=
idList
;
free
(
oldIdList
);
free
(
oldIdList
);
pthread_mutex_u
nlock
(
&
pIdPool
->
mutex
);
taosThreadMutexU
nlock
(
&
pIdPool
->
mutex
);
return
0
;
return
0
;
}
}
int32_t
taosIdPoolMaxSize
(
id_pool_t
*
pIdPool
)
{
int32_t
taosIdPoolMaxSize
(
id_pool_t
*
pIdPool
)
{
pthread_mutex_l
ock
(
&
pIdPool
->
mutex
);
taosThreadMutexL
ock
(
&
pIdPool
->
mutex
);
int32_t
ret
=
pIdPool
->
maxId
;
int32_t
ret
=
pIdPool
->
maxId
;
pthread_mutex_u
nlock
(
&
pIdPool
->
mutex
);
taosThreadMutexU
nlock
(
&
pIdPool
->
mutex
);
return
ret
;
return
ret
;
}
}
\ No newline at end of file
source/util/src/tlog.c
浏览文件 @
3544df41
...
@@ -45,8 +45,8 @@ typedef struct {
...
@@ -45,8 +45,8 @@ typedef struct {
int32_t
minBuffSize
;
int32_t
minBuffSize
;
TdFilePtr
pFile
;
TdFilePtr
pFile
;
int32_t
stop
;
int32_t
stop
;
pthread_t
asyncThread
;
TdThread
asyncThread
;
pthread_mutex_t
buffMutex
;
TdThreadMutex
buffMutex
;
tsem_t
buffNotEmpty
;
tsem_t
buffNotEmpty
;
}
SLogBuff
;
}
SLogBuff
;
...
@@ -59,7 +59,7 @@ typedef struct {
...
@@ -59,7 +59,7 @@ typedef struct {
pid_t
pid
;
pid_t
pid
;
char
logName
[
LOG_FILE_NAME_LEN
];
char
logName
[
LOG_FILE_NAME_LEN
];
SLogBuff
*
logHandle
;
SLogBuff
*
logHandle
;
pthread_mutex_t
logMutex
;
TdThreadMutex
logMutex
;
}
SLogObj
;
}
SLogObj
;
static
int8_t
tsLogInited
=
0
;
static
int8_t
tsLogInited
=
0
;
...
@@ -107,12 +107,12 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum)
...
@@ -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
taosCompressFile
(
char
*
srcFileName
,
char
*
destFileName
);
static
int32_t
taosStartLog
()
{
static
int32_t
taosStartLog
()
{
pthread_attr_t
threadAttr
;
TdThreadAttr
threadAttr
;
pthread_attr_i
nit
(
&
threadAttr
);
taosThreadAttrI
nit
(
&
threadAttr
);
if
(
pthread_c
reate
(
&
(
tsLogObj
.
logHandle
->
asyncThread
),
&
threadAttr
,
taosAsyncOutputLog
,
tsLogObj
.
logHandle
)
!=
0
)
{
if
(
taosThreadC
reate
(
&
(
tsLogObj
.
logHandle
->
asyncThread
),
&
threadAttr
,
taosAsyncOutputLog
,
tsLogObj
.
logHandle
)
!=
0
)
{
return
-
1
;
return
-
1
;
}
}
pthread_attr_d
estroy
(
&
threadAttr
);
taosThreadAttrD
estroy
(
&
threadAttr
);
return
0
;
return
0
;
}
}
...
@@ -139,7 +139,7 @@ static void taosStopLog() {
...
@@ -139,7 +139,7 @@ static void taosStopLog() {
void
taosCloseLog
()
{
void
taosCloseLog
()
{
taosStopLog
();
taosStopLog
();
if
(
taosCheckPthreadValid
(
tsLogObj
.
logHandle
->
asyncThread
))
{
if
(
taosCheckPthreadValid
(
tsLogObj
.
logHandle
->
asyncThread
))
{
pthread_j
oin
(
tsLogObj
.
logHandle
->
asyncThread
,
NULL
);
taosThreadJ
oin
(
tsLogObj
.
logHandle
->
asyncThread
,
NULL
);
}
}
tsLogInited
=
0
;
tsLogInited
=
0
;
// In case that other threads still use log resources causing invalid write in valgrind
// In case that other threads still use log resources causing invalid write in valgrind
...
@@ -224,22 +224,22 @@ static void *taosThreadToOpenNewFile(void *param) {
...
@@ -224,22 +224,22 @@ static void *taosThreadToOpenNewFile(void *param) {
}
}
static
int32_t
taosOpenNewLogFile
()
{
static
int32_t
taosOpenNewLogFile
()
{
pthread_mutex_l
ock
(
&
tsLogObj
.
logMutex
);
taosThreadMutexL
ock
(
&
tsLogObj
.
logMutex
);
if
(
tsLogObj
.
lines
>
tsLogObj
.
maxLines
&&
tsLogObj
.
openInProgress
==
0
)
{
if
(
tsLogObj
.
lines
>
tsLogObj
.
maxLines
&&
tsLogObj
.
openInProgress
==
0
)
{
tsLogObj
.
openInProgress
=
1
;
tsLogObj
.
openInProgress
=
1
;
uInfo
(
"open new log file ......"
);
uInfo
(
"open new log file ......"
);
pthread_t
thread
;
TdThread
thread
;
pthread_attr_t
attr
;
TdThreadAttr
attr
;
pthread_attr_i
nit
(
&
attr
);
taosThreadAttrI
nit
(
&
attr
);
pthread_attr_setdetachs
tate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
taosThreadAttrSetDetachS
tate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
pthread_c
reate
(
&
thread
,
&
attr
,
taosThreadToOpenNewFile
,
NULL
);
taosThreadC
reate
(
&
thread
,
&
attr
,
taosThreadToOpenNewFile
,
NULL
);
pthread_attr_d
estroy
(
&
attr
);
taosThreadAttrD
estroy
(
&
attr
);
}
}
pthread_mutex_u
nlock
(
&
tsLogObj
.
logMutex
);
taosThreadMutexU
nlock
(
&
tsLogObj
.
logMutex
);
return
0
;
return
0
;
}
}
...
@@ -344,7 +344,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
...
@@ -344,7 +344,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
char
fileName
[
LOG_FILE_NAME_LEN
+
50
]
=
"
\0
"
;
char
fileName
[
LOG_FILE_NAME_LEN
+
50
]
=
"
\0
"
;
sprintf
(
fileName
,
"%s.%d"
,
tsLogObj
.
logName
,
tsLogObj
.
flag
);
sprintf
(
fileName
,
"%s.%d"
,
tsLogObj
.
logName
,
tsLogObj
.
flag
);
pthread_mutex_i
nit
(
&
tsLogObj
.
logMutex
,
NULL
);
taosThreadMutexI
nit
(
&
tsLogObj
.
logMutex
,
NULL
);
taosUmaskFile
(
0
);
taosUmaskFile
(
0
);
tsLogObj
.
logHandle
->
pFile
=
taosOpenFile
(
fileName
,
TD_FILE_CTEATE
|
TD_FILE_WRITE
);
tsLogObj
.
logHandle
->
pFile
=
taosOpenFile
(
fileName
,
TD_FILE_CTEATE
|
TD_FILE_WRITE
);
...
@@ -518,7 +518,7 @@ static SLogBuff *taosLogBuffNew(int32_t bufSize) {
...
@@ -518,7 +518,7 @@ static SLogBuff *taosLogBuffNew(int32_t bufSize) {
tLogBuff
->
minBuffSize
=
bufSize
/
10
;
tLogBuff
->
minBuffSize
=
bufSize
/
10
;
tLogBuff
->
stop
=
0
;
tLogBuff
->
stop
=
0
;
if
(
pthread_mutex_i
nit
(
&
LOG_BUF_MUTEX
(
tLogBuff
),
NULL
)
<
0
)
goto
_err
;
if
(
taosThreadMutexI
nit
(
&
LOG_BUF_MUTEX
(
tLogBuff
),
NULL
)
<
0
)
goto
_err
;
// tsem_init(&(tLogBuff->buffNotEmpty), 0, 0);
// tsem_init(&(tLogBuff->buffNotEmpty), 0, 0);
return
tLogBuff
;
return
tLogBuff
;
...
@@ -553,7 +553,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
...
@@ -553,7 +553,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
if
(
tLogBuff
==
NULL
||
tLogBuff
->
stop
)
return
-
1
;
if
(
tLogBuff
==
NULL
||
tLogBuff
->
stop
)
return
-
1
;
pthread_mutex_l
ock
(
&
LOG_BUF_MUTEX
(
tLogBuff
));
taosThreadMutexL
ock
(
&
LOG_BUF_MUTEX
(
tLogBuff
));
start
=
LOG_BUF_START
(
tLogBuff
);
start
=
LOG_BUF_START
(
tLogBuff
);
end
=
LOG_BUF_END
(
tLogBuff
);
end
=
LOG_BUF_END
(
tLogBuff
);
...
@@ -567,7 +567,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
...
@@ -567,7 +567,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
if
(
remainSize
<=
msgLen
||
((
lostLine
>
0
)
&&
(
remainSize
<=
(
msgLen
+
tmpBufLen
))))
{
if
(
remainSize
<=
msgLen
||
((
lostLine
>
0
)
&&
(
remainSize
<=
(
msgLen
+
tmpBufLen
))))
{
lostLine
++
;
lostLine
++
;
tsAsyncLogLostLines
++
;
tsAsyncLogLostLines
++
;
pthread_mutex_u
nlock
(
&
LOG_BUF_MUTEX
(
tLogBuff
));
taosThreadMutexU
nlock
(
&
LOG_BUF_MUTEX
(
tLogBuff
));
return
-
1
;
return
-
1
;
}
}
...
@@ -588,7 +588,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
...
@@ -588,7 +588,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
}
}
*/
*/
pthread_mutex_u
nlock
(
&
LOG_BUF_MUTEX
(
tLogBuff
));
taosThreadMutexU
nlock
(
&
LOG_BUF_MUTEX
(
tLogBuff
));
return
0
;
return
0
;
}
}
...
...
source/util/src/tmempool.c
浏览文件 @
3544df41
...
@@ -25,7 +25,7 @@ typedef struct {
...
@@ -25,7 +25,7 @@ typedef struct {
int32_t
blockSize
;
/* block size in bytes */
int32_t
blockSize
;
/* block size in bytes */
int32_t
*
freeList
;
/* the index list */
int32_t
*
freeList
;
/* the index list */
char
*
pool
;
/* the actual mem block */
char
*
pool
;
/* the actual mem block */
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
}
pool_t
;
}
pool_t
;
mpool_h
taosMemPoolInit
(
int32_t
numOfBlock
,
int32_t
blockSize
)
{
mpool_h
taosMemPoolInit
(
int32_t
numOfBlock
,
int32_t
blockSize
)
{
...
@@ -58,7 +58,7 @@ mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) {
...
@@ -58,7 +58,7 @@ mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) {
return
NULL
;
return
NULL
;
}
}
pthread_mutex_i
nit
(
&
(
pool_p
->
mutex
),
NULL
);
taosThreadMutexI
nit
(
&
(
pool_p
->
mutex
),
NULL
);
memset
(
pool_p
->
pool
,
0
,
(
size_t
)(
blockSize
*
numOfBlock
));
memset
(
pool_p
->
pool
,
0
,
(
size_t
)(
blockSize
*
numOfBlock
));
for
(
i
=
0
;
i
<
pool_p
->
numOfBlock
;
++
i
)
pool_p
->
freeList
[
i
]
=
i
;
for
(
i
=
0
;
i
<
pool_p
->
numOfBlock
;
++
i
)
pool_p
->
freeList
[
i
]
=
i
;
...
@@ -73,7 +73,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
...
@@ -73,7 +73,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
char
*
pos
=
NULL
;
char
*
pos
=
NULL
;
pool_t
*
pool_p
=
(
pool_t
*
)
handle
;
pool_t
*
pool_p
=
(
pool_t
*
)
handle
;
pthread_mutex_l
ock
(
&
(
pool_p
->
mutex
));
taosThreadMutexL
ock
(
&
(
pool_p
->
mutex
));
if
(
pool_p
->
numOfFree
>
0
)
{
if
(
pool_p
->
numOfFree
>
0
)
{
pos
=
pool_p
->
pool
+
pool_p
->
blockSize
*
(
pool_p
->
freeList
[
pool_p
->
first
]);
pos
=
pool_p
->
pool
+
pool_p
->
blockSize
*
(
pool_p
->
freeList
[
pool_p
->
first
]);
...
@@ -82,7 +82,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
...
@@ -82,7 +82,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
pool_p
->
numOfFree
--
;
pool_p
->
numOfFree
--
;
}
}
pthread_mutex_u
nlock
(
&
(
pool_p
->
mutex
));
taosThreadMutexU
nlock
(
&
(
pool_p
->
mutex
));
if
(
pos
==
NULL
)
uDebug
(
"mempool: out of memory"
);
if
(
pos
==
NULL
)
uDebug
(
"mempool: out of memory"
);
return
pos
;
return
pos
;
...
@@ -108,18 +108,18 @@ void taosMemPoolFree(mpool_h handle, char *pMem) {
...
@@ -108,18 +108,18 @@ void taosMemPoolFree(mpool_h handle, char *pMem) {
memset
(
pMem
,
0
,
(
size_t
)
pool_p
->
blockSize
);
memset
(
pMem
,
0
,
(
size_t
)
pool_p
->
blockSize
);
pthread_mutex_l
ock
(
&
pool_p
->
mutex
);
taosThreadMutexL
ock
(
&
pool_p
->
mutex
);
pool_p
->
freeList
[(
pool_p
->
first
+
pool_p
->
numOfFree
)
%
pool_p
->
numOfBlock
]
=
index
;
pool_p
->
freeList
[(
pool_p
->
first
+
pool_p
->
numOfFree
)
%
pool_p
->
numOfBlock
]
=
index
;
pool_p
->
numOfFree
++
;
pool_p
->
numOfFree
++
;
pthread_mutex_u
nlock
(
&
pool_p
->
mutex
);
taosThreadMutexU
nlock
(
&
pool_p
->
mutex
);
}
}
void
taosMemPoolCleanUp
(
mpool_h
handle
)
{
void
taosMemPoolCleanUp
(
mpool_h
handle
)
{
pool_t
*
pool_p
=
(
pool_t
*
)
handle
;
pool_t
*
pool_p
=
(
pool_t
*
)
handle
;
pthread_mutex_d
estroy
(
&
pool_p
->
mutex
);
taosThreadMutexD
estroy
(
&
pool_p
->
mutex
);
if
(
pool_p
->
pool
)
free
(
pool_p
->
pool
);
if
(
pool_p
->
pool
)
free
(
pool_p
->
pool
);
if
(
pool_p
->
freeList
)
free
(
pool_p
->
freeList
);
if
(
pool_p
->
freeList
)
free
(
pool_p
->
freeList
);
memset
(
pool_p
,
0
,
sizeof
(
*
pool_p
));
memset
(
pool_p
,
0
,
sizeof
(
*
pool_p
));
...
...
source/util/src/tqueue.c
浏览文件 @
3544df41
...
@@ -37,13 +37,13 @@ typedef struct STaosQueue {
...
@@ -37,13 +37,13 @@ typedef struct STaosQueue {
void
*
ahandle
;
// for queue set
void
*
ahandle
;
// for queue set
FItem
itemFp
;
FItem
itemFp
;
FItems
itemsFp
;
FItems
itemsFp
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
}
STaosQueue
;
}
STaosQueue
;
typedef
struct
STaosQset
{
typedef
struct
STaosQset
{
STaosQueue
*
head
;
STaosQueue
*
head
;
STaosQueue
*
current
;
STaosQueue
*
current
;
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
int32_t
numOfQueues
;
int32_t
numOfQueues
;
int32_t
numOfItems
;
int32_t
numOfItems
;
tsem_t
sem
;
tsem_t
sem
;
...
@@ -63,7 +63,7 @@ STaosQueue *taosOpenQueue() {
...
@@ -63,7 +63,7 @@ STaosQueue *taosOpenQueue() {
return
NULL
;
return
NULL
;
}
}
if
(
pthread_mutex_i
nit
(
&
queue
->
mutex
,
NULL
)
!=
0
)
{
if
(
taosThreadMutexI
nit
(
&
queue
->
mutex
,
NULL
)
!=
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
}
}
...
@@ -84,11 +84,11 @@ void taosCloseQueue(STaosQueue *queue) {
...
@@ -84,11 +84,11 @@ void taosCloseQueue(STaosQueue *queue) {
STaosQnode
*
pTemp
;
STaosQnode
*
pTemp
;
STaosQset
*
qset
;
STaosQset
*
qset
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
STaosQnode
*
pNode
=
queue
->
head
;
STaosQnode
*
pNode
=
queue
->
head
;
queue
->
head
=
NULL
;
queue
->
head
=
NULL
;
qset
=
queue
->
qset
;
qset
=
queue
->
qset
;
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
if
(
queue
->
qset
)
{
if
(
queue
->
qset
)
{
taosRemoveFromQset
(
qset
,
queue
);
taosRemoveFromQset
(
qset
,
queue
);
...
@@ -100,7 +100,7 @@ void taosCloseQueue(STaosQueue *queue) {
...
@@ -100,7 +100,7 @@ void taosCloseQueue(STaosQueue *queue) {
free
(
pTemp
);
free
(
pTemp
);
}
}
pthread_mutex_d
estroy
(
&
queue
->
mutex
);
taosThreadMutexD
estroy
(
&
queue
->
mutex
);
free
(
queue
);
free
(
queue
);
uDebug
(
"queue:%p is closed"
,
queue
);
uDebug
(
"queue:%p is closed"
,
queue
);
...
@@ -110,19 +110,19 @@ bool taosQueueEmpty(STaosQueue *queue) {
...
@@ -110,19 +110,19 @@ bool taosQueueEmpty(STaosQueue *queue) {
if
(
queue
==
NULL
)
return
true
;
if
(
queue
==
NULL
)
return
true
;
bool
empty
=
false
;
bool
empty
=
false
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
if
(
queue
->
head
==
NULL
&&
queue
->
tail
==
NULL
)
{
if
(
queue
->
head
==
NULL
&&
queue
->
tail
==
NULL
)
{
empty
=
true
;
empty
=
true
;
}
}
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
return
empty
;
return
empty
;
}
}
int32_t
taosQueueSize
(
STaosQueue
*
queue
)
{
int32_t
taosQueueSize
(
STaosQueue
*
queue
)
{
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
int32_t
numOfItems
=
queue
->
numOfItems
;
int32_t
numOfItems
=
queue
->
numOfItems
;
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
return
numOfItems
;
return
numOfItems
;
}
}
...
@@ -151,7 +151,7 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
...
@@ -151,7 +151,7 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
STaosQnode
*
pNode
=
(
STaosQnode
*
)(((
char
*
)
pItem
)
-
sizeof
(
STaosQnode
));
STaosQnode
*
pNode
=
(
STaosQnode
*
)(((
char
*
)
pItem
)
-
sizeof
(
STaosQnode
));
pNode
->
next
=
NULL
;
pNode
->
next
=
NULL
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
if
(
queue
->
tail
)
{
if
(
queue
->
tail
)
{
queue
->
tail
->
next
=
pNode
;
queue
->
tail
->
next
=
pNode
;
...
@@ -165,7 +165,7 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
...
@@ -165,7 +165,7 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
if
(
queue
->
qset
)
atomic_add_fetch_32
(
&
queue
->
qset
->
numOfItems
,
1
);
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
);
uTrace
(
"item:%p is put into queue:%p, items:%d"
,
pItem
,
queue
,
queue
->
numOfItems
);
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
if
(
queue
->
qset
)
tsem_post
(
&
queue
->
qset
->
sem
);
if
(
queue
->
qset
)
tsem_post
(
&
queue
->
qset
->
sem
);
...
@@ -176,7 +176,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
...
@@ -176,7 +176,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
STaosQnode
*
pNode
=
NULL
;
STaosQnode
*
pNode
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
if
(
queue
->
head
)
{
if
(
queue
->
head
)
{
pNode
=
queue
->
head
;
pNode
=
queue
->
head
;
...
@@ -189,7 +189,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
...
@@ -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
);
uTrace
(
"item:%p is read out from queue:%p, items:%d"
,
*
ppItem
,
queue
,
queue
->
numOfItems
);
}
}
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
return
code
;
return
code
;
}
}
...
@@ -202,7 +202,7 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
...
@@ -202,7 +202,7 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
int32_t
code
=
0
;
int32_t
code
=
0
;
bool
empty
;
bool
empty
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
empty
=
queue
->
head
==
NULL
;
empty
=
queue
->
head
==
NULL
;
if
(
!
empty
)
{
if
(
!
empty
)
{
...
@@ -219,7 +219,7 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
...
@@ -219,7 +219,7 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
if
(
queue
->
qset
)
atomic_sub_fetch_32
(
&
queue
->
qset
->
numOfItems
,
qall
->
numOfItems
);
if
(
queue
->
qset
)
atomic_sub_fetch_32
(
&
queue
->
qset
->
numOfItems
,
qall
->
numOfItems
);
}
}
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
// if source queue is empty, we set destination qall to empty too.
// if source queue is empty, we set destination qall to empty too.
if
(
empty
)
{
if
(
empty
)
{
...
@@ -255,7 +255,7 @@ STaosQset *taosOpenQset() {
...
@@ -255,7 +255,7 @@ STaosQset *taosOpenQset() {
return
NULL
;
return
NULL
;
}
}
pthread_mutex_i
nit
(
&
qset
->
mutex
,
NULL
);
taosThreadMutexI
nit
(
&
qset
->
mutex
,
NULL
);
tsem_init
(
&
qset
->
sem
,
0
,
0
);
tsem_init
(
&
qset
->
sem
,
0
,
0
);
uDebug
(
"qset:%p is opened"
,
qset
);
uDebug
(
"qset:%p is opened"
,
qset
);
...
@@ -266,7 +266,7 @@ void taosCloseQset(STaosQset *qset) {
...
@@ -266,7 +266,7 @@ void taosCloseQset(STaosQset *qset) {
if
(
qset
==
NULL
)
return
;
if
(
qset
==
NULL
)
return
;
// remove all the queues from qset
// remove all the queues from qset
pthread_mutex_l
ock
(
&
qset
->
mutex
);
taosThreadMutexL
ock
(
&
qset
->
mutex
);
while
(
qset
->
head
)
{
while
(
qset
->
head
)
{
STaosQueue
*
queue
=
qset
->
head
;
STaosQueue
*
queue
=
qset
->
head
;
qset
->
head
=
qset
->
head
->
next
;
qset
->
head
=
qset
->
head
->
next
;
...
@@ -274,9 +274,9 @@ void taosCloseQset(STaosQset *qset) {
...
@@ -274,9 +274,9 @@ void taosCloseQset(STaosQset *qset) {
queue
->
qset
=
NULL
;
queue
->
qset
=
NULL
;
queue
->
next
=
NULL
;
queue
->
next
=
NULL
;
}
}
pthread_mutex_u
nlock
(
&
qset
->
mutex
);
taosThreadMutexU
nlock
(
&
qset
->
mutex
);
pthread_mutex_d
estroy
(
&
qset
->
mutex
);
taosThreadMutexD
estroy
(
&
qset
->
mutex
);
tsem_destroy
(
&
qset
->
sem
);
tsem_destroy
(
&
qset
->
sem
);
free
(
qset
);
free
(
qset
);
uDebug
(
"qset:%p is closed"
,
qset
);
uDebug
(
"qset:%p is closed"
,
qset
);
...
@@ -293,19 +293,19 @@ void taosQsetThreadResume(STaosQset *qset) {
...
@@ -293,19 +293,19 @@ void taosQsetThreadResume(STaosQset *qset) {
int32_t
taosAddIntoQset
(
STaosQset
*
qset
,
STaosQueue
*
queue
,
void
*
ahandle
)
{
int32_t
taosAddIntoQset
(
STaosQset
*
qset
,
STaosQueue
*
queue
,
void
*
ahandle
)
{
if
(
queue
->
qset
)
return
-
1
;
if
(
queue
->
qset
)
return
-
1
;
pthread_mutex_l
ock
(
&
qset
->
mutex
);
taosThreadMutexL
ock
(
&
qset
->
mutex
);
queue
->
next
=
qset
->
head
;
queue
->
next
=
qset
->
head
;
queue
->
ahandle
=
ahandle
;
queue
->
ahandle
=
ahandle
;
qset
->
head
=
queue
;
qset
->
head
=
queue
;
qset
->
numOfQueues
++
;
qset
->
numOfQueues
++
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
atomic_add_fetch_32
(
&
qset
->
numOfItems
,
queue
->
numOfItems
);
atomic_add_fetch_32
(
&
qset
->
numOfItems
,
queue
->
numOfItems
);
queue
->
qset
=
qset
;
queue
->
qset
=
qset
;
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
pthread_mutex_u
nlock
(
&
qset
->
mutex
);
taosThreadMutexU
nlock
(
&
qset
->
mutex
);
uTrace
(
"queue:%p is added into qset:%p"
,
queue
,
qset
);
uTrace
(
"queue:%p is added into qset:%p"
,
queue
,
qset
);
return
0
;
return
0
;
...
@@ -314,7 +314,7 @@ int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) {
...
@@ -314,7 +314,7 @@ int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) {
void
taosRemoveFromQset
(
STaosQset
*
qset
,
STaosQueue
*
queue
)
{
void
taosRemoveFromQset
(
STaosQset
*
qset
,
STaosQueue
*
queue
)
{
STaosQueue
*
tqueue
=
NULL
;
STaosQueue
*
tqueue
=
NULL
;
pthread_mutex_l
ock
(
&
qset
->
mutex
);
taosThreadMutexL
ock
(
&
qset
->
mutex
);
if
(
qset
->
head
)
{
if
(
qset
->
head
)
{
if
(
qset
->
head
==
queue
)
{
if
(
qset
->
head
==
queue
)
{
...
@@ -339,15 +339,15 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) {
...
@@ -339,15 +339,15 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) {
if
(
qset
->
current
==
queue
)
qset
->
current
=
tqueue
->
next
;
if
(
qset
->
current
==
queue
)
qset
->
current
=
tqueue
->
next
;
qset
->
numOfQueues
--
;
qset
->
numOfQueues
--
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
atomic_sub_fetch_32
(
&
qset
->
numOfItems
,
queue
->
numOfItems
);
atomic_sub_fetch_32
(
&
qset
->
numOfItems
,
queue
->
numOfItems
);
queue
->
qset
=
NULL
;
queue
->
qset
=
NULL
;
queue
->
next
=
NULL
;
queue
->
next
=
NULL
;
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
}
}
}
}
pthread_mutex_u
nlock
(
&
qset
->
mutex
);
taosThreadMutexU
nlock
(
&
qset
->
mutex
);
uDebug
(
"queue:%p is removed from qset:%p"
,
queue
,
qset
);
uDebug
(
"queue:%p is removed from qset:%p"
,
queue
,
qset
);
}
}
...
@@ -360,7 +360,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FI
...
@@ -360,7 +360,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FI
tsem_wait
(
&
qset
->
sem
);
tsem_wait
(
&
qset
->
sem
);
pthread_mutex_l
ock
(
&
qset
->
mutex
);
taosThreadMutexL
ock
(
&
qset
->
mutex
);
for
(
int32_t
i
=
0
;
i
<
qset
->
numOfQueues
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
qset
->
numOfQueues
;
++
i
)
{
if
(
qset
->
current
==
NULL
)
qset
->
current
=
qset
->
head
;
if
(
qset
->
current
==
NULL
)
qset
->
current
=
qset
->
head
;
...
@@ -369,7 +369,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FI
...
@@ -369,7 +369,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FI
if
(
queue
==
NULL
)
break
;
if
(
queue
==
NULL
)
break
;
if
(
queue
->
head
==
NULL
)
continue
;
if
(
queue
->
head
==
NULL
)
continue
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
if
(
queue
->
head
)
{
if
(
queue
->
head
)
{
pNode
=
queue
->
head
;
pNode
=
queue
->
head
;
...
@@ -385,11 +385,11 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FI
...
@@ -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
);
uTrace
(
"item:%p is read out from queue:%p, items:%d"
,
*
ppItem
,
queue
,
queue
->
numOfItems
);
}
}
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
if
(
pNode
)
break
;
if
(
pNode
)
break
;
}
}
pthread_mutex_u
nlock
(
&
qset
->
mutex
);
taosThreadMutexU
nlock
(
&
qset
->
mutex
);
return
code
;
return
code
;
}
}
...
@@ -399,7 +399,7 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
...
@@ -399,7 +399,7 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
int32_t
code
=
0
;
int32_t
code
=
0
;
tsem_wait
(
&
qset
->
sem
);
tsem_wait
(
&
qset
->
sem
);
pthread_mutex_l
ock
(
&
qset
->
mutex
);
taosThreadMutexL
ock
(
&
qset
->
mutex
);
for
(
int32_t
i
=
0
;
i
<
qset
->
numOfQueues
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
qset
->
numOfQueues
;
++
i
)
{
if
(
qset
->
current
==
NULL
)
qset
->
current
=
qset
->
head
;
if
(
qset
->
current
==
NULL
)
qset
->
current
=
qset
->
head
;
...
@@ -408,7 +408,7 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
...
@@ -408,7 +408,7 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
if
(
queue
==
NULL
)
break
;
if
(
queue
==
NULL
)
break
;
if
(
queue
->
head
==
NULL
)
continue
;
if
(
queue
->
head
==
NULL
)
continue
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
if
(
queue
->
head
)
{
if
(
queue
->
head
)
{
qall
->
current
=
queue
->
head
;
qall
->
current
=
queue
->
head
;
...
@@ -428,12 +428,12 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
...
@@ -428,12 +428,12 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
}
}
}
}
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
if
(
code
!=
0
)
break
;
if
(
code
!=
0
)
break
;
}
}
pthread_mutex_u
nlock
(
&
qset
->
mutex
);
taosThreadMutexU
nlock
(
&
qset
->
mutex
);
return
code
;
return
code
;
}
}
...
@@ -443,7 +443,7 @@ int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **aha
...
@@ -443,7 +443,7 @@ int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **aha
tsem_wait
(
&
qset
->
sem
);
tsem_wait
(
&
qset
->
sem
);
pthread_mutex_l
ock
(
&
qset
->
mutex
);
taosThreadMutexL
ock
(
&
qset
->
mutex
);
for
(
int32_t
i
=
0
;
i
<
qset
->
numOfQueues
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
qset
->
numOfQueues
;
++
i
)
{
if
(
qset
->
current
==
NULL
)
qset
->
current
=
qset
->
head
;
if
(
qset
->
current
==
NULL
)
qset
->
current
=
qset
->
head
;
...
@@ -456,7 +456,7 @@ int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **aha
...
@@ -456,7 +456,7 @@ int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **aha
continue
;
continue
;
}
}
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
if
(
queue
->
head
)
{
if
(
queue
->
head
)
{
pNode
=
queue
->
head
;
pNode
=
queue
->
head
;
...
@@ -475,11 +475,11 @@ int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **aha
...
@@ -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
);
uTrace
(
"item:%p is read out from queue:%p, items:%d"
,
*
ppItem
,
queue
,
queue
->
numOfItems
);
}
}
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
if
(
pNode
)
break
;
if
(
pNode
)
break
;
}
}
pthread_mutex_u
nlock
(
&
qset
->
mutex
);
taosThreadMutexU
nlock
(
&
qset
->
mutex
);
return
code
;
return
code
;
}
}
...
@@ -488,21 +488,21 @@ void taosResetQsetThread(STaosQset *qset, void *pItem) {
...
@@ -488,21 +488,21 @@ void taosResetQsetThread(STaosQset *qset, void *pItem) {
if
(
pItem
==
NULL
)
return
;
if
(
pItem
==
NULL
)
return
;
STaosQnode
*
pNode
=
(
STaosQnode
*
)((
char
*
)
pItem
-
sizeof
(
STaosQnode
));
STaosQnode
*
pNode
=
(
STaosQnode
*
)((
char
*
)
pItem
-
sizeof
(
STaosQnode
));
pthread_mutex_l
ock
(
&
qset
->
mutex
);
taosThreadMutexL
ock
(
&
qset
->
mutex
);
pNode
->
queue
->
threadId
=
-
1
;
pNode
->
queue
->
threadId
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
pNode
->
queue
->
numOfItems
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pNode
->
queue
->
numOfItems
;
++
i
)
{
tsem_post
(
&
qset
->
sem
);
tsem_post
(
&
qset
->
sem
);
}
}
pthread_mutex_u
nlock
(
&
qset
->
mutex
);
taosThreadMutexU
nlock
(
&
qset
->
mutex
);
}
}
int32_t
taosGetQueueItemsNumber
(
STaosQueue
*
queue
)
{
int32_t
taosGetQueueItemsNumber
(
STaosQueue
*
queue
)
{
if
(
!
queue
)
return
0
;
if
(
!
queue
)
return
0
;
int32_t
num
;
int32_t
num
;
pthread_mutex_l
ock
(
&
queue
->
mutex
);
taosThreadMutexL
ock
(
&
queue
->
mutex
);
num
=
queue
->
numOfItems
;
num
=
queue
->
numOfItems
;
pthread_mutex_u
nlock
(
&
queue
->
mutex
);
taosThreadMutexU
nlock
(
&
queue
->
mutex
);
return
num
;
return
num
;
}
}
...
@@ -510,8 +510,8 @@ int32_t taosGetQsetItemsNumber(STaosQset *qset) {
...
@@ -510,8 +510,8 @@ int32_t taosGetQsetItemsNumber(STaosQset *qset) {
if
(
!
qset
)
return
0
;
if
(
!
qset
)
return
0
;
int32_t
num
=
0
;
int32_t
num
=
0
;
pthread_mutex_l
ock
(
&
qset
->
mutex
);
taosThreadMutexL
ock
(
&
qset
->
mutex
);
num
=
qset
->
numOfItems
;
num
=
qset
->
numOfItems
;
pthread_mutex_u
nlock
(
&
qset
->
mutex
);
taosThreadMutexU
nlock
(
&
qset
->
mutex
);
return
num
;
return
num
;
}
}
source/util/src/tref.c
浏览文件 @
3544df41
...
@@ -45,8 +45,8 @@ typedef struct {
...
@@ -45,8 +45,8 @@ typedef struct {
}
SRefSet
;
}
SRefSet
;
static
SRefSet
tsRefSetList
[
TSDB_REF_OBJECTS
];
static
SRefSet
tsRefSetList
[
TSDB_REF_OBJECTS
];
static
pthread_once_t
tsRefModuleInit
=
PTHREAD_ONCE_INIT
;
static
TdThreadOnce
tsRefModuleInit
=
PTHREAD_ONCE_INIT
;
static
pthread_mutex_t
tsRefMutex
;
static
TdThreadMutex
tsRefMutex
;
static
int32_t
tsRefSetNum
=
0
;
static
int32_t
tsRefSetNum
=
0
;
static
int32_t
tsNextId
=
0
;
static
int32_t
tsNextId
=
0
;
...
@@ -63,7 +63,7 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) {
...
@@ -63,7 +63,7 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) {
int64_t
*
lockedBy
;
int64_t
*
lockedBy
;
int32_t
i
,
rsetId
;
int32_t
i
,
rsetId
;
pthread_o
nce
(
&
tsRefModuleInit
,
taosInitRefModule
);
taosThreadO
nce
(
&
tsRefModuleInit
,
taosInitRefModule
);
nodeList
=
calloc
(
sizeof
(
SRefNode
*
),
(
size_t
)
max
);
nodeList
=
calloc
(
sizeof
(
SRefNode
*
),
(
size_t
)
max
);
if
(
nodeList
==
NULL
)
{
if
(
nodeList
==
NULL
)
{
...
@@ -78,7 +78,7 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) {
...
@@ -78,7 +78,7 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) {
return
-
1
;
return
-
1
;
}
}
pthread_mutex_l
ock
(
&
tsRefMutex
);
taosThreadMutexL
ock
(
&
tsRefMutex
);
for
(
i
=
0
;
i
<
TSDB_REF_OBJECTS
;
++
i
)
{
for
(
i
=
0
;
i
<
TSDB_REF_OBJECTS
;
++
i
)
{
tsNextId
=
(
tsNextId
+
1
)
%
TSDB_REF_OBJECTS
;
tsNextId
=
(
tsNextId
+
1
)
%
TSDB_REF_OBJECTS
;
...
@@ -107,7 +107,7 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *)) {
...
@@ -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
);
uTrace
(
"run out of Ref ID, maximum:%d refSetNum:%d"
,
TSDB_REF_OBJECTS
,
tsRefSetNum
);
}
}
pthread_mutex_u
nlock
(
&
tsRefMutex
);
taosThreadMutexU
nlock
(
&
tsRefMutex
);
return
rsetId
;
return
rsetId
;
}
}
...
@@ -124,7 +124,7 @@ int32_t taosCloseRef(int32_t rsetId) {
...
@@ -124,7 +124,7 @@ int32_t taosCloseRef(int32_t rsetId) {
pSet
=
tsRefSetList
+
rsetId
;
pSet
=
tsRefSetList
+
rsetId
;
pthread_mutex_l
ock
(
&
tsRefMutex
);
taosThreadMutexL
ock
(
&
tsRefMutex
);
if
(
pSet
->
state
==
TSDB_REF_STATE_ACTIVE
)
{
if
(
pSet
->
state
==
TSDB_REF_STATE_ACTIVE
)
{
pSet
->
state
=
TSDB_REF_STATE_DELETED
;
pSet
->
state
=
TSDB_REF_STATE_DELETED
;
...
@@ -134,7 +134,7 @@ int32_t taosCloseRef(int32_t rsetId) {
...
@@ -134,7 +134,7 @@ int32_t taosCloseRef(int32_t rsetId) {
uTrace
(
"rsetId:%d is already closed, count:%d"
,
rsetId
,
pSet
->
count
);
uTrace
(
"rsetId:%d is already closed, count:%d"
,
rsetId
,
pSet
->
count
);
}
}
pthread_mutex_u
nlock
(
&
tsRefMutex
);
taosThreadMutexU
nlock
(
&
tsRefMutex
);
if
(
deleted
)
taosDecRsetCount
(
pSet
);
if
(
deleted
)
taosDecRsetCount
(
pSet
);
...
@@ -354,7 +354,7 @@ int32_t taosListRef() {
...
@@ -354,7 +354,7 @@ int32_t taosListRef() {
SRefNode
*
pNode
;
SRefNode
*
pNode
;
int32_t
num
=
0
;
int32_t
num
=
0
;
pthread_mutex_l
ock
(
&
tsRefMutex
);
taosThreadMutexL
ock
(
&
tsRefMutex
);
for
(
int32_t
i
=
0
;
i
<
TSDB_REF_OBJECTS
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_REF_OBJECTS
;
++
i
)
{
pSet
=
tsRefSetList
+
i
;
pSet
=
tsRefSetList
+
i
;
...
@@ -374,7 +374,7 @@ int32_t taosListRef() {
...
@@ -374,7 +374,7 @@ int32_t taosListRef() {
}
}
}
}
pthread_mutex_u
nlock
(
&
tsRefMutex
);
taosThreadMutexU
nlock
(
&
tsRefMutex
);
return
num
;
return
num
;
}
}
...
@@ -470,7 +470,7 @@ static void taosUnlockList(int64_t *lockedBy) {
...
@@ -470,7 +470,7 @@ static void taosUnlockList(int64_t *lockedBy) {
}
}
}
}
static
void
taosInitRefModule
(
void
)
{
pthread_mutex_i
nit
(
&
tsRefMutex
,
NULL
);
}
static
void
taosInitRefModule
(
void
)
{
taosThreadMutexI
nit
(
&
tsRefMutex
,
NULL
);
}
static
void
taosIncRsetCount
(
SRefSet
*
pSet
)
{
static
void
taosIncRsetCount
(
SRefSet
*
pSet
)
{
atomic_add_fetch_32
(
&
pSet
->
count
,
1
);
atomic_add_fetch_32
(
&
pSet
->
count
,
1
);
...
@@ -483,7 +483,7 @@ static void taosDecRsetCount(SRefSet *pSet) {
...
@@ -483,7 +483,7 @@ static void taosDecRsetCount(SRefSet *pSet) {
if
(
count
>
0
)
return
;
if
(
count
>
0
)
return
;
pthread_mutex_l
ock
(
&
tsRefMutex
);
taosThreadMutexL
ock
(
&
tsRefMutex
);
if
(
pSet
->
state
!=
TSDB_REF_STATE_EMPTY
)
{
if
(
pSet
->
state
!=
TSDB_REF_STATE_EMPTY
)
{
pSet
->
state
=
TSDB_REF_STATE_EMPTY
;
pSet
->
state
=
TSDB_REF_STATE_EMPTY
;
...
@@ -497,5 +497,5 @@ static void taosDecRsetCount(SRefSet *pSet) {
...
@@ -497,5 +497,5 @@ static void taosDecRsetCount(SRefSet *pSet) {
uTrace
(
"rsetId:%d is cleaned, refSetNum:%d count:%d"
,
pSet
->
rsetId
,
tsRefSetNum
,
pSet
->
count
);
uTrace
(
"rsetId:%d is cleaned, refSetNum:%d count:%d"
,
pSet
->
rsetId
,
tsRefSetNum
,
pSet
->
count
);
}
}
pthread_mutex_u
nlock
(
&
tsRefMutex
);
taosThreadMutexU
nlock
(
&
tsRefMutex
);
}
}
source/util/src/tsched.c
浏览文件 @
3544df41
...
@@ -26,12 +26,12 @@ typedef struct {
...
@@ -26,12 +26,12 @@ typedef struct {
char
label
[
TSDB_LABEL_LEN
];
char
label
[
TSDB_LABEL_LEN
];
tsem_t
emptySem
;
tsem_t
emptySem
;
tsem_t
fullSem
;
tsem_t
fullSem
;
pthread_mutex_t
queueMutex
;
TdThreadMutex
queueMutex
;
int32_t
fullSlot
;
int32_t
fullSlot
;
int32_t
emptySlot
;
int32_t
emptySlot
;
int32_t
queueSize
;
int32_t
queueSize
;
int32_t
numOfThreads
;
int32_t
numOfThreads
;
pthread_t
*
qthread
;
TdThread
*
qthread
;
SSchedMsg
*
queue
;
SSchedMsg
*
queue
;
bool
stop
;
bool
stop
;
void
*
pTmrCtrl
;
void
*
pTmrCtrl
;
...
@@ -55,7 +55,7 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
...
@@ -55,7 +55,7 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
return
NULL
;
return
NULL
;
}
}
pSched
->
qthread
=
calloc
(
sizeof
(
pthread_t
),
numOfThreads
);
pSched
->
qthread
=
calloc
(
sizeof
(
TdThread
),
numOfThreads
);
if
(
pSched
->
qthread
==
NULL
)
{
if
(
pSched
->
qthread
==
NULL
)
{
uError
(
"%s: no enough memory for qthread"
,
label
);
uError
(
"%s: no enough memory for qthread"
,
label
);
taosCleanUpScheduler
(
pSched
);
taosCleanUpScheduler
(
pSched
);
...
@@ -68,7 +68,7 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
...
@@ -68,7 +68,7 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
pSched
->
fullSlot
=
0
;
pSched
->
fullSlot
=
0
;
pSched
->
emptySlot
=
0
;
pSched
->
emptySlot
=
0
;
if
(
pthread_mutex_i
nit
(
&
pSched
->
queueMutex
,
NULL
)
<
0
)
{
if
(
taosThreadMutexI
nit
(
&
pSched
->
queueMutex
,
NULL
)
<
0
)
{
uError
(
"init %s:queueMutex failed(%s)"
,
label
,
strerror
(
errno
));
uError
(
"init %s:queueMutex failed(%s)"
,
label
,
strerror
(
errno
));
taosCleanUpScheduler
(
pSched
);
taosCleanUpScheduler
(
pSched
);
return
NULL
;
return
NULL
;
...
@@ -88,11 +88,11 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
...
@@ -88,11 +88,11 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
pSched
->
stop
=
false
;
pSched
->
stop
=
false
;
for
(
int32_t
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
pthread_attr_t
attr
;
TdThreadAttr
attr
;
pthread_attr_i
nit
(
&
attr
);
taosThreadAttrI
nit
(
&
attr
);
pthread_attr_setdetachs
tate
(
&
attr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
attr
,
PTHREAD_CREATE_JOINABLE
);
int32_t
code
=
pthread_c
reate
(
pSched
->
qthread
+
i
,
&
attr
,
taosProcessSchedQueue
,
(
void
*
)
pSched
);
int32_t
code
=
taosThreadC
reate
(
pSched
->
qthread
+
i
,
&
attr
,
taosProcessSchedQueue
,
(
void
*
)
pSched
);
pthread_attr_d
estroy
(
&
attr
);
taosThreadAttrD
estroy
(
&
attr
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
uError
(
"%s: failed to create rpc thread(%s)"
,
label
,
strerror
(
errno
));
uError
(
"%s: failed to create rpc thread(%s)"
,
label
,
strerror
(
errno
));
taosCleanUpScheduler
(
pSched
);
taosCleanUpScheduler
(
pSched
);
...
@@ -135,7 +135,7 @@ void *taosProcessSchedQueue(void *scheduler) {
...
@@ -135,7 +135,7 @@ void *taosProcessSchedQueue(void *scheduler) {
break
;
break
;
}
}
if
((
ret
=
pthread_mutex_l
ock
(
&
pSched
->
queueMutex
))
!=
0
)
{
if
((
ret
=
taosThreadMutexL
ock
(
&
pSched
->
queueMutex
))
!=
0
)
{
uFatal
(
"lock %s queueMutex failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
uFatal
(
"lock %s queueMutex failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
exit
(
ret
);
exit
(
ret
);
}
}
...
@@ -144,7 +144,7 @@ void *taosProcessSchedQueue(void *scheduler) {
...
@@ -144,7 +144,7 @@ void *taosProcessSchedQueue(void *scheduler) {
memset
(
pSched
->
queue
+
pSched
->
fullSlot
,
0
,
sizeof
(
SSchedMsg
));
memset
(
pSched
->
queue
+
pSched
->
fullSlot
,
0
,
sizeof
(
SSchedMsg
));
pSched
->
fullSlot
=
(
pSched
->
fullSlot
+
1
)
%
pSched
->
queueSize
;
pSched
->
fullSlot
=
(
pSched
->
fullSlot
+
1
)
%
pSched
->
queueSize
;
if
((
ret
=
pthread_mutex_u
nlock
(
&
pSched
->
queueMutex
))
!=
0
)
{
if
((
ret
=
taosThreadMutexU
nlock
(
&
pSched
->
queueMutex
))
!=
0
)
{
uFatal
(
"unlock %s queueMutex failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
uFatal
(
"unlock %s queueMutex failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
exit
(
ret
);
exit
(
ret
);
}
}
...
@@ -177,7 +177,7 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) {
...
@@ -177,7 +177,7 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) {
exit
(
ret
);
exit
(
ret
);
}
}
if
((
ret
=
pthread_mutex_l
ock
(
&
pSched
->
queueMutex
))
!=
0
)
{
if
((
ret
=
taosThreadMutexL
ock
(
&
pSched
->
queueMutex
))
!=
0
)
{
uFatal
(
"lock %s queueMutex failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
uFatal
(
"lock %s queueMutex failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
exit
(
ret
);
exit
(
ret
);
}
}
...
@@ -185,7 +185,7 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) {
...
@@ -185,7 +185,7 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) {
pSched
->
queue
[
pSched
->
emptySlot
]
=
*
pMsg
;
pSched
->
queue
[
pSched
->
emptySlot
]
=
*
pMsg
;
pSched
->
emptySlot
=
(
pSched
->
emptySlot
+
1
)
%
pSched
->
queueSize
;
pSched
->
emptySlot
=
(
pSched
->
emptySlot
+
1
)
%
pSched
->
queueSize
;
if
((
ret
=
pthread_mutex_u
nlock
(
&
pSched
->
queueMutex
))
!=
0
)
{
if
((
ret
=
taosThreadMutexU
nlock
(
&
pSched
->
queueMutex
))
!=
0
)
{
uFatal
(
"unlock %s queueMutex failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
uFatal
(
"unlock %s queueMutex failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
exit
(
ret
);
exit
(
ret
);
}
}
...
@@ -208,13 +208,13 @@ void taosCleanUpScheduler(void *param) {
...
@@ -208,13 +208,13 @@ void taosCleanUpScheduler(void *param) {
}
}
for
(
int32_t
i
=
0
;
i
<
pSched
->
numOfThreads
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pSched
->
numOfThreads
;
++
i
)
{
if
(
taosCheckPthreadValid
(
pSched
->
qthread
[
i
]))
{
if
(
taosCheckPthreadValid
(
pSched
->
qthread
[
i
]))
{
pthread_j
oin
(
pSched
->
qthread
[
i
],
NULL
);
taosThreadJ
oin
(
pSched
->
qthread
[
i
],
NULL
);
}
}
}
}
tsem_destroy
(
&
pSched
->
emptySem
);
tsem_destroy
(
&
pSched
->
emptySem
);
tsem_destroy
(
&
pSched
->
fullSem
);
tsem_destroy
(
&
pSched
->
fullSem
);
pthread_mutex_d
estroy
(
&
pSched
->
queueMutex
);
taosThreadMutexD
estroy
(
&
pSched
->
queueMutex
);
if
(
pSched
->
pTimer
)
{
if
(
pSched
->
pTimer
)
{
taosTmrStopA
(
&
pSched
->
pTimer
);
taosTmrStopA
(
&
pSched
->
pTimer
);
...
...
source/util/src/tskiplist.c
浏览文件 @
3544df41
...
@@ -70,13 +70,13 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
...
@@ -70,13 +70,13 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
}
}
if
(
SL_IS_THREAD_SAFE
(
pSkipList
))
{
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
)
{
if
(
pSkipList
->
lock
==
NULL
)
{
tSkipListDestroy
(
pSkipList
);
tSkipListDestroy
(
pSkipList
);
return
NULL
;
return
NULL
;
}
}
if
(
pthread_rwlock_i
nit
(
pSkipList
->
lock
,
NULL
)
!=
0
)
{
if
(
taosThreadRwlockI
nit
(
pSkipList
->
lock
,
NULL
)
!=
0
)
{
tSkipListDestroy
(
pSkipList
);
tSkipListDestroy
(
pSkipList
);
return
NULL
;
return
NULL
;
}
}
...
@@ -109,7 +109,7 @@ void tSkipListDestroy(SSkipList *pSkipList) {
...
@@ -109,7 +109,7 @@ void tSkipListDestroy(SSkipList *pSkipList) {
tSkipListUnlock
(
pSkipList
);
tSkipListUnlock
(
pSkipList
);
if
(
pSkipList
->
lock
!=
NULL
)
{
if
(
pSkipList
->
lock
!=
NULL
)
{
pthread_rwlock_d
estroy
(
pSkipList
->
lock
);
taosThreadRwlockD
estroy
(
pSkipList
->
lock
);
tfree
(
pSkipList
->
lock
);
tfree
(
pSkipList
->
lock
);
}
}
...
@@ -435,21 +435,21 @@ static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t
...
@@ -435,21 +435,21 @@ static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t
static
FORCE_INLINE
int32_t
tSkipListWLock
(
SSkipList
*
pSkipList
)
{
static
FORCE_INLINE
int32_t
tSkipListWLock
(
SSkipList
*
pSkipList
)
{
if
(
pSkipList
->
lock
)
{
if
(
pSkipList
->
lock
)
{
return
pthread_rwlock_w
rlock
(
pSkipList
->
lock
);
return
taosThreadRwlockW
rlock
(
pSkipList
->
lock
);
}
}
return
0
;
return
0
;
}
}
static
FORCE_INLINE
int32_t
tSkipListRLock
(
SSkipList
*
pSkipList
)
{
static
FORCE_INLINE
int32_t
tSkipListRLock
(
SSkipList
*
pSkipList
)
{
if
(
pSkipList
->
lock
)
{
if
(
pSkipList
->
lock
)
{
return
pthread_rwlock_r
dlock
(
pSkipList
->
lock
);
return
taosThreadRwlockR
dlock
(
pSkipList
->
lock
);
}
}
return
0
;
return
0
;
}
}
static
FORCE_INLINE
int32_t
tSkipListUnlock
(
SSkipList
*
pSkipList
)
{
static
FORCE_INLINE
int32_t
tSkipListUnlock
(
SSkipList
*
pSkipList
)
{
if
(
pSkipList
->
lock
)
{
if
(
pSkipList
->
lock
)
{
return
pthread_rwlock_u
nlock
(
pSkipList
->
lock
);
return
taosThreadRwlockU
nlock
(
pSkipList
->
lock
);
}
}
return
0
;
return
0
;
}
}
...
...
source/util/src/tthread.c
浏览文件 @
3544df41
...
@@ -16,13 +16,13 @@
...
@@ -16,13 +16,13 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "tthread.h"
#include "tthread.h"
pthread_t
*
taosCreateThread
(
void
*
(
*
__start_routine
)(
void
*
),
void
*
param
)
{
TdThread
*
taosCreateThread
(
void
*
(
*
__start_routine
)(
void
*
),
void
*
param
)
{
pthread_t
*
pthread
=
(
pthread_t
*
)
malloc
(
sizeof
(
pthread_t
));
TdThread
*
pthread
=
(
TdThread
*
)
malloc
(
sizeof
(
TdThread
));
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
int32_t
ret
=
pthread_c
reate
(
pthread
,
&
thattr
,
__start_routine
,
param
);
int32_t
ret
=
taosThreadC
reate
(
pthread
,
&
thattr
,
__start_routine
,
param
);
pthread_attr_d
estroy
(
&
thattr
);
taosThreadAttrD
estroy
(
&
thattr
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
free
(
pthread
);
free
(
pthread
);
...
@@ -31,20 +31,20 @@ pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param) {
...
@@ -31,20 +31,20 @@ pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param) {
return
pthread
;
return
pthread
;
}
}
bool
taosDestoryThread
(
pthread_t
*
pthread
)
{
bool
taosDestoryThread
(
TdThread
*
pthread
)
{
if
(
pthread
==
NULL
)
return
false
;
if
(
pthread
==
NULL
)
return
false
;
if
(
taosThreadRunning
(
pthread
))
{
if
(
taosThreadRunning
(
pthread
))
{
pthread_c
ancel
(
*
pthread
);
taosThreadC
ancel
(
*
pthread
);
pthread_j
oin
(
*
pthread
,
NULL
);
taosThreadJ
oin
(
*
pthread
,
NULL
);
}
}
free
(
pthread
);
free
(
pthread
);
return
true
;
return
true
;
}
}
bool
taosThreadRunning
(
pthread_t
*
pthread
)
{
bool
taosThreadRunning
(
TdThread
*
pthread
)
{
if
(
pthread
==
NULL
)
return
false
;
if
(
pthread
==
NULL
)
return
false
;
int32_t
ret
=
pthread_k
ill
(
*
pthread
,
0
);
int32_t
ret
=
taosThreadK
ill
(
*
pthread
,
0
);
if
(
ret
==
ESRCH
)
return
false
;
if
(
ret
==
ESRCH
)
return
false
;
if
(
ret
==
EINVAL
)
return
false
;
if
(
ret
==
EINVAL
)
return
false
;
// alive
// alive
...
...
source/util/src/ttimer.c
浏览文件 @
3544df41
...
@@ -102,7 +102,7 @@ typedef struct timer_map_t {
...
@@ -102,7 +102,7 @@ typedef struct timer_map_t {
}
timer_map_t
;
}
timer_map_t
;
typedef
struct
time_wheel_t
{
typedef
struct
time_wheel_t
{
pthread_mutex_t
mutex
;
TdThreadMutex
mutex
;
int64_t
nextScanAt
;
int64_t
nextScanAt
;
uint32_t
resolution
;
uint32_t
resolution
;
uint16_t
size
;
uint16_t
size
;
...
@@ -112,8 +112,8 @@ typedef struct time_wheel_t {
...
@@ -112,8 +112,8 @@ typedef struct time_wheel_t {
int32_t
tsMaxTmrCtrl
=
512
;
int32_t
tsMaxTmrCtrl
=
512
;
static
pthread_once_t
tmrModuleInit
=
PTHREAD_ONCE_INIT
;
static
TdThreadOnce
tmrModuleInit
=
PTHREAD_ONCE_INIT
;
static
pthread_mutex_t
tmrCtrlMutex
;
static
TdThreadMutex
tmrCtrlMutex
;
static
tmr_ctrl_t
*
tmrCtrls
;
static
tmr_ctrl_t
*
tmrCtrls
;
static
tmr_ctrl_t
*
unusedTmrCtrl
=
NULL
;
static
tmr_ctrl_t
*
unusedTmrCtrl
=
NULL
;
static
void
*
tmrQhandle
;
static
void
*
tmrQhandle
;
...
@@ -230,7 +230,7 @@ static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
...
@@ -230,7 +230,7 @@ static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
timer
->
prev
=
NULL
;
timer
->
prev
=
NULL
;
timer
->
expireAt
=
taosGetMonotonicMs
()
+
delay
;
timer
->
expireAt
=
taosGetMonotonicMs
()
+
delay
;
pthread_mutex_l
ock
(
&
wheel
->
mutex
);
taosThreadMutexL
ock
(
&
wheel
->
mutex
);
uint32_t
idx
=
0
;
uint32_t
idx
=
0
;
if
(
timer
->
expireAt
>
wheel
->
nextScanAt
)
{
if
(
timer
->
expireAt
>
wheel
->
nextScanAt
)
{
...
@@ -248,7 +248,7 @@ static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
...
@@ -248,7 +248,7 @@ static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
p
->
prev
=
timer
;
p
->
prev
=
timer
;
}
}
pthread_mutex_u
nlock
(
&
wheel
->
mutex
);
taosThreadMutexU
nlock
(
&
wheel
->
mutex
);
}
}
static
bool
removeFromWheel
(
tmr_obj_t
*
timer
)
{
static
bool
removeFromWheel
(
tmr_obj_t
*
timer
)
{
...
@@ -259,7 +259,7 @@ static bool removeFromWheel(tmr_obj_t* timer) {
...
@@ -259,7 +259,7 @@ static bool removeFromWheel(tmr_obj_t* timer) {
time_wheel_t
*
wheel
=
wheels
+
wheelIdx
;
time_wheel_t
*
wheel
=
wheels
+
wheelIdx
;
bool
removed
=
false
;
bool
removed
=
false
;
pthread_mutex_l
ock
(
&
wheel
->
mutex
);
taosThreadMutexL
ock
(
&
wheel
->
mutex
);
// other thread may modify timer->wheel, check again.
// other thread may modify timer->wheel, check again.
if
(
timer
->
wheel
<
tListLen
(
wheels
))
{
if
(
timer
->
wheel
<
tListLen
(
wheels
))
{
if
(
timer
->
prev
!=
NULL
)
{
if
(
timer
->
prev
!=
NULL
)
{
...
@@ -277,7 +277,7 @@ static bool removeFromWheel(tmr_obj_t* timer) {
...
@@ -277,7 +277,7 @@ static bool removeFromWheel(tmr_obj_t* timer) {
timerDecRef
(
timer
);
timerDecRef
(
timer
);
removed
=
true
;
removed
=
true
;
}
}
pthread_mutex_u
nlock
(
&
wheel
->
mutex
);
taosThreadMutexU
nlock
(
&
wheel
->
mutex
);
return
removed
;
return
removed
;
}
}
...
@@ -372,7 +372,7 @@ static void taosTimerLoopFunc(int32_t signo) {
...
@@ -372,7 +372,7 @@ static void taosTimerLoopFunc(int32_t signo) {
time_wheel_t
*
wheel
=
wheels
+
i
;
time_wheel_t
*
wheel
=
wheels
+
i
;
while
(
now
>=
wheel
->
nextScanAt
)
{
while
(
now
>=
wheel
->
nextScanAt
)
{
pthread_mutex_l
ock
(
&
wheel
->
mutex
);
taosThreadMutexL
ock
(
&
wheel
->
mutex
);
wheel
->
index
=
(
wheel
->
index
+
1
)
%
wheel
->
size
;
wheel
->
index
=
(
wheel
->
index
+
1
)
%
wheel
->
size
;
tmr_obj_t
*
timer
=
wheel
->
slots
[
wheel
->
index
];
tmr_obj_t
*
timer
=
wheel
->
slots
[
wheel
->
index
];
while
(
timer
!=
NULL
)
{
while
(
timer
!=
NULL
)
{
...
@@ -407,7 +407,7 @@ static void taosTimerLoopFunc(int32_t signo) {
...
@@ -407,7 +407,7 @@ static void taosTimerLoopFunc(int32_t signo) {
timer
=
next
;
timer
=
next
;
}
}
wheel
->
nextScanAt
+=
wheel
->
resolution
;
wheel
->
nextScanAt
+=
wheel
->
resolution
;
pthread_mutex_u
nlock
(
&
wheel
->
mutex
);
taosThreadMutexU
nlock
(
&
wheel
->
mutex
);
}
}
addToExpired
(
expired
);
addToExpired
(
expired
);
...
@@ -528,12 +528,12 @@ static void taosTmrModuleInit(void) {
...
@@ -528,12 +528,12 @@ static void taosTmrModuleInit(void) {
(
tmrCtrls
+
tsMaxTmrCtrl
-
1
)
->
next
=
NULL
;
(
tmrCtrls
+
tsMaxTmrCtrl
-
1
)
->
next
=
NULL
;
unusedTmrCtrl
=
tmrCtrls
;
unusedTmrCtrl
=
tmrCtrls
;
pthread_mutex_i
nit
(
&
tmrCtrlMutex
,
NULL
);
taosThreadMutexI
nit
(
&
tmrCtrlMutex
,
NULL
);
int64_t
now
=
taosGetMonotonicMs
();
int64_t
now
=
taosGetMonotonicMs
();
for
(
int32_t
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
time_wheel_t
*
wheel
=
wheels
+
i
;
time_wheel_t
*
wheel
=
wheels
+
i
;
if
(
pthread_mutex_i
nit
(
&
wheel
->
mutex
,
NULL
)
!=
0
)
{
if
(
taosThreadMutexI
nit
(
&
wheel
->
mutex
,
NULL
)
!=
0
)
{
tmrError
(
"failed to create the mutex for wheel, reason:%s"
,
strerror
(
errno
));
tmrError
(
"failed to create the mutex for wheel, reason:%s"
,
strerror
(
errno
));
return
;
return
;
}
}
...
@@ -564,15 +564,15 @@ void* taosTmrInit(int32_t maxNumOfTmrs, int32_t resolution, int32_t longest, con
...
@@ -564,15 +564,15 @@ void* taosTmrInit(int32_t maxNumOfTmrs, int32_t resolution, int32_t longest, con
const
char
*
ret
=
taosMonotonicInit
();
const
char
*
ret
=
taosMonotonicInit
();
tmrDebug
(
"ttimer monotonic clock source:%s"
,
ret
);
tmrDebug
(
"ttimer monotonic clock source:%s"
,
ret
);
pthread_o
nce
(
&
tmrModuleInit
,
taosTmrModuleInit
);
taosThreadO
nce
(
&
tmrModuleInit
,
taosTmrModuleInit
);
pthread_mutex_l
ock
(
&
tmrCtrlMutex
);
taosThreadMutexL
ock
(
&
tmrCtrlMutex
);
tmr_ctrl_t
*
ctrl
=
unusedTmrCtrl
;
tmr_ctrl_t
*
ctrl
=
unusedTmrCtrl
;
if
(
ctrl
!=
NULL
)
{
if
(
ctrl
!=
NULL
)
{
unusedTmrCtrl
=
ctrl
->
next
;
unusedTmrCtrl
=
ctrl
->
next
;
numOfTmrCtrl
++
;
numOfTmrCtrl
++
;
}
}
pthread_mutex_u
nlock
(
&
tmrCtrlMutex
);
taosThreadMutexU
nlock
(
&
tmrCtrlMutex
);
if
(
ctrl
==
NULL
)
{
if
(
ctrl
==
NULL
)
{
tmrError
(
"%s too many timer controllers, failed to create timer controller."
,
label
);
tmrError
(
"%s too many timer controllers, failed to create timer controller."
,
label
);
...
@@ -594,11 +594,11 @@ void taosTmrCleanUp(void* handle) {
...
@@ -594,11 +594,11 @@ void taosTmrCleanUp(void* handle) {
tmrDebug
(
"%s timer controller is cleaned up."
,
ctrl
->
label
);
tmrDebug
(
"%s timer controller is cleaned up."
,
ctrl
->
label
);
ctrl
->
label
[
0
]
=
0
;
ctrl
->
label
[
0
]
=
0
;
pthread_mutex_l
ock
(
&
tmrCtrlMutex
);
taosThreadMutexL
ock
(
&
tmrCtrlMutex
);
ctrl
->
next
=
unusedTmrCtrl
;
ctrl
->
next
=
unusedTmrCtrl
;
numOfTmrCtrl
--
;
numOfTmrCtrl
--
;
unusedTmrCtrl
=
ctrl
;
unusedTmrCtrl
=
ctrl
;
pthread_mutex_u
nlock
(
&
tmrCtrlMutex
);
taosThreadMutexU
nlock
(
&
tmrCtrlMutex
);
tmrDebug
(
"time controller's tmr ctrl size: %d"
,
numOfTmrCtrl
);
tmrDebug
(
"time controller's tmr ctrl size: %d"
,
numOfTmrCtrl
);
if
(
numOfTmrCtrl
<=
0
)
{
if
(
numOfTmrCtrl
<=
0
)
{
...
@@ -608,11 +608,11 @@ void taosTmrCleanUp(void* handle) {
...
@@ -608,11 +608,11 @@ void taosTmrCleanUp(void* handle) {
for
(
int32_t
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
time_wheel_t
*
wheel
=
wheels
+
i
;
time_wheel_t
*
wheel
=
wheels
+
i
;
pthread_mutex_d
estroy
(
&
wheel
->
mutex
);
taosThreadMutexD
estroy
(
&
wheel
->
mutex
);
free
(
wheel
->
slots
);
free
(
wheel
->
slots
);
}
}
pthread_mutex_d
estroy
(
&
tmrCtrlMutex
);
taosThreadMutexD
estroy
(
&
tmrCtrlMutex
);
for
(
size_t
i
=
0
;
i
<
timerMap
.
size
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
timerMap
.
size
;
i
++
)
{
timer_list_t
*
list
=
timerMap
.
slots
+
i
;
timer_list_t
*
list
=
timerMap
.
slots
+
i
;
...
...
source/util/src/tworker.c
浏览文件 @
3544df41
...
@@ -28,7 +28,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) {
...
@@ -28,7 +28,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) {
return
-
1
;
return
-
1
;
}
}
if
(
pthread_mutex_i
nit
(
&
pool
->
mutex
,
NULL
))
{
if
(
taosThreadMutexI
nit
(
&
pool
->
mutex
,
NULL
))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
...
@@ -56,13 +56,13 @@ void tQWorkerCleanup(SQWorkerPool *pool) {
...
@@ -56,13 +56,13 @@ void tQWorkerCleanup(SQWorkerPool *pool) {
SQWorker
*
worker
=
pool
->
workers
+
i
;
SQWorker
*
worker
=
pool
->
workers
+
i
;
if
(
worker
==
NULL
)
continue
;
if
(
worker
==
NULL
)
continue
;
if
(
taosCheckPthreadValid
(
worker
->
thread
))
{
if
(
taosCheckPthreadValid
(
worker
->
thread
))
{
pthread_j
oin
(
worker
->
thread
,
NULL
);
taosThreadJ
oin
(
worker
->
thread
,
NULL
);
}
}
}
}
tfree
(
pool
->
workers
);
tfree
(
pool
->
workers
);
taosCloseQset
(
pool
->
qset
);
taosCloseQset
(
pool
->
qset
);
pthread_mutex_d
estroy
(
&
pool
->
mutex
);
taosThreadMutexD
estroy
(
&
pool
->
mutex
);
uDebug
(
"worker:%s is closed"
,
pool
->
name
);
uDebug
(
"worker:%s is closed"
,
pool
->
name
);
}
}
...
@@ -94,10 +94,10 @@ static void *tQWorkerThreadFp(SQWorker *worker) {
...
@@ -94,10 +94,10 @@ static void *tQWorkerThreadFp(SQWorker *worker) {
}
}
STaosQueue
*
tWorkerAllocQueue
(
SQWorkerPool
*
pool
,
void
*
ahandle
,
FItem
fp
,
ThreadFp
threadFp
)
{
STaosQueue
*
tWorkerAllocQueue
(
SQWorkerPool
*
pool
,
void
*
ahandle
,
FItem
fp
,
ThreadFp
threadFp
)
{
pthread_mutex_l
ock
(
&
pool
->
mutex
);
taosThreadMutexL
ock
(
&
pool
->
mutex
);
STaosQueue
*
queue
=
taosOpenQueue
();
STaosQueue
*
queue
=
taosOpenQueue
();
if
(
queue
==
NULL
)
{
if
(
queue
==
NULL
)
{
pthread_mutex_u
nlock
(
&
pool
->
mutex
);
taosThreadMutexU
nlock
(
&
pool
->
mutex
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
}
}
...
@@ -110,11 +110,11 @@ STaosQueue *tWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp, Threa
...
@@ -110,11 +110,11 @@ STaosQueue *tWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp, Threa
do
{
do
{
SQWorker
*
worker
=
pool
->
workers
+
pool
->
num
;
SQWorker
*
worker
=
pool
->
workers
+
pool
->
num
;
pthread_attr_t
thAttr
;
TdThreadAttr
thAttr
;
pthread_attr_i
nit
(
&
thAttr
);
taosThreadAttrI
nit
(
&
thAttr
);
pthread_attr_setdetachs
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_c
reate
(
&
worker
->
thread
,
&
thAttr
,
threadFp
,
worker
)
!=
0
)
{
if
(
taosThreadC
reate
(
&
worker
->
thread
,
&
thAttr
,
threadFp
,
worker
)
!=
0
)
{
uError
(
"worker:%s:%d failed to create thread to process since %s"
,
pool
->
name
,
worker
->
id
,
strerror
(
errno
));
uError
(
"worker:%s:%d failed to create thread to process since %s"
,
pool
->
name
,
worker
->
id
,
strerror
(
errno
));
taosCloseQueue
(
queue
);
taosCloseQueue
(
queue
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
@@ -122,13 +122,13 @@ STaosQueue *tWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp, Threa
...
@@ -122,13 +122,13 @@ STaosQueue *tWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp, Threa
break
;
break
;
}
}
pthread_attr_d
estroy
(
&
thAttr
);
taosThreadAttrD
estroy
(
&
thAttr
);
pool
->
num
++
;
pool
->
num
++
;
uDebug
(
"worker:%s:%d is launched, total:%d"
,
pool
->
name
,
worker
->
id
,
pool
->
num
);
uDebug
(
"worker:%s:%d is launched, total:%d"
,
pool
->
name
,
worker
->
id
,
pool
->
num
);
}
while
(
pool
->
num
<
pool
->
min
);
}
while
(
pool
->
num
<
pool
->
min
);
}
}
pthread_mutex_u
nlock
(
&
pool
->
mutex
);
taosThreadMutexU
nlock
(
&
pool
->
mutex
);
uDebug
(
"worker:%s, queue:%p is allocated, ahandle:%p"
,
pool
->
name
,
queue
,
ahandle
);
uDebug
(
"worker:%s, queue:%p is allocated, ahandle:%p"
,
pool
->
name
,
queue
,
ahandle
);
return
queue
;
return
queue
;
...
@@ -194,7 +194,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) {
...
@@ -194,7 +194,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) {
return
-
1
;
return
-
1
;
}
}
if
(
pthread_mutex_i
nit
(
&
pool
->
mutex
,
NULL
)
!=
0
)
{
if
(
taosThreadMutexI
nit
(
&
pool
->
mutex
,
NULL
)
!=
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
...
@@ -224,14 +224,14 @@ void tWWorkerCleanup(SWWorkerPool *pool) {
...
@@ -224,14 +224,14 @@ void tWWorkerCleanup(SWWorkerPool *pool) {
for
(
int32_t
i
=
0
;
i
<
pool
->
max
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pool
->
max
;
++
i
)
{
SWWorker
*
worker
=
pool
->
workers
+
i
;
SWWorker
*
worker
=
pool
->
workers
+
i
;
if
(
taosCheckPthreadValid
(
worker
->
thread
))
{
if
(
taosCheckPthreadValid
(
worker
->
thread
))
{
pthread_j
oin
(
worker
->
thread
,
NULL
);
taosThreadJ
oin
(
worker
->
thread
,
NULL
);
taosFreeQall
(
worker
->
qall
);
taosFreeQall
(
worker
->
qall
);
taosCloseQset
(
worker
->
qset
);
taosCloseQset
(
worker
->
qset
);
}
}
}
}
tfree
(
pool
->
workers
);
tfree
(
pool
->
workers
);
pthread_mutex_d
estroy
(
&
pool
->
mutex
);
taosThreadMutexD
estroy
(
&
pool
->
mutex
);
uInfo
(
"worker:%s is closed"
,
pool
->
name
);
uInfo
(
"worker:%s is closed"
,
pool
->
name
);
}
}
...
@@ -265,12 +265,12 @@ static void *tWWorkerThreadFp(SWWorker *worker) {
...
@@ -265,12 +265,12 @@ static void *tWWorkerThreadFp(SWWorker *worker) {
}
}
STaosQueue
*
tWWorkerAllocQueue
(
SWWorkerPool
*
pool
,
void
*
ahandle
,
FItems
fp
)
{
STaosQueue
*
tWWorkerAllocQueue
(
SWWorkerPool
*
pool
,
void
*
ahandle
,
FItems
fp
)
{
pthread_mutex_l
ock
(
&
pool
->
mutex
);
taosThreadMutexL
ock
(
&
pool
->
mutex
);
SWWorker
*
worker
=
pool
->
workers
+
pool
->
nextId
;
SWWorker
*
worker
=
pool
->
workers
+
pool
->
nextId
;
STaosQueue
*
queue
=
taosOpenQueue
();
STaosQueue
*
queue
=
taosOpenQueue
();
if
(
queue
==
NULL
)
{
if
(
queue
==
NULL
)
{
pthread_mutex_u
nlock
(
&
pool
->
mutex
);
taosThreadMutexU
nlock
(
&
pool
->
mutex
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
}
}
...
@@ -281,7 +281,7 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
...
@@ -281,7 +281,7 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
worker
->
qset
=
taosOpenQset
();
worker
->
qset
=
taosOpenQset
();
if
(
worker
->
qset
==
NULL
)
{
if
(
worker
->
qset
==
NULL
)
{
taosCloseQueue
(
queue
);
taosCloseQueue
(
queue
);
pthread_mutex_u
nlock
(
&
pool
->
mutex
);
taosThreadMutexU
nlock
(
&
pool
->
mutex
);
return
NULL
;
return
NULL
;
}
}
...
@@ -290,15 +290,15 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
...
@@ -290,15 +290,15 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
if
(
worker
->
qall
==
NULL
)
{
if
(
worker
->
qall
==
NULL
)
{
taosCloseQset
(
worker
->
qset
);
taosCloseQset
(
worker
->
qset
);
taosCloseQueue
(
queue
);
taosCloseQueue
(
queue
);
pthread_mutex_u
nlock
(
&
pool
->
mutex
);
taosThreadMutexU
nlock
(
&
pool
->
mutex
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
}
}
pthread_attr_t
thAttr
;
TdThreadAttr
thAttr
;
pthread_attr_i
nit
(
&
thAttr
);
taosThreadAttrI
nit
(
&
thAttr
);
pthread_attr_setdetachs
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_c
reate
(
&
worker
->
thread
,
&
thAttr
,
(
ThreadFp
)
tWWorkerThreadFp
,
worker
)
!=
0
)
{
if
(
taosThreadC
reate
(
&
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
));
uError
(
"worker:%s:%d failed to create thread to process since %s"
,
pool
->
name
,
worker
->
id
,
strerror
(
errno
));
taosFreeQall
(
worker
->
qall
);
taosFreeQall
(
worker
->
qall
);
taosCloseQset
(
worker
->
qset
);
taosCloseQset
(
worker
->
qset
);
...
@@ -310,13 +310,13 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
...
@@ -310,13 +310,13 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
pool
->
nextId
=
(
pool
->
nextId
+
1
)
%
pool
->
max
;
pool
->
nextId
=
(
pool
->
nextId
+
1
)
%
pool
->
max
;
}
}
pthread_attr_d
estroy
(
&
thAttr
);
taosThreadAttrD
estroy
(
&
thAttr
);
}
else
{
}
else
{
taosAddIntoQset
(
worker
->
qset
,
queue
,
ahandle
);
taosAddIntoQset
(
worker
->
qset
,
queue
,
ahandle
);
pool
->
nextId
=
(
pool
->
nextId
+
1
)
%
pool
->
max
;
pool
->
nextId
=
(
pool
->
nextId
+
1
)
%
pool
->
max
;
}
}
pthread_mutex_u
nlock
(
&
pool
->
mutex
);
taosThreadMutexU
nlock
(
&
pool
->
mutex
);
uDebug
(
"worker:%s, queue:%p is allocated, ahandle:%p"
,
pool
->
name
,
queue
,
ahandle
);
uDebug
(
"worker:%s, queue:%p is allocated, ahandle:%p"
,
pool
->
name
,
queue
,
ahandle
);
return
queue
;
return
queue
;
...
...
source/util/test/trefTest.c
浏览文件 @
3544df41
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include "os.h"
#include "os.h"
...
@@ -102,18 +101,18 @@ void *openRefSpace(void *param) {
...
@@ -102,18 +101,18 @@ void *openRefSpace(void *param) {
pSpace
->
p
=
(
void
**
)
calloc
(
sizeof
(
void
*
),
pSpace
->
refNum
);
pSpace
->
p
=
(
void
**
)
calloc
(
sizeof
(
void
*
),
pSpace
->
refNum
);
pSpace
->
rid
=
calloc
(
pSpace
->
refNum
,
sizeof
(
int64_t
));
pSpace
->
rid
=
calloc
(
pSpace
->
refNum
,
sizeof
(
int64_t
));
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
pthread_t
thread1
,
thread2
,
thread3
;
TdThread
thread1
,
thread2
,
thread3
;
pthread_c
reate
(
&
(
thread1
),
&
thattr
,
addRef
,
(
void
*
)(
pSpace
));
taosThreadC
reate
(
&
(
thread1
),
&
thattr
,
addRef
,
(
void
*
)(
pSpace
));
pthread_c
reate
(
&
(
thread2
),
&
thattr
,
removeRef
,
(
void
*
)(
pSpace
));
taosThreadC
reate
(
&
(
thread2
),
&
thattr
,
removeRef
,
(
void
*
)(
pSpace
));
pthread_c
reate
(
&
(
thread3
),
&
thattr
,
acquireRelease
,
(
void
*
)(
pSpace
));
taosThreadC
reate
(
&
(
thread3
),
&
thattr
,
acquireRelease
,
(
void
*
)(
pSpace
));
pthread_j
oin
(
thread1
,
NULL
);
taosThreadJ
oin
(
thread1
,
NULL
);
pthread_j
oin
(
thread2
,
NULL
);
taosThreadJ
oin
(
thread2
,
NULL
);
pthread_j
oin
(
thread3
,
NULL
);
taosThreadJ
oin
(
thread3
,
NULL
);
for
(
int
i
=
0
;
i
<
pSpace
->
refNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pSpace
->
refNum
;
++
i
)
{
taosRemoveRef
(
pSpace
->
rsetId
,
pSpace
->
rid
[
i
]);
taosRemoveRef
(
pSpace
->
rsetId
,
pSpace
->
rid
[
i
]);
...
@@ -161,22 +160,22 @@ int main(int argc, char *argv[]) {
...
@@ -161,22 +160,22 @@ int main(int argc, char *argv[]) {
taosInitLog
(
"tref.log"
,
10
);
taosInitLog
(
"tref.log"
,
10
);
SRefSpace
*
pSpaceList
=
(
SRefSpace
*
)
calloc
(
sizeof
(
SRefSpace
),
threads
);
SRefSpace
*
pSpaceList
=
(
SRefSpace
*
)
calloc
(
sizeof
(
SRefSpace
),
threads
);
pthread_t
*
pThreadList
=
(
pthread_t
*
)
calloc
(
sizeof
(
pthread_t
),
threads
);
TdThread
*
pThreadList
=
(
TdThread
*
)
calloc
(
sizeof
(
TdThread
),
threads
);
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
for
(
int
i
=
0
;
i
<
loops
;
++
i
)
{
for
(
int
i
=
0
;
i
<
loops
;
++
i
)
{
printf
(
"
\n
loop: %d
\n
"
,
i
);
printf
(
"
\n
loop: %d
\n
"
,
i
);
for
(
int
j
=
0
;
j
<
threads
;
++
j
)
{
for
(
int
j
=
0
;
j
<
threads
;
++
j
)
{
pSpaceList
[
j
].
steps
=
steps
;
pSpaceList
[
j
].
steps
=
steps
;
pSpaceList
[
j
].
refNum
=
refNum
;
pSpaceList
[
j
].
refNum
=
refNum
;
pthread_c
reate
(
&
(
pThreadList
[
j
]),
&
thattr
,
openRefSpace
,
(
void
*
)(
pSpaceList
+
j
));
taosThreadC
reate
(
&
(
pThreadList
[
j
]),
&
thattr
,
openRefSpace
,
(
void
*
)(
pSpaceList
+
j
));
}
}
for
(
int
j
=
0
;
j
<
threads
;
++
j
)
{
for
(
int
j
=
0
;
j
<
threads
;
++
j
)
{
pthread_j
oin
(
pThreadList
[
j
],
NULL
);
taosThreadJ
oin
(
pThreadList
[
j
],
NULL
);
}
}
}
}
...
...
tests/script/api/batchprepare.c
浏览文件 @
3544df41
// TAOS standard API example. The same syntax as MySQL, but only a subet
// TAOS standard API example. The same syntax as MySQL, but only a subet
// to compile: gcc -o prepare prepare.c -ltaos
// to compile: gcc -o prepare prepare.c -ltaos
#include <pthread.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
@@ -5067,11 +5066,11 @@ int main(int argc, char *argv[])
...
@@ -5067,11 +5066,11 @@ int main(int argc, char *argv[])
exit
(
1
);
exit
(
1
);
}
}
pthread_t
*
pThreadList
=
(
pthread_t
*
)
calloc
(
sizeof
(
pthread_t
),
4
);
TdThread
*
pThreadList
=
(
TdThread
*
)
calloc
(
sizeof
(
TdThread
),
4
);
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
T_par
par
[
4
];
T_par
par
[
4
];
par
[
0
].
taos
=
taos
[
0
];
par
[
0
].
taos
=
taos
[
0
];
...
@@ -5083,10 +5082,10 @@ int main(int argc, char *argv[])
...
@@ -5083,10 +5082,10 @@ int main(int argc, char *argv[])
par
[
3
].
taos
=
taos
[
3
];
par
[
3
].
taos
=
taos
[
3
];
par
[
3
].
idx
=
3
;
par
[
3
].
idx
=
3
;
pthread_c
reate
(
&
(
pThreadList
[
0
]),
&
thattr
,
runcase
,
(
void
*
)
&
par
[
0
]);
taosThreadC
reate
(
&
(
pThreadList
[
0
]),
&
thattr
,
runcase
,
(
void
*
)
&
par
[
0
]);
//
pthread_c
reate(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]);
//
taosThreadC
reate(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]);
//
pthread_c
reate(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]);
//
taosThreadC
reate(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]);
//
pthread_c
reate(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
//
taosThreadC
reate(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
while
(
1
)
{
while
(
1
)
{
taosSsleep
(
1
);
taosSsleep
(
1
);
...
...
tests/script/api/stmtBatchTest.c
浏览文件 @
3544df41
// TAOS standard API example. The same syntax as MySQL, but only a subet
// TAOS standard API example. The same syntax as MySQL, but only a subet
// to compile: gcc -o prepare prepare.c -ltaos
// to compile: gcc -o prepare prepare.c -ltaos
#include <pthread.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
@@ -5080,7 +5079,7 @@ int main(int argc, char *argv[])
...
@@ -5080,7 +5079,7 @@ int main(int argc, char *argv[])
#if 0
#if 0
printf("server:%s, threadNum:%d, rows:%d\n\n", serverIp, threadNum, g_rows);
printf("server:%s, threadNum:%d, rows:%d\n\n", serverIp, threadNum, g_rows);
pthread_t *pThreadList = (pthread_t *) calloc(sizeof(pthread_t
), (size_t)threadNum);
TdThread *pThreadList = (TdThread *) calloc(sizeof(TdThread
), (size_t)threadNum);
ThreadInfo* threadInfo = (ThreadInfo *) calloc(sizeof(ThreadInfo), (size_t)threadNum);
ThreadInfo* threadInfo = (ThreadInfo *) calloc(sizeof(ThreadInfo), (size_t)threadNum);
ThreadInfo* tInfo = threadInfo;
ThreadInfo* tInfo = threadInfo;
...
@@ -5094,16 +5093,16 @@ int main(int argc, char *argv[])
...
@@ -5094,16 +5093,16 @@ int main(int argc, char *argv[])
tInfo->taos = taos;
tInfo->taos = taos;
tInfo->idx = i;
tInfo->idx = i;
if (0 == i) {
if (0 == i) {
//
pthread_c
reate(&(pThreadList[0]), NULL, runCase, (void *)tInfo);
//
taosThreadC
reate(&(pThreadList[0]), NULL, runCase, (void *)tInfo);
pthread_c
reate(&(pThreadList[0]), NULL, SpecifyColumnBatchCase, (void *)tInfo);
taosThreadC
reate(&(pThreadList[0]), NULL, SpecifyColumnBatchCase, (void *)tInfo);
} else if (1 == i){
} else if (1 == i){
pthread_c
reate(&(pThreadList[0]), NULL, runCase_long, (void *)tInfo);
taosThreadC
reate(&(pThreadList[0]), NULL, runCase_long, (void *)tInfo);
}
}
tInfo++;
tInfo++;
}
}
for (int i = 0; i < threadNum; i++) {
for (int i = 0; i < threadNum; i++) {
pthread_j
oin(pThreadList[i], NULL);
taosThreadJ
oin(pThreadList[i], NULL);
}
}
free(pThreadList);
free(pThreadList);
...
...
tests/script/api/stmtTest.c
浏览文件 @
3544df41
#include <pthread.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
...
tests/script/api/stmt_function.c
浏览文件 @
3544df41
#include <assert.h>
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
...
tests/script/http/httpTest.c
浏览文件 @
3544df41
...
@@ -5,12 +5,11 @@
...
@@ -5,12 +5,11 @@
#include <unistd.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <stdlib.h>
#include <pthread.h>
#define MAXLINE 1024
#define MAXLINE 1024
typedef
struct
{
typedef
struct
{
pthread_t
pid
;
TdThread
pid
;
int
threadId
;
int
threadId
;
int
rows
;
int
rows
;
int
tables
;
int
tables
;
...
@@ -107,16 +106,16 @@ void multiThread() {
...
@@ -107,16 +106,16 @@ void multiThread() {
ThreadObj
*
threads
=
calloc
((
size_t
)
numOfThreads
,
sizeof
(
ThreadObj
));
ThreadObj
*
threads
=
calloc
((
size_t
)
numOfThreads
,
sizeof
(
ThreadObj
));
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
ThreadObj
*
pthread
=
threads
+
i
;
ThreadObj
*
pthread
=
threads
+
i
;
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread
->
threadId
=
i
+
1
;
pthread
->
threadId
=
i
+
1
;
pthread
->
rows
=
numOfRows
;
pthread
->
rows
=
numOfRows
;
pthread
->
tables
=
numOfTables
;
pthread
->
tables
=
numOfTables
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
pthread_c
reate
(
&
pthread
->
pid
,
&
thattr
,
(
void
*
(
*
)(
void
*
))
execute
,
pthread
);
taosThreadC
reate
(
&
pthread
->
pid
,
&
thattr
,
(
void
*
(
*
)(
void
*
))
execute
,
pthread
);
}
}
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
pthread_j
oin
(
threads
[
i
].
pid
,
NULL
);
taosThreadJ
oin
(
threads
[
i
].
pid
,
NULL
);
}
}
free
(
threads
);
free
(
threads
);
}
}
...
...
tests/script/http/httpTestSqlUtc.c
浏览文件 @
3544df41
...
@@ -5,12 +5,11 @@
...
@@ -5,12 +5,11 @@
#include <unistd.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <stdlib.h>
#include <pthread.h>
#define MAXLINE 1024
#define MAXLINE 1024
typedef
struct
{
typedef
struct
{
pthread_t
pid
;
TdThread
pid
;
int
threadId
;
int
threadId
;
int
rows
;
int
rows
;
int
tables
;
int
tables
;
...
@@ -107,16 +106,16 @@ void multiThread() {
...
@@ -107,16 +106,16 @@ void multiThread() {
ThreadObj
*
threads
=
calloc
((
size_t
)
numOfThreads
,
sizeof
(
ThreadObj
));
ThreadObj
*
threads
=
calloc
((
size_t
)
numOfThreads
,
sizeof
(
ThreadObj
));
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
ThreadObj
*
pthread
=
threads
+
i
;
ThreadObj
*
pthread
=
threads
+
i
;
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread
->
threadId
=
i
+
1
;
pthread
->
threadId
=
i
+
1
;
pthread
->
rows
=
numOfRows
;
pthread
->
rows
=
numOfRows
;
pthread
->
tables
=
numOfTables
;
pthread
->
tables
=
numOfTables
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
pthread_c
reate
(
&
pthread
->
pid
,
&
thattr
,
(
void
*
(
*
)(
void
*
))
execute
,
pthread
);
taosThreadC
reate
(
&
pthread
->
pid
,
&
thattr
,
(
void
*
(
*
)(
void
*
))
execute
,
pthread
);
}
}
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
pthread_j
oin
(
threads
[
i
].
pid
,
NULL
);
taosThreadJ
oin
(
threads
[
i
].
pid
,
NULL
);
}
}
free
(
threads
);
free
(
threads
);
}
}
...
...
tests/script/http/httpTestSqlt.c
浏览文件 @
3544df41
...
@@ -5,12 +5,11 @@
...
@@ -5,12 +5,11 @@
#include <unistd.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <stdlib.h>
#include <pthread.h>
#define MAXLINE 1024
#define MAXLINE 1024
typedef
struct
{
typedef
struct
{
pthread_t
pid
;
TdThread
pid
;
int
threadId
;
int
threadId
;
int
rows
;
int
rows
;
int
tables
;
int
tables
;
...
@@ -107,16 +106,16 @@ void multiThread() {
...
@@ -107,16 +106,16 @@ void multiThread() {
ThreadObj
*
threads
=
calloc
((
size_t
)
numOfThreads
,
sizeof
(
ThreadObj
));
ThreadObj
*
threads
=
calloc
((
size_t
)
numOfThreads
,
sizeof
(
ThreadObj
));
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
ThreadObj
*
pthread
=
threads
+
i
;
ThreadObj
*
pthread
=
threads
+
i
;
pthread_attr_t
thattr
;
TdThreadAttr
thattr
;
pthread
->
threadId
=
i
+
1
;
pthread
->
threadId
=
i
+
1
;
pthread
->
rows
=
numOfRows
;
pthread
->
rows
=
numOfRows
;
pthread
->
tables
=
numOfTables
;
pthread
->
tables
=
numOfTables
;
pthread_attr_i
nit
(
&
thattr
);
taosThreadAttrI
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
pthread_c
reate
(
&
pthread
->
pid
,
&
thattr
,
(
void
*
(
*
)(
void
*
))
execute
,
pthread
);
taosThreadC
reate
(
&
pthread
->
pid
,
&
thattr
,
(
void
*
(
*
)(
void
*
))
execute
,
pthread
);
}
}
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++
)
{
pthread_j
oin
(
threads
[
i
].
pid
,
NULL
);
taosThreadJ
oin
(
threads
[
i
].
pid
,
NULL
);
}
}
free
(
threads
);
free
(
threads
);
}
}
...
...
tests/test/c/create_table.c
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
tests/tsim/inc/simInt.h
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
tests/tsim/src/simExe.c
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
tests/tsim/src/simSystem.c
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
tools/shell/src/backup/shellCheck.c
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
tools/shell/src/backup/shellDarwin.c
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
tools/shell/src/backup/shellImport.c
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
tools/shell/src/backup/tnettest.c
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
tools/shell/src/shellLinux.c
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
tools/shell/src/shellMain.c
浏览文件 @
3544df41
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录