fix: return code validation

This commit is contained in:
dapan1121 2024-07-25 17:34:41 +08:00
parent be66e5d21c
commit 11dea101d1
4 changed files with 443 additions and 88 deletions

View File

@ -75,7 +75,7 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
char buf[TSDB_PASSWORD_LEN + 1];
buf[TSDB_PASSWORD_LEN] = 0;
sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1],
(void)sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1],
context.digest[2], context.digest[3], context.digest[4], context.digest[5], context.digest[6],
context.digest[7], context.digest[8], context.digest[9], context.digest[10], context.digest[11],
context.digest[12], context.digest[13], context.digest[14], context.digest[15]);
@ -108,10 +108,10 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
int32_t offset = 0;
if (prefix < 0) {
offset = -1 * prefix;
strncpy(tbName, tbname, offset);
(void)strncpy(tbName, tbname, offset);
}
if (suffix < 0) {
strncpy(tbName + offset, tbname + tblen + suffix, -1 * suffix);
(void)strncpy(tbName + offset, tbname + tblen + suffix, -1 * suffix);
offset += -1 * suffix;
}
return MurmurHash3_32(tbName, offset);

View File

@ -301,8 +301,8 @@ int64_t taosGetLineCmd(TdCmdPtr pCmd, char** __restrict ptrBuf) {
(*ptrBuf)[1023] = 0;
return strlen(*ptrBuf);
#else
int64_t len = 0;
len = getline(ptrBuf, &len, (FILE*)pCmd);
ssize_t len = 0;
len = getline(ptrBuf, (size_t*)&len, (FILE*)pCmd);
if (-1 == len) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;

View File

@ -18,68 +18,159 @@
#include "os.h"
int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start)(void *), void *arg) {
return pthread_create(tid, attr, start, arg);
int32_t code = pthread_create(tid, attr, start, arg);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { return pthread_attr_destroy(attr); }
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) {
int32_t code = pthread_attr_destroy(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachstate) {
return pthread_attr_getdetachstate(attr, detachstate);
int32_t code = pthread_attr_getdetachstate(attr, detachstate);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inheritsched) {
return pthread_attr_getinheritsched(attr, inheritsched);
int32_t code = pthread_attr_getinheritsched(attr, inheritsched);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param *param) {
return pthread_attr_getschedparam(attr, param);
int32_t code = pthread_attr_getschedparam(attr, param);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy) {
return pthread_attr_getschedpolicy(attr, policy);
int32_t code = pthread_attr_getschedpolicy(attr, policy);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscope) {
return pthread_attr_getscope(attr, contentionscope);
int32_t code = pthread_attr_getscope(attr, contentionscope);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize) {
return pthread_attr_getstacksize(attr, stacksize);
int32_t code = pthread_attr_getstacksize(attr, stacksize);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrInit(TdThreadAttr *attr) { return pthread_attr_init(attr); }
int32_t taosThreadAttrInit(TdThreadAttr *attr) {
int32_t code = pthread_attr_init(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) {
return pthread_attr_setdetachstate(attr, detachstate);
int32_t code = pthread_attr_setdetachstate(attr, detachstate);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched) {
return pthread_attr_setinheritsched(attr, inheritsched);
int32_t code = pthread_attr_setinheritsched(attr, inheritsched);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param *param) {
return pthread_attr_setschedparam(attr, param);
int32_t code = pthread_attr_setschedparam(attr, param);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) {
return pthread_attr_setschedpolicy(attr, policy);
int32_t code = pthread_attr_setschedpolicy(attr, policy);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) {
return pthread_attr_setscope(attr, contentionscope);
int32_t code = pthread_attr_setscope(attr, contentionscope);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) {
return pthread_attr_setstacksize(attr, stacksize);
int32_t code = pthread_attr_setstacksize(attr, stacksize);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadCancel(TdThread thread) { return pthread_cancel(thread); }
int32_t taosThreadCancel(TdThread thread) {
int32_t code = pthread_cancel(thread);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadCondDestroy(TdThreadCond *cond) {
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_cond_destroy(cond);
int32_t code = pthread_cond_destroy(cond);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -88,7 +179,12 @@ int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) {
InitializeConditionVariable(cond);
return 0;
#else
return pthread_cond_init(cond, attr);
int32_t code = pthread_cond_init(cond, attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -97,7 +193,12 @@ int32_t taosThreadCondSignal(TdThreadCond *cond) {
WakeConditionVariable(cond);
return 0;
#else
return pthread_cond_signal(cond);
int32_t code = pthread_cond_signal(cond);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -106,7 +207,12 @@ int32_t taosThreadCondBroadcast(TdThreadCond *cond) {
WakeAllConditionVariable(cond);
return 0;
#else
return pthread_cond_broadcast(cond);
int32_t code = pthread_cond_broadcast(cond);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -117,7 +223,12 @@ int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) {
}
return 0;
#else
return pthread_cond_wait(cond, mutex);
int32_t code = pthread_cond_wait(cond, mutex);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -130,7 +241,12 @@ int32_t taosThreadCondTimedWait(TdThreadCond *cond, TdThreadMutex *mutex, const
}
return EINVAL;
#else
return pthread_cond_timedwait(cond, mutex, abstime);
int32_t code = pthread_cond_timedwait(cond, mutex, abstime);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -138,7 +254,12 @@ int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) {
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_condattr_destroy(attr);
int32_t code = pthread_condattr_destroy(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -147,7 +268,12 @@ int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *psha
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
return 0;
#else
return pthread_condattr_getpshared(attr, pshared);
int32_t code = pthread_condattr_getpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -155,7 +281,12 @@ int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) {
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_condattr_init(attr);
int32_t code = pthread_condattr_init(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -165,7 +296,12 @@ int32_t taosThreadCondAttrSetclock(TdThreadCondAttr *attr, int clockId) {
#elif defined(__APPLE__)
return 0;
#else
return pthread_condattr_setclock(attr, clockId);
int32_t code = pthread_condattr_setclock(attr, clockId);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -173,31 +309,80 @@ int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) {
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_condattr_setpshared(attr, pshared);
int32_t code = pthread_condattr_setpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
int32_t taosThreadDetach(TdThread thread) { return pthread_detach(thread); }
int32_t taosThreadDetach(TdThread thread) {
int32_t code = pthread_detach(thread);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadEqual(TdThread t1, TdThread t2) { return pthread_equal(t1, t2); }
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
return pthread_equal(t1, t2);
}
void taosThreadExit(void *valuePtr) { return pthread_exit(valuePtr); }
void taosThreadExit(void *valuePtr) {
return pthread_exit(valuePtr);
}
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
return pthread_getschedparam(thread, policy, param);
int32_t code = pthread_getschedparam(thread, policy, param);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
void *taosThreadGetSpecific(TdThreadKey key) { return pthread_getspecific(key); }
void *taosThreadGetSpecific(TdThreadKey key) {
return pthread_getspecific(key);
}
int32_t taosThreadJoin(TdThread thread, void **valuePtr) { return pthread_join(thread, valuePtr); }
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
int32_t code = pthread_join(thread, valuePtr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) {
return pthread_key_create(key, destructor);
int32_t code = pthread_key_create(key, destructor);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadKeyDelete(TdThreadKey key) { return pthread_key_delete(key); }
int32_t taosThreadKeyDelete(TdThreadKey key) {
int32_t code = pthread_key_delete(key);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadKill(TdThread thread, int32_t sig) { return pthread_kill(thread, sig); }
int32_t taosThreadKill(TdThread thread, int32_t sig) {
int32_t code = pthread_kill(thread, sig);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
// int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) {
// return pthread_mutex_consistent(mutex);
@ -208,7 +393,12 @@ int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) {
DeleteCriticalSection(mutex);
return 0;
#else
return pthread_mutex_destroy(mutex);
int32_t code = pthread_mutex_destroy(mutex);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -222,7 +412,12 @@ int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr)
InitializeCriticalSection(mutex);
return 0;
#else
return pthread_mutex_init(mutex, attr);
int32_t code = pthread_mutex_init(mutex, attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -231,7 +426,12 @@ int32_t taosThreadMutexLock(TdThreadMutex *mutex) {
EnterCriticalSection(mutex);
return 0;
#else
return pthread_mutex_lock(mutex);
int32_t code = pthread_mutex_lock(mutex);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -244,7 +444,12 @@ int32_t taosThreadMutexTryLock(TdThreadMutex *mutex) {
if (TryEnterCriticalSection(mutex)) return 0;
return EBUSY;
#else
return pthread_mutex_trylock(mutex);
int32_t code = pthread_mutex_trylock(mutex);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -253,7 +458,12 @@ int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) {
LeaveCriticalSection(mutex);
return 0;
#else
return pthread_mutex_unlock(mutex);
int32_t code = pthread_mutex_unlock(mutex);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -261,7 +471,12 @@ int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) {
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_mutexattr_destroy(attr);
int32_t code = pthread_mutexattr_destroy(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -270,7 +485,12 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *ps
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
return 0;
#else
return pthread_mutexattr_getpshared(attr, pshared);
int32_t code = pthread_mutexattr_getpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -283,7 +503,12 @@ int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr *attr, int32_t *kind)
if (kind) *kind = PTHREAD_MUTEX_NORMAL;
return 0;
#else
return pthread_mutexattr_gettype(attr, kind);
int32_t code = pthread_mutexattr_gettype(attr, kind);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -291,7 +516,12 @@ int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) {
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_mutexattr_init(attr);
int32_t code = pthread_mutexattr_init(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -299,7 +529,12 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared)
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_mutexattr_setpshared(attr, pshared);
int32_t code = pthread_mutexattr_setpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -311,12 +546,22 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) {
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_mutexattr_settype(attr, kind);
int32_t code = pthread_mutexattr_settype(attr, kind);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
int32_t taosThreadOnce(TdThreadOnce *onceControl, void (*initRoutine)(void)) {
return pthread_once(onceControl, initRoutine);
int32_t code = pthread_once(onceControl, initRoutine);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) {
@ -326,7 +571,12 @@ int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) {
*/
return 0;
#else
return pthread_rwlock_destroy(rwlock);
int32_t code = pthread_rwlock_destroy(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -336,7 +586,12 @@ int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *a
InitializeSRWLock(&rwlock->lock);
return 0;
#else
return pthread_rwlock_init(rwlock, attr);
int32_t code = pthread_rwlock_init(rwlock, attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -345,7 +600,12 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) {
AcquireSRWLockShared(&rwlock->lock);
return 0;
#else
return pthread_rwlock_rdlock(rwlock);
int32_t code = pthread_rwlock_rdlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -362,7 +622,12 @@ int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) {
if (!TryAcquireSRWLockShared(&rwlock->lock)) return EBUSY;
return 0;
#else
return pthread_rwlock_tryrdlock(rwlock);
int32_t code = pthread_rwlock_tryrdlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -372,7 +637,12 @@ int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) {
atomic_store_8(&rwlock->excl, 1);
return 0;
#else
return pthread_rwlock_trywrlock(rwlock);
int32_t code = pthread_rwlock_trywrlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -385,7 +655,12 @@ int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) {
}
return 0;
#else
return pthread_rwlock_unlock(rwlock);
int32_t code = pthread_rwlock_unlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -395,7 +670,12 @@ int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) {
atomic_store_8(&rwlock->excl, 1);
return 0;
#else
return pthread_rwlock_wrlock(rwlock);
int32_t code = pthread_rwlock_wrlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -403,7 +683,12 @@ int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) {
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_rwlockattr_destroy(attr);
int32_t code = pthread_rwlockattr_destroy(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -412,7 +697,12 @@ int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
return 0;
#else
return pthread_rwlockattr_getpshared(attr, pshared);
int32_t code = pthread_rwlockattr_getpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -420,7 +710,12 @@ int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) {
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_rwlockattr_init(attr);
int32_t code = pthread_rwlockattr_init(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -428,27 +723,63 @@ int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared
#ifdef __USE_WIN_THREAD
return 0;
#else
return pthread_rwlockattr_setpshared(attr, pshared);
int32_t code = pthread_rwlockattr_setpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
TdThread taosThreadSelf(void) { return pthread_self(); }
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) { return pthread_setcancelstate(state, oldstate); }
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { return pthread_setcanceltype(type, oldtype); }
int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
return pthread_setschedparam(thread, policy, param);
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
int32_t code = pthread_setcancelstate(state, oldstate);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { return pthread_setspecific(key, value); }
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
int32_t code = pthread_setcanceltype(type, oldtype);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
int32_t code = pthread_setschedparam(thread, policy, param);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
int32_t code = pthread_setspecific(key, value);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
}
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_destroy((pthread_mutex_t *)lock);
#else
return pthread_spin_destroy((pthread_spinlock_t *)lock);
int32_t code = pthread_spin_destroy((pthread_spinlock_t *)lock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -458,7 +789,12 @@ int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) {
if (pshared != 0) return -1;
return pthread_mutex_init((pthread_mutex_t *)lock, NULL);
#else
return pthread_spin_init((pthread_spinlock_t *)lock, pshared);
int32_t code = pthread_spin_init((pthread_spinlock_t *)lock, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -466,7 +802,12 @@ int32_t taosThreadSpinLock(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_lock((pthread_mutex_t *)lock);
#else
return pthread_spin_lock((pthread_spinlock_t *)lock);
int32_t code = pthread_spin_lock((pthread_spinlock_t *)lock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -474,7 +815,12 @@ int32_t taosThreadSpinTrylock(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_trylock((pthread_mutex_t *)lock);
#else
return pthread_spin_trylock((pthread_spinlock_t *)lock);
int32_t code = pthread_spin_trylock((pthread_spinlock_t *)lock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
@ -482,10 +828,19 @@ int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_unlock((pthread_mutex_t *)lock);
#else
return pthread_spin_unlock((pthread_spinlock_t *)lock);
int32_t code = pthread_spin_unlock((pthread_spinlock_t *)lock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
}
return code;
#endif
}
void taosThreadTestCancel(void) { return pthread_testcancel(); }
void taosThreadTestCancel(void) {
return pthread_testcancel();
}
void taosThreadClear(TdThread *thread) { memset(thread, 0, sizeof(TdThread)); }
void taosThreadClear(TdThread *thread) {
(void)memset(thread, 0, sizeof(TdThread));
}

View File

@ -42,7 +42,7 @@ mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) {
uError("mempool malloc failed\n");
return NULL;
} else {
memset(pool_p, 0, sizeof(pool_t));
(void)memset(pool_p, 0, sizeof(pool_t));
}
pool_p->blockSize = blockSize;
@ -58,9 +58,9 @@ mpool_h taosMemPoolInit(int32_t numOfBlock, int32_t blockSize) {
return NULL;
}
taosThreadMutexInit(&(pool_p->mutex), NULL);
(void)taosThreadMutexInit(&(pool_p->mutex), NULL);
memset(pool_p->pool, 0, (size_t)(blockSize * numOfBlock));
(void)memset(pool_p->pool, 0, (size_t)(blockSize * numOfBlock));
for (i = 0; i < pool_p->numOfBlock; ++i) pool_p->freeList[i] = i;
pool_p->first = 0;
@ -73,7 +73,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
char *pos = NULL;
pool_t *pool_p = (pool_t *)handle;
taosThreadMutexLock(&(pool_p->mutex));
(void)taosThreadMutexLock(&(pool_p->mutex));
if (pool_p->numOfFree > 0) {
pos = pool_p->pool + pool_p->blockSize * (pool_p->freeList[pool_p->first]);
@ -82,7 +82,7 @@ char *taosMemPoolMalloc(mpool_h handle) {
pool_p->numOfFree--;
}
taosThreadMutexUnlock(&(pool_p->mutex));
(void)taosThreadMutexUnlock(&(pool_p->mutex));
if (pos == NULL) uDebug("mempool: out of memory");
return pos;
@ -106,22 +106,22 @@ void taosMemPoolFree(mpool_h handle, char *pMem) {
return;
}
memset(pMem, 0, (size_t)pool_p->blockSize);
(void)memset(pMem, 0, (size_t)pool_p->blockSize);
taosThreadMutexLock(&pool_p->mutex);
(void)taosThreadMutexLock(&pool_p->mutex);
pool_p->freeList[(pool_p->first + pool_p->numOfFree) % pool_p->numOfBlock] = index;
pool_p->numOfFree++;
taosThreadMutexUnlock(&pool_p->mutex);
(void)taosThreadMutexUnlock(&pool_p->mutex);
}
void taosMemPoolCleanUp(mpool_h handle) {
pool_t *pool_p = (pool_t *)handle;
taosThreadMutexDestroy(&pool_p->mutex);
(void)taosThreadMutexDestroy(&pool_p->mutex);
if (pool_p->pool) taosMemoryFree(pool_p->pool);
if (pool_p->freeList) taosMemoryFree(pool_p->freeList);
memset(pool_p, 0, sizeof(*pool_p));
(void)memset(pool_p, 0, sizeof(*pool_p));
taosMemoryFree(pool_p);
}