test: ut for osthread

This commit is contained in:
Shengliang Guan 2024-12-11 18:04:02 +08:00
parent 98075a7c5a
commit 34a73b96ed
2 changed files with 225 additions and 126 deletions

View File

@ -23,8 +23,7 @@ int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start)
int32_t code = pthread_create(tid, attr, start, arg); int32_t code = pthread_create(tid, attr, start, arg);
if (code) { if (code) {
taosThreadClear(tid); taosThreadClear(tid);
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -33,8 +32,7 @@ int32_t taosThreadAttrDestroy(TdThreadAttr *attr) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_destroy(attr); int32_t code = pthread_attr_destroy(attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -44,8 +42,7 @@ int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachst
OS_PARAM_CHECK(detachstate); OS_PARAM_CHECK(detachstate);
int32_t code = pthread_attr_getdetachstate(attr, detachstate); int32_t code = pthread_attr_getdetachstate(attr, detachstate);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -55,8 +52,7 @@ int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inherit
OS_PARAM_CHECK(inheritsched); OS_PARAM_CHECK(inheritsched);
int32_t code = pthread_attr_getinheritsched(attr, inheritsched); int32_t code = pthread_attr_getinheritsched(attr, inheritsched);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -66,8 +62,7 @@ int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param
OS_PARAM_CHECK(param); OS_PARAM_CHECK(param);
int32_t code = pthread_attr_getschedparam(attr, param); int32_t code = pthread_attr_getschedparam(attr, param);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -77,8 +72,7 @@ int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy)
OS_PARAM_CHECK(policy); OS_PARAM_CHECK(policy);
int32_t code = pthread_attr_getschedpolicy(attr, policy); int32_t code = pthread_attr_getschedpolicy(attr, policy);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -88,8 +82,7 @@ int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscop
OS_PARAM_CHECK(contentionscope); OS_PARAM_CHECK(contentionscope);
int32_t code = pthread_attr_getscope(attr, contentionscope); int32_t code = pthread_attr_getscope(attr, contentionscope);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -99,8 +92,7 @@ int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize)
OS_PARAM_CHECK(stacksize); OS_PARAM_CHECK(stacksize);
int32_t code = pthread_attr_getstacksize(attr, stacksize); int32_t code = pthread_attr_getstacksize(attr, stacksize);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -109,8 +101,7 @@ int32_t taosThreadAttrInit(TdThreadAttr *attr) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_init(attr); int32_t code = pthread_attr_init(attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -119,8 +110,7 @@ int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setdetachstate(attr, detachstate); int32_t code = pthread_attr_setdetachstate(attr, detachstate);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -129,8 +119,7 @@ int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched)
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setinheritsched(attr, inheritsched); int32_t code = pthread_attr_setinheritsched(attr, inheritsched);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -139,8 +128,7 @@ int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setschedparam(attr, param); int32_t code = pthread_attr_setschedparam(attr, param);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -149,8 +137,7 @@ int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setschedpolicy(attr, policy); int32_t code = pthread_attr_setschedpolicy(attr, policy);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -159,8 +146,7 @@ int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setscope(attr, contentionscope); int32_t code = pthread_attr_setscope(attr, contentionscope);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -169,8 +155,7 @@ int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setstacksize(attr, stacksize); int32_t code = pthread_attr_setstacksize(attr, stacksize);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -178,8 +163,7 @@ int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) {
int32_t taosThreadCancel(TdThread thread) { int32_t taosThreadCancel(TdThread thread) {
int32_t code = pthread_cancel(thread); int32_t code = pthread_cancel(thread);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -191,8 +175,7 @@ int32_t taosThreadCondDestroy(TdThreadCond *cond) {
#else #else
int32_t code = pthread_cond_destroy(cond); int32_t code = pthread_cond_destroy(cond);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -206,8 +189,7 @@ int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) {
#else #else
int32_t code = pthread_cond_init(cond, attr); int32_t code = pthread_cond_init(cond, attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -221,8 +203,7 @@ int32_t taosThreadCondSignal(TdThreadCond *cond) {
#else #else
int32_t code = pthread_cond_signal(cond); int32_t code = pthread_cond_signal(cond);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -236,8 +217,7 @@ int32_t taosThreadCondBroadcast(TdThreadCond *cond) {
#else #else
int32_t code = pthread_cond_broadcast(cond); int32_t code = pthread_cond_broadcast(cond);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -254,8 +234,7 @@ int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) {
#else #else
int32_t code = pthread_cond_wait(cond, mutex); int32_t code = pthread_cond_wait(cond, mutex);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -291,14 +270,14 @@ int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_condattr_destroy(attr); int32_t code = pthread_condattr_destroy(attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
} }
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) { int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) {
OS_PARAM_CHECK(attr);
OS_PARAM_CHECK(pshared); OS_PARAM_CHECK(pshared);
#ifdef __USE_WIN_THREAD #ifdef __USE_WIN_THREAD
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE; if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
@ -307,8 +286,7 @@ int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *psha
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_condattr_getpshared(attr, pshared); int32_t code = pthread_condattr_getpshared(attr, pshared);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -321,8 +299,7 @@ int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_condattr_init(attr); int32_t code = pthread_condattr_init(attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -337,8 +314,7 @@ int32_t taosThreadCondAttrSetclock(TdThreadCondAttr *attr, int clockId) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_condattr_setclock(attr, clockId); int32_t code = pthread_condattr_setclock(attr, clockId);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -351,8 +327,7 @@ int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) {
#else #else
int32_t code = pthread_condattr_setpshared(attr, pshared); int32_t code = pthread_condattr_setpshared(attr, pshared);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -361,8 +336,7 @@ int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) {
int32_t taosThreadDetach(TdThread thread) { int32_t taosThreadDetach(TdThread thread) {
int32_t code = pthread_detach(thread); int32_t code = pthread_detach(thread);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -380,8 +354,7 @@ int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_p
OS_PARAM_CHECK(param); OS_PARAM_CHECK(param);
int32_t code = pthread_getschedparam(thread, policy, param); int32_t code = pthread_getschedparam(thread, policy, param);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -393,8 +366,7 @@ void *taosThreadGetSpecific(TdThreadKey key) {
int32_t taosThreadJoin(TdThread thread, void **valuePtr) { int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
int32_t code = pthread_join(thread, valuePtr); int32_t code = pthread_join(thread, valuePtr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -403,8 +375,7 @@ int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) {
OS_PARAM_CHECK(key); OS_PARAM_CHECK(key);
int32_t code = pthread_key_create(key, destructor); int32_t code = pthread_key_create(key, destructor);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -412,8 +383,7 @@ int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) {
int32_t taosThreadKeyDelete(TdThreadKey key) { int32_t taosThreadKeyDelete(TdThreadKey key) {
int32_t code = pthread_key_delete(key); int32_t code = pthread_key_delete(key);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -421,8 +391,7 @@ int32_t taosThreadKeyDelete(TdThreadKey key) {
int32_t taosThreadKill(TdThread thread, int32_t sig) { int32_t taosThreadKill(TdThread thread, int32_t sig) {
int32_t code = pthread_kill(thread, sig); int32_t code = pthread_kill(thread, sig);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -439,8 +408,7 @@ int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) {
#else #else
int32_t code = pthread_mutex_destroy(mutex); int32_t code = pthread_mutex_destroy(mutex);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -459,8 +427,7 @@ int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr)
#else #else
int32_t code = pthread_mutex_init(mutex, attr); int32_t code = pthread_mutex_init(mutex, attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -474,8 +441,7 @@ int32_t taosThreadMutexLock(TdThreadMutex *mutex) {
#else #else
int32_t code = pthread_mutex_lock(mutex); int32_t code = pthread_mutex_lock(mutex);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -507,8 +473,7 @@ int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) {
#else #else
int32_t code = pthread_mutex_unlock(mutex); int32_t code = pthread_mutex_unlock(mutex);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -521,8 +486,7 @@ int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_destroy(attr); int32_t code = pthread_mutexattr_destroy(attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -537,8 +501,7 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *ps
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_getpshared(attr, pshared); int32_t code = pthread_mutexattr_getpshared(attr, pshared);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -557,8 +520,7 @@ int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr *attr, int32_t *kind)
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_gettype(attr, kind); int32_t code = pthread_mutexattr_gettype(attr, kind);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -571,8 +533,7 @@ int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_init(attr); int32_t code = pthread_mutexattr_init(attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -585,8 +546,7 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared)
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_setpshared(attr, pshared); int32_t code = pthread_mutexattr_setpshared(attr, pshared);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -603,8 +563,7 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_settype(attr, kind); int32_t code = pthread_mutexattr_settype(attr, kind);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -613,8 +572,7 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) {
int32_t taosThreadOnce(TdThreadOnce *onceControl, void (*initRoutine)(void)) { int32_t taosThreadOnce(TdThreadOnce *onceControl, void (*initRoutine)(void)) {
int32_t code = pthread_once(onceControl, initRoutine); int32_t code = pthread_once(onceControl, initRoutine);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -629,8 +587,7 @@ int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) {
OS_PARAM_CHECK(rwlock); OS_PARAM_CHECK(rwlock);
int32_t code = pthread_rwlock_destroy(rwlock); int32_t code = pthread_rwlock_destroy(rwlock);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -645,8 +602,7 @@ int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *a
#else #else
int32_t code = pthread_rwlock_init(rwlock, attr); int32_t code = pthread_rwlock_init(rwlock, attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -660,8 +616,7 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) {
#else #else
int32_t code = pthread_rwlock_rdlock(rwlock); int32_t code = pthread_rwlock_rdlock(rwlock);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -683,8 +638,7 @@ int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) {
#else #else
int32_t code = pthread_rwlock_tryrdlock(rwlock); int32_t code = pthread_rwlock_tryrdlock(rwlock);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -699,8 +653,7 @@ int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) {
#else #else
int32_t code = pthread_rwlock_trywrlock(rwlock); int32_t code = pthread_rwlock_trywrlock(rwlock);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -718,8 +671,7 @@ int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) {
#else #else
int32_t code = pthread_rwlock_unlock(rwlock); int32_t code = pthread_rwlock_unlock(rwlock);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -734,8 +686,7 @@ int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) {
#else #else
int32_t code = pthread_rwlock_wrlock(rwlock); int32_t code = pthread_rwlock_wrlock(rwlock);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -748,8 +699,7 @@ int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_rwlockattr_destroy(attr); int32_t code = pthread_rwlockattr_destroy(attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -763,8 +713,7 @@ int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *
#else #else
int32_t code = pthread_rwlockattr_getpshared(attr, pshared); int32_t code = pthread_rwlockattr_getpshared(attr, pshared);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -777,8 +726,7 @@ int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) {
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_rwlockattr_init(attr); int32_t code = pthread_rwlockattr_init(attr);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -791,8 +739,7 @@ int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared
OS_PARAM_CHECK(attr); OS_PARAM_CHECK(attr);
int32_t code = pthread_rwlockattr_setpshared(attr, pshared); int32_t code = pthread_rwlockattr_setpshared(attr, pshared);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -803,8 +750,7 @@ TdThread taosThreadSelf(void) { return pthread_self(); }
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) { int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
int32_t code = pthread_setcancelstate(state, oldstate); int32_t code = pthread_setcancelstate(state, oldstate);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -812,8 +758,7 @@ int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
int32_t code = pthread_setcanceltype(type, oldtype); int32_t code = pthread_setcanceltype(type, oldtype);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -822,8 +767,7 @@ int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sc
OS_PARAM_CHECK(param); OS_PARAM_CHECK(param);
int32_t code = pthread_setschedparam(thread, policy, param); int32_t code = pthread_setschedparam(thread, policy, param);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -832,8 +776,7 @@ int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
OS_PARAM_CHECK(value); OS_PARAM_CHECK(value);
int32_t code = pthread_setspecific(key, value); int32_t code = pthread_setspecific(key, value);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
} }
@ -845,8 +788,7 @@ int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) {
#else #else
int32_t code = pthread_spin_destroy((pthread_spinlock_t *)lock); int32_t code = pthread_spin_destroy((pthread_spinlock_t *)lock);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -860,8 +802,7 @@ int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) {
#else #else
int32_t code = pthread_spin_init((pthread_spinlock_t *)lock, pshared); int32_t code = pthread_spin_init((pthread_spinlock_t *)lock, pshared);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -874,8 +815,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock *lock) {
#else #else
int32_t code = pthread_spin_lock((pthread_spinlock_t *)lock); int32_t code = pthread_spin_lock((pthread_spinlock_t *)lock);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif
@ -901,8 +841,7 @@ int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) {
#else #else
int32_t code = pthread_spin_unlock((pthread_spinlock_t *)lock); int32_t code = pthread_spin_unlock((pthread_spinlock_t *)lock);
if (code) { if (code) {
terrno = TAOS_SYSTEM_ERROR(code); return (terrno = TAOS_SYSTEM_ERROR(code));
return terrno;
} }
return code; return code;
#endif #endif

View File

@ -29,6 +29,166 @@
#include "os.h" #include "os.h"
#include "tlog.h" #include "tlog.h"
TEST(osThreadTests, osThreadTests1) { static void *funcPtr0(void *param) { return NULL; }
static void *funcPtr1(void *param) {
taosMsleep(1000);
return NULL;
}
TEST(osThreadTests, invalidParameter) {
TdThread tid1 = {0};
TdThread tid2 = {0};
int32_t reti = 0;
TdThreadAttr attr = {0};
TdThreadAttr attr2 = {0};
int32_t param = 0;
(void)taosThreadAttrInit(&attr);
reti = taosThreadCreate(NULL, NULL, funcPtr0, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCreate(&tid1, NULL, NULL, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCreate(&tid1, NULL, funcPtr1, NULL);
EXPECT_EQ(reti, 0);
reti = taosThreadCancel(tid1);
EXPECT_EQ(reti, 0);
reti = taosThreadCreate(&tid2, NULL, funcPtr0, NULL);
EXPECT_EQ(reti, 0);
taosMsleep(1000);
reti = taosThreadCancel(tid2);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_JOINABLE);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetDetachState(&attr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetDetachState(NULL, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetDetachState(NULL, &param);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetDetachState(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetDetachState(&attr, &param);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetInheritSched(&attr, PTHREAD_INHERIT_SCHED);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetInheritSched(&attr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetInheritSched(NULL, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetInheritSched(NULL, &param);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetInheritSched(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetInheritSched(&attr, &param);
EXPECT_EQ(reti, 0);
struct sched_param schedparam = {0};
reti = taosThreadAttrGetSchedParam(&attr, &schedparam);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetSchedParam(&attr, &schedparam);
EXPECT_EQ(reti, 0);
schedparam.sched_priority = -1;
reti = taosThreadAttrSetSchedParam(&attr, &schedparam);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetSchedParam(NULL, &schedparam);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedParam(NULL, &schedparam);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedParam(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetSchedPolicy(&attr, SCHED_FIFO);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetSchedPolicy(&attr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetSchedPolicy(NULL, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedPolicy(NULL, &param);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedPolicy(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedPolicy(&attr, &param);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetScope(&attr, PTHREAD_SCOPE_SYSTEM);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetScope(&attr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetScope(NULL, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetScope(NULL, &param);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetScope(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetScope(&attr, &param);
EXPECT_EQ(reti, 0);
size_t stacksize;
reti = taosThreadAttrGetStackSize(&attr, &stacksize);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetStackSize(&attr, stacksize);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetStackSize(&attr, 2048);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetStackSize(NULL, stacksize);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetStackSize(NULL, &stacksize);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetStackSize(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrInit(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondInit(NULL, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondSignal(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondBroadcast(NULL);
EXPECT_NE(reti, 0);
TdThreadCond cond;
TdThreadMutex mutex;
reti = taosThreadCondWait(&cond, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondWait(NULL, &mutex);
EXPECT_NE(reti, 0);
struct timespec abstime = {0};
reti = taosThreadCondTimedWait(&cond, NULL, &abstime);
EXPECT_NE(reti, 0);
reti = taosThreadCondTimedWait(NULL, &mutex, &abstime);
EXPECT_NE(reti, 0);
reti = taosThreadCondTimedWait(&cond, &mutex, NULL);
EXPECT_NE(reti, 0);
TdThreadCondAttr condattr;
(void)taosThreadCondAttrInit(&condattr);
reti = taosThreadCondAttrInit(NULL);
EXPECT_NE(reti, 0);
int32_t pshared;
reti = taosThreadCondAttrGetPshared(&condattr, &pshared);
EXPECT_EQ(reti, 0);
reti = taosThreadCondAttrSetPshared(&condattr, pshared);
EXPECT_EQ(reti, 0);
reti = taosThreadCondAttrSetPshared(&condattr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrSetPshared(NULL, pshared);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrGetPshared(NULL, &pshared);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrGetPshared(&condattr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrDestroy(&condattr);
EXPECT_EQ(reti, 0);
} }