fix(os): centos pthread spinlock error.

This commit is contained in:
afwerar 2022-04-18 20:52:10 +08:00
parent 63b0e304d4
commit 68b69be5fa
2 changed files with 29 additions and 42 deletions

View File

@ -22,6 +22,10 @@
extern "C" { extern "C" {
#endif #endif
#ifndef __USE_XOPEN2K
typedef pthread_mutex_t pthread_spinlock_t;
#endif
typedef pthread_t TdThread; typedef pthread_t TdThread;
typedef pthread_spinlock_t TdThreadSpinlock; typedef pthread_spinlock_t TdThreadSpinlock;
typedef pthread_mutex_t TdThreadMutex; typedef pthread_mutex_t TdThreadMutex;
@ -33,8 +37,6 @@ typedef pthread_rwlockattr_t TdThreadRwlockAttr;
typedef pthread_cond_t TdThreadCond; typedef pthread_cond_t TdThreadCond;
typedef pthread_condattr_t TdThreadCondAttr; typedef pthread_condattr_t TdThreadCondAttr;
typedef pthread_key_t TdThreadKey; typedef pthread_key_t TdThreadKey;
typedef pthread_barrier_t TdThreadBarrier;
typedef pthread_barrierattr_t TdThreadBarrierAttr;
#define taosThreadCleanupPush pthread_cleanup_push #define taosThreadCleanupPush pthread_cleanup_push
#define taosThreadCleanupPop pthread_cleanup_pop #define taosThreadCleanupPop pthread_cleanup_pop
@ -156,13 +158,6 @@ int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_para
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy); int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy);
int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope); int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope);
int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize); int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize);
int32_t taosThreadBarrierDestroy(TdThreadBarrier * barrier);
int32_t taosThreadBarrierInit(TdThreadBarrier * barrier, const TdThreadBarrierAttr * attr, uint32_t count);
int32_t taosThreadBarrierWait(TdThreadBarrier * barrier);
int32_t taosThreadBarrierAttrDestroy(TdThreadBarrierAttr * attr);
int32_t taosThreadBarrierAttrGetPshared(const TdThreadBarrierAttr * attr, int32_t *pshared);
int32_t taosThreadBarrierAttrInit(TdThreadBarrierAttr * attr);
int32_t taosThreadBarrierAttrSetPshared(TdThreadBarrierAttr * attr, int32_t pshared);
int32_t taosThreadCancel(TdThread thread); int32_t taosThreadCancel(TdThread thread);
int32_t taosThreadCondDestroy(TdThreadCond * cond); int32_t taosThreadCondDestroy(TdThreadCond * cond);
int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr); int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr);

View File

@ -77,34 +77,6 @@ int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize) {
return pthread_attr_setstacksize(attr, stacksize); return pthread_attr_setstacksize(attr, stacksize);
} }
int32_t taosThreadBarrierDestroy(TdThreadBarrier * barrier) {
return pthread_barrier_destroy(barrier);
}
int32_t taosThreadBarrierInit(TdThreadBarrier * barrier, const TdThreadBarrierAttr * attr, uint32_t count) {
return pthread_barrier_init(barrier, attr, count);
}
int32_t taosThreadBarrierWait(TdThreadBarrier * barrier) {
return pthread_barrier_wait(barrier);
}
int32_t taosThreadBarrierAttrDestroy(TdThreadBarrierAttr * attr) {
return pthread_barrierattr_destroy(attr);
}
int32_t taosThreadBarrierAttrGetPshared(const TdThreadBarrierAttr * attr, int32_t *pshared) {
return pthread_barrierattr_getpshared(attr, pshared);
}
int32_t taosThreadBarrierAttrInit(TdThreadBarrierAttr * attr) {
return pthread_barrierattr_init(attr);
}
int32_t taosThreadBarrierAttrSetPshared(TdThreadBarrierAttr * attr, int32_t pshared) {
return pthread_barrierattr_setpshared(attr, pshared);
}
int32_t taosThreadCancel(TdThread thread) { int32_t taosThreadCancel(TdThread thread) {
return pthread_cancel(thread); return pthread_cancel(thread);
} }
@ -322,23 +294,43 @@ int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
} }
int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) { int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) {
return pthread_spin_destroy(lock); #ifndef __USE_XOPEN2K
return pthread_mutex_destroy((pthread_mutex_t*)lock);
#else
return pthread_spin_destroy((pthread_spinlock_t*)lock);
#endif
} }
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) { int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) {
return pthread_spin_init(lock, pshared); #ifndef __USE_XOPEN2K
return pthread_mutex_init((pthread_mutex_t*)lock, pshared);
#else
return pthread_spin_init((pthread_spinlock_t*)lock, pshared);
#endif
} }
int32_t taosThreadSpinLock(TdThreadSpinlock * lock) { int32_t taosThreadSpinLock(TdThreadSpinlock * lock) {
return pthread_spin_lock(lock); #ifndef __USE_XOPEN2K
return pthread_mutex_lock((pthread_mutex_t*)lock);
#else
return pthread_spin_lock((pthread_spinlock_t*)lock);
#endif
} }
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) { int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) {
return pthread_spin_trylock(lock); #ifndef __USE_XOPEN2K
return pthread_mutex_trylock((pthread_mutex_t*)lock);
#else
return pthread_spin_trylock((pthread_spinlock_t*)lock);
#endif
} }
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) { int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) {
return pthread_spin_unlock(lock); #ifndef __USE_XOPEN2K
return pthread_mutex_unlock((pthread_mutex_t*)lock);
#else
return pthread_spin_unlock((pthread_spinlock_t*)lock);
#endif
} }
void taosThreadTestCancel(void) { void taosThreadTestCancel(void) {