diff --git a/include/os/osSleep.h b/include/os/osSleep.h
index 686bdd292e376f55182caea52189a678bfdc3b14..feb94729954e73cc74e1a6b33ec8621a9be10a44 100644
--- a/include/os/osSleep.h
+++ b/include/os/osSleep.h
@@ -20,7 +20,17 @@
extern "C" {
#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 Sleep SLEEP_FUNC_TAOS_FORBID
+ #define sleep SLEEP_FUNC_TAOS_FORBID
+ #define usleep USLEEP_FUNC_TAOS_FORBID
+ #define nanosleep NANOSLEEP_FUNC_TAOS_FORBID
+#endif
+
+void taosSsleep(int32_t s);
void taosMsleep(int32_t ms);
+void taosUsleep(int32_t us);
#ifdef __cplusplus
}
diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c
index b1e9de8000cbdbceed961d9d91a59dccda560d26..88763b8faf2666ca2459cd75617a41749d9571e8 100644
--- a/source/client/src/clientHb.c
+++ b/source/client/src/clientHb.c
@@ -449,7 +449,7 @@ static void hbStopThread() {
}
while (2 != atomic_load_8(&clientHbMgr.threadStop)) {
- usleep(10);
+ taosUsleep(10);
}
tscDebug("hb thread stopped");
diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c
index 60103cc9c5a5f5c25ccc214beb379452feaca0c6..c60d898a9efbf8dc3a8754f61d113d139ebbadf1 100644
--- a/source/client/src/tmq.c
+++ b/source/client/src/tmq.c
@@ -1146,13 +1146,13 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
if (taosArrayGetSize(tmq->clientTopics) == 0) {
tscDebug("consumer:%ld poll but not assigned", tmq->consumerId);
/*printf("over1\n");*/
- usleep(blocking_time * 1000);
+ taosMsleep(blocking_time);
return NULL;
}
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, tmq->nextTopicIdx);
if (taosArrayGetSize(pTopic->vgs) == 0) {
/*printf("over2\n");*/
- usleep(blocking_time * 1000);
+ taosMsleep(blocking_time);
return NULL;
}
@@ -1165,14 +1165,14 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
SMqConsumeReq* pReq = tmqBuildConsumeReqImpl(tmq, blocking_time, pTopic, pVg);
if (pReq == NULL) {
ASSERT(false);
- usleep(blocking_time * 1000);
+ taosMsleep(blocking_time);
return NULL;
}
SMqPollCbParam* param = malloc(sizeof(SMqPollCbParam));
if (param == NULL) {
ASSERT(false);
- usleep(blocking_time * 1000);
+ taosMsleep(blocking_time);
return NULL;
}
param->tmq = tmq;
@@ -1204,7 +1204,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
if (tmq_message == NULL) {
if (beginVgIdx == pTopic->nextVgIdx) {
- usleep(blocking_time * 1000);
+ taosMsleep(blocking_time);
} else {
continue;
}
diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c
index 77d25fa1641f8d509d46335ca1aaa8f9622d8efb..cd4f5438d5de844aaa0f313691d53bb513360e9b 100644
--- a/source/libs/catalog/src/catalog.c
+++ b/source/libs/catalog/src/catalog.c
@@ -2635,7 +2635,7 @@ void catalogDestroy(void) {
tsem_post(&gCtgMgmt.sem);
while (CTG_IS_LOCKED(&gCtgMgmt.lock)) {
- usleep(1);
+ taosUsleep(1);
}
CTG_LOCK(CTG_WRITE, &gCtgMgmt.lock);
diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp
index 00f6a508b71677eb8d43cbe574e3e180f12f7035..cc0e5bb1a9b653a72e766a32b75b6cc3710cf4c6 100644
--- a/source/libs/catalog/test/catalogTests.cpp
+++ b/source/libs/catalog/test/catalogTests.cpp
@@ -723,7 +723,7 @@ void *ctgTestGetDbVgroupThread(void *param) {
}
if (ctgTestEnableSleep) {
- usleep(taosRand() % 5);
+ taosUsleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
printf("Get:%d\n", n);
@@ -747,7 +747,7 @@ void *ctgTestSetSameDbVgroupThread(void *param) {
}
if (ctgTestEnableSleep) {
- usleep(taosRand() % 5);
+ taosUsleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n);
@@ -771,7 +771,7 @@ void *ctgTestSetDiffDbVgroupThread(void *param) {
}
if (ctgTestEnableSleep) {
- usleep(taosRand() % 5);
+ taosUsleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n);
@@ -801,7 +801,7 @@ void *ctgTestGetCtableMetaThread(void *param) {
tfree(tbMeta);
if (ctgTestEnableSleep) {
- usleep(taosRand() % 5);
+ taosUsleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
@@ -838,7 +838,7 @@ void *ctgTestSetCtableMetaThread(void *param) {
}
if (ctgTestEnableSleep) {
- usleep(taosRand() % 5);
+ taosUsleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n);
@@ -880,7 +880,7 @@ TEST(tableMeta, normalTable) {
ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
- usleep(50000);
+ taosMsleep(50);
}
ctgTestSetRspTableMeta();
@@ -901,7 +901,7 @@ TEST(tableMeta, normalTable) {
while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) {
- usleep(50000);
+ taosMsleep(50);
} else {
break;
}
@@ -949,7 +949,7 @@ TEST(tableMeta, normalTable) {
allDbNum += dbNum;
allStbNum += stbNum;
- sleep(2);
+ taosSsleep(2);
}
ASSERT_EQ(allDbNum, 1);
@@ -996,7 +996,7 @@ TEST(tableMeta, childTableCase) {
while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) {
- usleep(50000);
+ taosMsleep(50);
} else {
break;
}
@@ -1058,7 +1058,7 @@ TEST(tableMeta, childTableCase) {
allDbNum += dbNum;
allStbNum += stbNum;
- sleep(2);
+ taosSsleep(2);
}
ASSERT_EQ(allDbNum, 1);
@@ -1105,7 +1105,7 @@ TEST(tableMeta, superTableCase) {
while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) {
- usleep(50000);
+ taosMsleep(50);
} else {
break;
}
@@ -1132,7 +1132,7 @@ TEST(tableMeta, superTableCase) {
while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (2 != n) {
- usleep(50000);
+ taosMsleep(50);
} else {
break;
}
@@ -1181,7 +1181,7 @@ TEST(tableMeta, superTableCase) {
allDbNum += dbNum;
allStbNum += stbNum;
- sleep(2);
+ taosSsleep(2);
}
ASSERT_EQ(allDbNum, 1);
@@ -1230,7 +1230,7 @@ TEST(tableMeta, rmStbMeta) {
while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) {
- usleep(50000);
+ taosMsleep(50);
} else {
break;
}
@@ -1244,7 +1244,7 @@ TEST(tableMeta, rmStbMeta) {
int32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
int32_t m = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM);
if (n || m) {
- usleep(50000);
+ taosMsleep(50);
} else {
break;
}
@@ -1300,7 +1300,7 @@ TEST(tableMeta, updateStbMeta) {
while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) {
- usleep(50000);
+ taosMsleep(50);
} else {
break;
}
@@ -1320,7 +1320,7 @@ TEST(tableMeta, updateStbMeta) {
uint64_t n = 0;
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
if (n != 3) {
- usleep(50000);
+ taosMsleep(50);
} else {
break;
}
@@ -1392,7 +1392,7 @@ TEST(refreshGetMeta, normal2normal) {
if (n > 0) {
break;
}
- usleep(50000);
+ taosMsleep(50);
}
STableMeta *tableMeta = NULL;
@@ -1410,7 +1410,7 @@ TEST(refreshGetMeta, normal2normal) {
tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
- usleep(50000);
+ taosMsleep(50);
}
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
@@ -1471,7 +1471,7 @@ TEST(refreshGetMeta, normal2notexist) {
if (n > 0) {
break;
}
- usleep(50000);
+ taosMsleep(50);
}
STableMeta *tableMeta = NULL;
@@ -1489,7 +1489,7 @@ TEST(refreshGetMeta, normal2notexist) {
tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
- usleep(50000);
+ taosMsleep(50);
}
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
@@ -1545,7 +1545,7 @@ TEST(refreshGetMeta, normal2child) {
if (n > 0) {
break;
}
- usleep(50000);
+ taosMsleep(50);
}
STableMeta *tableMeta = NULL;
@@ -1563,7 +1563,7 @@ TEST(refreshGetMeta, normal2child) {
tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
- usleep(50000);
+ taosMsleep(50);
}
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
@@ -1629,7 +1629,7 @@ TEST(refreshGetMeta, stable2child) {
if (n > 0) {
break;
}
- usleep(50000);
+ taosMsleep(50);
}
STableMeta *tableMeta = NULL;
@@ -1648,7 +1648,7 @@ TEST(refreshGetMeta, stable2child) {
tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
- usleep(50000);
+ taosMsleep(50);
}
ctgTestCurrentSTableName = ctgTestSTablename;
@@ -1714,7 +1714,7 @@ TEST(refreshGetMeta, stable2stable) {
if (n > 0) {
break;
}
- usleep(50000);
+ taosMsleep(50);
}
STableMeta *tableMeta = NULL;
@@ -1733,7 +1733,7 @@ TEST(refreshGetMeta, stable2stable) {
tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
- usleep(50000);
+ taosMsleep(50);
}
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
@@ -1802,7 +1802,7 @@ TEST(refreshGetMeta, child2stable) {
if (n > 0) {
break;
}
- usleep(50000);
+ taosMsleep(50);
}
STableMeta *tableMeta = NULL;
@@ -1819,7 +1819,7 @@ TEST(refreshGetMeta, child2stable) {
tfree(tableMeta);
while (2 != ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
- usleep(50000);
+ taosMsleep(50);
}
ctgTestCurrentSTableName = ctgTestTablename;
@@ -2019,7 +2019,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
if (n > 0) {
break;
}
- usleep(50000);
+ taosMsleep(50);
}
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
@@ -2043,7 +2043,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
uint64_t n = 0;
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
if (n != 3) {
- usleep(50000);
+ taosMsleep(50);
} else {
break;
}
@@ -2100,20 +2100,20 @@ TEST(multiThread, getSetRmSameDbVgroup) {
pthread_t thread1, thread2;
pthread_create(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg);
- sleep(1);
+ taosSsleep(1);
pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
while (true) {
if (ctgTestDeadLoop) {
- sleep(1);
+ taosSsleep(1);
} else {
- sleep(ctgTestMTRunSec);
+ taosSsleep(ctgTestMTRunSec);
break;
}
}
ctgTestStop = true;
- sleep(1);
+ taosSsleep(1);
catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
@@ -2152,20 +2152,20 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
pthread_t thread1, thread2;
pthread_create(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg);
- sleep(1);
+ taosSsleep(1);
pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
while (true) {
if (ctgTestDeadLoop) {
- sleep(1);
+ taosSsleep(1);
} else {
- sleep(ctgTestMTRunSec);
+ taosSsleep(ctgTestMTRunSec);
break;
}
}
ctgTestStop = true;
- sleep(1);
+ taosSsleep(1);
catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
@@ -2203,20 +2203,20 @@ TEST(multiThread, ctableMeta) {
pthread_t thread1, thread2;
pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
- sleep(1);
+ taosSsleep(1);
pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
while (true) {
if (ctgTestDeadLoop) {
- sleep(1);
+ taosSsleep(1);
} else {
- sleep(ctgTestMTRunSec);
+ taosSsleep(ctgTestMTRunSec);
break;
}
}
ctgTestStop = true;
- sleep(2);
+ taosSsleep(2);
catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
@@ -2267,7 +2267,7 @@ TEST(rentTest, allRent) {
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
while (ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) {
- usleep(50000);
+ taosMsleep(50);
}
code = catalogGetExpiredDBs(pCtg, &dbs, &num);
@@ -2292,7 +2292,7 @@ TEST(rentTest, allRent) {
}
printf("*************************************************\n");
- sleep(2);
+ taosSsleep(2);
}
catalogDestroy();
diff --git a/source/libs/qcom/test/queryTest.cpp b/source/libs/qcom/test/queryTest.cpp
index 9ca7442d55fd35d3db8ef084f237a49f4b90c82b..72ce0f7c37f814e0457699ad2c1e7b1d883bab6b 100644
--- a/source/libs/qcom/test/queryTest.cpp
+++ b/source/libs/qcom/test/queryTest.cpp
@@ -63,7 +63,7 @@ int main(int argc, char** argv) {
TEST(testCase, async_task_test) {
SParam* p = (SParam*)calloc(1, sizeof(SParam));
taosAsyncExec(testPrint, p, NULL);
- usleep(5000);
+ taosMsleep(5);
}
TEST(testCase, many_async_task_test) {
@@ -73,14 +73,14 @@ TEST(testCase, many_async_task_test) {
taosAsyncExec(testPrint, p, NULL);
}
- usleep(10000);
+ taosMsleep(10);
}
TEST(testCase, error_in_async_test) {
int32_t code = 0;
SParam* p = (SParam*) calloc(1, sizeof(SParam));
taosAsyncExec(testPrintError, p, &code);
- usleep(1000);
+ taosMsleep(1);
printf("Error code:%d after asynchronously exec function\n", code);
}
diff --git a/source/libs/qworker/test/qworkerTests.cpp b/source/libs/qworker/test/qworkerTests.cpp
index 8658c4cead00fff30f567ea87adeda3ea9a5cd7c..2e262abcd026ccbd50c40f530e7725b77c5c24de 100644
--- a/source/libs/qworker/test/qworkerTests.cpp
+++ b/source/libs/qworker/test/qworkerTests.cpp
@@ -308,7 +308,7 @@ int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
if (qwtTestEnableSleep) {
if (runTime) {
- usleep(runTime);
+ taosUsleep(runTime);
}
}
@@ -590,7 +590,7 @@ void *queryThread(void *param) {
qwtBuildQueryReqMsg(&queryRpc);
qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc);
if (qwtTestEnableSleep) {
- usleep(taosRand()%5);
+ taosUsleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("query:%d\n", n);
@@ -612,7 +612,7 @@ void *readyThread(void *param) {
qwtBuildReadyReqMsg(&readyMsg, &readyRpc);
code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
if (qwtTestEnableSleep) {
- usleep(taosRand()%5);
+ taosUsleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("ready:%d\n", n);
@@ -634,7 +634,7 @@ void *fetchThread(void *param) {
qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc);
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc);
if (qwtTestEnableSleep) {
- usleep(taosRand()%5);
+ taosUsleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("fetch:%d\n", n);
@@ -656,7 +656,7 @@ void *dropThread(void *param) {
qwtBuildDropReqMsg(&dropMsg, &dropRpc);
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc);
if (qwtTestEnableSleep) {
- usleep(taosRand()%5);
+ taosUsleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("drop:%d\n", n);
@@ -678,7 +678,7 @@ void *statusThread(void *param) {
qwtBuildStatusReqMsg(&statusMsg, &statusRpc);
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
if (qwtTestEnableSleep) {
- usleep(taosRand()%5);
+ taosUsleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("status:%d\n", n);
@@ -696,7 +696,7 @@ void *qwtclientThread(void *param) {
void *mockPointer = (void *)0x1;
SRpcMsg queryRpc = {0};
- sleep(1);
+ taosSsleep(1);
while (!qwtTestStop) {
qwtTestCaseFinished = false;
@@ -705,7 +705,7 @@ void *qwtclientThread(void *param) {
qwtPutReqToQueue((void *)0x1, &queryRpc);
while (!qwtTestCaseFinished) {
- usleep(1);
+ taosUsleep(1);
}
@@ -751,7 +751,7 @@ void *queryQueueThread(void *param) {
int32_t delay = taosRand() % qwtTestReqMaxDelayUsec;
if (delay) {
- usleep(delay);
+ taosUsleep(delay);
}
}
@@ -807,7 +807,7 @@ void *fetchQueueThread(void *param) {
int32_t delay = taosRand() % qwtTestReqMaxDelayUsec;
if (delay) {
- usleep(delay);
+ taosUsleep(delay);
}
}
@@ -982,21 +982,21 @@ TEST(seqTest, randCase) {
qwtBuildReadyReqMsg(&readyMsg, &readyRpc);
code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
if (qwtTestEnableSleep) {
- usleep(1);
+ taosUsleep(1);
}
} else if (r >= maxr * 2/5 && r < maxr* 3/5) {
printf("Fetch,%d\n", t++);
qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc);
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc);
if (qwtTestEnableSleep) {
- usleep(1);
+ taosUsleep(1);
}
} else if (r >= maxr * 3/5 && r < maxr * 4/5) {
printf("Drop,%d\n", t++);
qwtBuildDropReqMsg(&dropMsg, &dropRpc);
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc);
if (qwtTestEnableSleep) {
- usleep(1);
+ taosUsleep(1);
}
} else if (r >= maxr * 4/5 && r < maxr-1) {
printf("Status,%d\n", t++);
@@ -1004,7 +1004,7 @@ TEST(seqTest, randCase) {
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
ASSERT_EQ(code, 0);
if (qwtTestEnableSleep) {
- usleep(1);
+ taosUsleep(1);
}
} else {
printf("QUIT RAND NOW");
@@ -1042,15 +1042,15 @@ TEST(seqTest, multithreadRand) {
while (true) {
if (qwtTestDeadLoop) {
- sleep(1);
+ taosSsleep(1);
} else {
- sleep(qwtTestMTRunSec);
+ taosSsleep(qwtTestMTRunSec);
break;
}
}
qwtTestStop = true;
- sleep(3);
+ taosSsleep(3);
qWorkerDestroy(&mgmt);
}
@@ -1099,9 +1099,9 @@ TEST(rcTest, shortExecshortDelay) {
while (true) {
if (qwtTestDeadLoop) {
- sleep(1);
+ taosSsleep(1);
} else {
- sleep(qwtTestMTRunSec);
+ taosSsleep(qwtTestMTRunSec);
break;
}
}
@@ -1113,14 +1113,14 @@ TEST(rcTest, shortExecshortDelay) {
break;
}
- sleep(1);
+ taosSsleep(1);
if (qwtTestCaseFinished) {
if (qwtTestQuitThreadNum < 3) {
tsem_post(&qwtTestQuerySem);
tsem_post(&qwtTestFetchSem);
- usleep(10);
+ taosUsleep(10);
}
}
@@ -1180,9 +1180,9 @@ TEST(rcTest, longExecshortDelay) {
while (true) {
if (qwtTestDeadLoop) {
- sleep(1);
+ taosSsleep(1);
} else {
- sleep(qwtTestMTRunSec);
+ taosSsleep(qwtTestMTRunSec);
break;
}
}
@@ -1195,14 +1195,14 @@ TEST(rcTest, longExecshortDelay) {
break;
}
- sleep(1);
+ taosSsleep(1);
if (qwtTestCaseFinished) {
if (qwtTestQuitThreadNum < 3) {
tsem_post(&qwtTestQuerySem);
tsem_post(&qwtTestFetchSem);
- usleep(10);
+ taosUsleep(10);
}
}
@@ -1263,9 +1263,9 @@ TEST(rcTest, shortExeclongDelay) {
while (true) {
if (qwtTestDeadLoop) {
- sleep(1);
+ taosSsleep(1);
} else {
- sleep(qwtTestMTRunSec);
+ taosSsleep(qwtTestMTRunSec);
break;
}
}
@@ -1278,14 +1278,14 @@ TEST(rcTest, shortExeclongDelay) {
break;
}
- sleep(1);
+ taosSsleep(1);
if (qwtTestCaseFinished) {
if (qwtTestQuitThreadNum < 3) {
tsem_post(&qwtTestQuerySem);
tsem_post(&qwtTestFetchSem);
- usleep(10);
+ taosUsleep(10);
}
}
@@ -1342,15 +1342,15 @@ TEST(rcTest, dropTest) {
while (true) {
if (qwtTestDeadLoop) {
- sleep(1);
+ taosSsleep(1);
} else {
- sleep(qwtTestMTRunSec);
+ taosSsleep(qwtTestMTRunSec);
break;
}
}
qwtTestStop = true;
- sleep(3);
+ taosSsleep(3);
qWorkerDestroy(&mgmt);
}
diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp
index f17dcbd1f5d04c29512251e8eb853c4eb3040265..77353607fadfa60f89f6a5e340a7468305be2302 100644
--- a/source/libs/scheduler/test/schedulerTests.cpp
+++ b/source/libs/scheduler/test/schedulerTests.cpp
@@ -278,7 +278,7 @@ void *schtSendRsp(void *param) {
break;
}
- usleep(1000);
+ taosMsleep(1);
}
pJob = schAcquireJob(job);
@@ -303,7 +303,7 @@ void *schtCreateFetchRspThread(void *param) {
int64_t job = *(int64_t *)param;
SSchJob* pJob = schAcquireJob(job);
- sleep(1);
+ taosSsleep(1);
int32_t code = 0;
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)calloc(1, sizeof(SRetrieveTableRsp));
@@ -327,7 +327,7 @@ void *schtFetchRspThread(void *aa) {
continue;
}
- usleep(1);
+ taosUsleep(1);
param = (SSchCallbackParam *)calloc(1, sizeof(*param));
@@ -532,7 +532,7 @@ void* schtRunJobThread(void *aa) {
void* schtFreeJobThread(void *aa) {
while (!schtTestStop) {
- usleep(taosRand() % 100);
+ taosUsleep(taosRand() % 100);
schtFreeQueryJob(1);
}
}
@@ -701,15 +701,15 @@ TEST(multiThread, forceFree) {
while (true) {
if (schtTestDeadLoop) {
- sleep(1);
+ taosSsleep(1);
} else {
- sleep(schtTestMTRunSec);
+ taosSsleep(schtTestMTRunSec);
break;
}
}
schtTestStop = true;
- sleep(3);
+ taosSsleep(3);
}
int main(int argc, char** argv) {
diff --git a/source/libs/sync/test/syncIOSendMsgClientTest.cpp b/source/libs/sync/test/syncIOSendMsgClientTest.cpp
index 83ac7247897f18f248334048a0923af2e9aac1d0..250054fd5a223229cda73e3e5f53fc69830c57da 100644
--- a/source/libs/sync/test/syncIOSendMsgClientTest.cpp
+++ b/source/libs/sync/test/syncIOSendMsgClientTest.cpp
@@ -39,11 +39,11 @@ int main() {
rpcMsg.msgType = 77;
syncIOSendMsg(gSyncIO->clientRpc, &epSet, &rpcMsg);
- sleep(1);
+ taosSsleep(1);
}
while (1) {
- sleep(1);
+ taosSsleep(1);
}
return 0;
diff --git a/source/libs/sync/test/syncIOSendMsgServerTest.cpp b/source/libs/sync/test/syncIOSendMsgServerTest.cpp
index b0f177962fe7b8c053e221d4efeba095afa7051d..1d7402e461f26ea8c7f00508af7352c6c76ac9c8 100644
--- a/source/libs/sync/test/syncIOSendMsgServerTest.cpp
+++ b/source/libs/sync/test/syncIOSendMsgServerTest.cpp
@@ -26,7 +26,7 @@ int main() {
assert(ret == 0);
while (1) {
- sleep(1);
+ taosSsleep(1);
}
return 0;
diff --git a/source/libs/sync/test/syncIOSendMsgTest.cpp b/source/libs/sync/test/syncIOSendMsgTest.cpp
index c25ad3b1dddef7d41d3e727834ffddc0ca69a6ef..ed88fbb03e39e018c28128e0ec947da8b8b1a3bd 100644
--- a/source/libs/sync/test/syncIOSendMsgTest.cpp
+++ b/source/libs/sync/test/syncIOSendMsgTest.cpp
@@ -39,11 +39,11 @@ int main() {
rpcMsg.msgType = 77;
syncIOSendMsg(gSyncIO->clientRpc, &epSet, &rpcMsg);
- sleep(1);
+ taosSsleep(1);
}
while (1) {
- sleep(1);
+ taosSsleep(1);
}
return 0;
diff --git a/source/libs/sync/test/syncIOTickPingTest.cpp b/source/libs/sync/test/syncIOTickPingTest.cpp
index 777fc035e212aec5fd8956afa56c3c4b0357bce6..8be93e6fc0d43f3d8cfa68a5ef6eda7e3706a937 100644
--- a/source/libs/sync/test/syncIOTickPingTest.cpp
+++ b/source/libs/sync/test/syncIOTickPingTest.cpp
@@ -29,7 +29,7 @@ int main() {
assert(ret == 0);
while (1) {
- sleep(1);
+ taosSsleep(1);
}
return 0;
}
diff --git a/source/libs/sync/test/syncIOTickQTest.cpp b/source/libs/sync/test/syncIOTickQTest.cpp
index 5615058cc3fefe119c2da21e32d06e95b0b221d0..76f5e33e82750df8cbc87524b4adca21198d3713 100644
--- a/source/libs/sync/test/syncIOTickQTest.cpp
+++ b/source/libs/sync/test/syncIOTickQTest.cpp
@@ -29,7 +29,7 @@ int main() {
assert(ret == 0);
while (1) {
- sleep(1);
+ taosSsleep(1);
}
return 0;
}
diff --git a/source/libs/transport/test/pushClient.c b/source/libs/transport/test/pushClient.c
index f4babc998059aee1aa0aac109476995a840fc045..bdb754ea145a8ac506366ac624089cca4da1f0b0 100644
--- a/source/libs/transport/test/pushClient.c
+++ b/source/libs/transport/test/pushClient.c
@@ -107,7 +107,7 @@ static void *sendRequest(void *param) {
tDebug("recv response succefully");
- // usleep(100000000);
+ // taosSsleep(100);
}
tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000);
@@ -223,7 +223,7 @@ int main(int argc, char *argv[]) {
}
do {
- usleep(1);
+ taosUsleep(1);
} while (tcount < appThreads);
gettimeofday(&systemTime, NULL);
diff --git a/source/libs/transport/test/pushServer.c b/source/libs/transport/test/pushServer.c
index c763b7bd8adf8acfc9b3d72aa5defe78ca1fa11d..f4ad73f743a10eb20b726ba27ed6f44dbc0e1e2b 100644
--- a/source/libs/transport/test/pushServer.c
+++ b/source/libs/transport/test/pushServer.c
@@ -77,7 +77,7 @@ void processShellMsg() {
taosFreeQitem(pRpcMsg);
{
- // sleep(1);
+ // taosSsleep(1);
SRpcMsg nRpcMsg = {0};
nRpcMsg.pCont = rpcMallocCont(msgSize);
nRpcMsg.contLen = msgSize;
@@ -176,7 +176,7 @@ int main(int argc, char *argv[]) {
tError("failed to start RPC server");
return -1;
}
- // sleep(5);
+ // taosSsleep(5);
tInfo("RPC server is running, ctrl-c to exit");
diff --git a/source/libs/transport/test/rclient.c b/source/libs/transport/test/rclient.c
index 6fc935cb613c7341296549624b30d71b815d0584..f3940e34f97b6d9d6dc24f6eca6a090ee4d4c03a 100644
--- a/source/libs/transport/test/rclient.c
+++ b/source/libs/transport/test/rclient.c
@@ -84,7 +84,7 @@ static void *sendRequest(void *param) {
tDebug("recv response succefully");
- // usleep(100000000);
+ // taosSsleep(100);
}
tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000);
@@ -200,7 +200,7 @@ int main(int argc, char *argv[]) {
}
do {
- usleep(1);
+ taosUsleep(1);
} while (tcount < appThreads);
gettimeofday(&systemTime, NULL);
diff --git a/source/libs/transport/test/rsclient.c b/source/libs/transport/test/rsclient.c
index 26a02eb05b7b704e32025731238453ffc3daece9..f2a963b83f2d91f2570667acf3651572f18aea8e 100644
--- a/source/libs/transport/test/rsclient.c
+++ b/source/libs/transport/test/rsclient.c
@@ -178,7 +178,7 @@ int main(int argc, char *argv[]) {
}
do {
- usleep(1);
+ taosUsleep(1);
} while ( tcount < appThreads);
gettimeofday(&systemTime, NULL);
diff --git a/source/libs/transport/test/syncClient.c b/source/libs/transport/test/syncClient.c
index f43fa7aae6a1f494c5e7b783ec14f5251616eeeb..f84ced5374b1d4f0bdfdf51018388e4fce6f421c 100644
--- a/source/libs/transport/test/syncClient.c
+++ b/source/libs/transport/test/syncClient.c
@@ -85,7 +85,7 @@ static void *sendRequest(void *param) {
tDebug("recv response succefully");
- // usleep(100000000);
+ // taosSsleep(100);
}
tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000);
@@ -201,7 +201,7 @@ int main(int argc, char *argv[]) {
}
do {
- usleep(1);
+ taosUsleep(1);
} while (tcount < appThreads);
gettimeofday(&systemTime, NULL);
diff --git a/source/os/src/osSleep.c b/source/os/src/osSleep.c
index 3b90fbdad88059e370673b150070785823eec571..724347b0bc9fb4ff27de2d2d69d8be253cb10743 100644
--- a/source/os/src/osSleep.c
+++ b/source/os/src/osSleep.c
@@ -13,47 +13,35 @@
* along with this program. If not, see .
*/
+#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include "os.h"
-#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
-
-void taosMsleep(int32_t ms) { Sleep(ms); }
-
-#else
+#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
#include
+#endif
-/*
- to make taosMsleep work,
- signal SIGALRM shall be blocked in the calling thread,
-
- sigset_t set;
- sigemptyset(&set);
- sigaddset(&set, SIGALRM);
- pthread_sigmask(SIG_BLOCK, &set, NULL);
-*/
-void taosMsleep(int32_t mseconds) {
-#if 1
- usleep(mseconds * 1000);
+void taosSsleep(int32_t s) {
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+ Sleep(1000 * s);
#else
- struct timeval timeout;
- int32_t seconds, useconds;
-
- seconds = mseconds / 1000;
- useconds = (mseconds % 1000) * 1000;
- timeout.tv_sec = seconds;
- timeout.tv_usec = useconds;
-
- /* sigset_t set; */
- /* sigemptyset(&set); */
- /* sigaddset(&set, SIGALRM); */
- /* pthread_sigmask(SIG_BLOCK, &set, NULL); */
-
- select(0, NULL, NULL, NULL, &timeout);
+ sleep(s);
+#endif
+}
-/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
+void taosMsleep(int32_t ms) {
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+ Sleep(ms);
+#else
+ usleep(ms * 1000);
#endif
}
+void taosUsleep(int32_t us) {
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+ nanosleep(1000 * us);
+#else
+ usleep(us);
#endif
+}
diff --git a/source/os/src/osString.c b/source/os/src/osString.c
index 88ea4b3e1521103b4827c7b5646ec2ed92b556e6..0fab7a941e7b6c78983ec81b7e055fe881952265 100644
--- a/source/os/src/osString.c
+++ b/source/os/src/osString.c
@@ -291,11 +291,10 @@ int32_t twcslen(const wchar_t *wcs) {
return n;
}
-
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) {
- for (int32_t i = 0; i < bytes; ++i) {
- int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4);
- int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i * 4);
+ for (int32_t i = 0; i < bytes; i += TSDB_NCHAR_SIZE) {
+ int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i);
+ int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i);
if ((f1 == 0 && f2 != 0) || (f1 != 0 && f2 == 0)) {
return f1 - f2;
diff --git a/source/util/test/cacheTest.cpp b/source/util/test/cacheTest.cpp
index e1c8c8c14ece5d79fe660717da024e003d53c406..748cf31b679a9496a6db0a615a0e2938e167393d 100644
--- a/source/util/test/cacheTest.cpp
+++ b/source/util/test/cacheTest.cpp
@@ -14,7 +14,7 @@ TEST(cacheTest, client_cache_test) {
char data1[] = "test11";
char* cachedObj = (char*) taosCachePut(tscMetaCache, key1, strlen(key1), data1, strlen(data1)+1, 1);
- sleep(REFRESH_TIME_IN_SEC+1);
+ taosSsleep(REFRESH_TIME_IN_SEC+1);
printf("obj is still valid: %s\n", cachedObj);
@@ -37,7 +37,7 @@ TEST(cacheTest, client_cache_test) {
taosCacheRelease(tscMetaCache, (void**) &cachedObj2, false);
- sleep(3);
+ taosSsleep(3);
char* d = (char*) taosCacheAcquireByKey(tscMetaCache, key3, strlen(key3));
assert(d == NULL);
diff --git a/source/util/test/trefTest.c b/source/util/test/trefTest.c
index 586151d7827066cfa4fa840cbb862a03bb435989..58d9d2202ec66459e50799271332e1d398a72ad6 100644
--- a/source/util/test/trefTest.c
+++ b/source/util/test/trefTest.c
@@ -42,7 +42,7 @@ void *addRef(void *param) {
pSpace->p[id] = malloc(128);
pSpace->rid[id] = taosAddRef(pSpace->rsetId, pSpace->p[id]);
}
- usleep(100);
+ taosUsleep(100);
}
return NULL;
@@ -60,7 +60,7 @@ void *removeRef(void *param) {
if (code == 0) pSpace->rid[id] = 0;
}
- usleep(100);
+ taosUsleep(100);
}
return NULL;
@@ -76,7 +76,7 @@ void *acquireRelease(void *param) {
id = random() % pSpace->refNum;
void *p = taosAcquireRef(pSpace->rsetId, (int64_t) pSpace->p[id]);
if (p) {
- usleep(id % 5 + 1);
+ taosUsleep(id % 5 + 1);
taosReleaseRef(pSpace->rsetId, (int64_t) pSpace->p[id]);
}
}
diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c
index 386df15d864ef6917168fd731543caca8b1a17a5..5336a557e3f0707b41d3a52256182909beee33db 100644
--- a/tests/script/api/batchprepare.c
+++ b/tests/script/api/batchprepare.c
@@ -5089,7 +5089,7 @@ int main(int argc, char *argv[])
//pthread_create(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
while(1) {
- sleep(1);
+ taosSsleep(1);
}
return 0;
}