提交 82ce093a 编写于 作者: weixin_48148422's avatar weixin_48148422

TBASE-870: fix link error in windows

上级 128a49fc
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
#define __sync_add_and_fetch_64 __sync_add_and_fetch #define __sync_add_and_fetch_64 __sync_add_and_fetch
#define __sync_add_and_fetch_32 __sync_add_and_fetch #define __sync_add_and_fetch_32 __sync_add_and_fetch
#define __sync_add_and_fetch_16 __sync_add_and_fetch #define __sync_add_and_fetch_16 __sync_add_and_fetch
#define __sync_add_and_fetch_ptr __sync_add_and_fetch
#define __sync_add_and_fetch_8 __sync_add_and_fetch #define __sync_add_and_fetch_8 __sync_add_and_fetch
#define __sync_add_and_fetch_ptr __sync_add_and_fetch
#define __sync_sub_and_fetch_64 __sync_sub_and_fetch #define __sync_sub_and_fetch_64 __sync_sub_and_fetch
#define __sync_sub_and_fetch_32 __sync_sub_and_fetch #define __sync_sub_and_fetch_32 __sync_sub_and_fetch
......
...@@ -100,8 +100,8 @@ extern "C" { ...@@ -100,8 +100,8 @@ extern "C" {
#define __sync_add_and_fetch_64 __sync_add_and_fetch #define __sync_add_and_fetch_64 __sync_add_and_fetch
#define __sync_add_and_fetch_32 __sync_add_and_fetch #define __sync_add_and_fetch_32 __sync_add_and_fetch
#define __sync_add_and_fetch_16 __sync_add_and_fetch #define __sync_add_and_fetch_16 __sync_add_and_fetch
#define __sync_add_and_fetch_ptr __sync_add_and_fetch
#define __sync_add_and_fetch_8 __sync_add_and_fetch #define __sync_add_and_fetch_8 __sync_add_and_fetch
#define __sync_add_and_fetch_ptr __sync_add_and_fetch
#define __sync_sub_and_fetch_64 __sync_sub_and_fetch #define __sync_sub_and_fetch_64 __sync_sub_and_fetch
#define __sync_sub_and_fetch_32 __sync_sub_and_fetch #define __sync_sub_and_fetch_32 __sync_sub_and_fetch
......
...@@ -127,16 +127,19 @@ extern "C" { ...@@ -127,16 +127,19 @@ extern "C" {
#define __sync_val_compare_and_swap_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval)) #define __sync_val_compare_and_swap_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
#define __sync_val_compare_and_swap_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval)) #define __sync_val_compare_and_swap_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
char interlocked_add_8(char volatile* ptr, char val); char interlocked_add_8(char volatile *ptr, char val);
short interlocked_add_16(short volatile* ptr, short val); short interlocked_add_16(short volatile *ptr, short val);
long interlocked_add_32(long volatile *ptr, long val);
__int64 interlocked_add_64(__int64 volatile *ptr, __int64 val);
#define __sync_add_and_fetch_8(ptr, val) interlocked_add_8((char volatile*)(ptr), (char)(val)) #define __sync_add_and_fetch_8(ptr, val) interlocked_add_8((char volatile*)(ptr), (char)(val))
#define __sync_add_and_fetch_16(ptr, val) interlocked_add_16((short volatile*)(ptr), (short)(val)) #define __sync_add_and_fetch_16(ptr, val) interlocked_add_16((short volatile*)(ptr), (short)(val))
#define __sync_add_and_fetch_32(ptr, val) _InterlockedAdd((long volatile*)(ptr), (long)(val)) #define __sync_add_and_fetch_32(ptr, val) interlocked_add_32((long volatile*)(ptr), (long)(val))
#define __sync_add_and_fetch_64(ptr, val) _InterlockedAdd64((__int64 volatile*)(ptr), (__int64)(val)) #define __sync_add_and_fetch_64(ptr, val) interlocked_add_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64 #ifdef _WIN64
#define __sync_add_and_fetch_ptr atomic_add_fetch_64 #define __sync_add_and_fetch_ptr __sync_add_and_fetch_64
#else #else
#define __sync_add_and_fetch_ptr atomic_add_fetch_32 #define __sync_add_and_fetch_ptr __sync_add_and_fetch_32
#endif #endif
#define __sync_sub_and_fetch_8(ptr, val) __sync_add_and_fetch_8((ptr), -(val)) #define __sync_sub_and_fetch_8(ptr, val) __sync_add_and_fetch_8((ptr), -(val))
......
...@@ -43,8 +43,11 @@ void taosResetPthread(pthread_t *thread) { ...@@ -43,8 +43,11 @@ void taosResetPthread(pthread_t *thread) {
} }
int64_t taosGetPthreadId() { int64_t taosGetPthreadId() {
pthread_t id = pthread_self(); #ifdef PTW32_VERSION
return (int64_t)id.p; return pthread_getw32threadid_np(pthread_self());
#else
return (int64_t)pthread_self();
#endif
} }
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) { int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) {
...@@ -72,6 +75,14 @@ short interlocked_add_16(short volatile* ptr, short val) { ...@@ -72,6 +75,14 @@ short interlocked_add_16(short volatile* ptr, short val) {
return _InterlockedExchangeAdd16(ptr, val) + val; return _InterlockedExchangeAdd16(ptr, val) + val;
} }
long interlocked_add_32(long volatile* ptr, long val) {
return _InterlockedExchangeAdd(ptr, val) + val;
}
__int64 interlocked_add_64(__int64 volatile* ptr, __int64 val) {
return _InterlockedExchangeAdd64(ptr, val) + val;
}
int32_t __sync_val_load_32(int32_t *ptr) { int32_t __sync_val_load_32(int32_t *ptr) {
return InterlockedOr(ptr, 0); return InterlockedOr(ptr, 0);
} }
......
...@@ -27,15 +27,6 @@ ...@@ -27,15 +27,6 @@
#include "tutil.h" #include "tutil.h"
static uintptr_t pthreadGetId() {
#ifdef PTW32_VERSION
return pthread_getw32threadid_np(pthread_self());
#else
assert(sizeof(pthread_t) == sizeof(uintptr_t));
return (uintptr_t)pthread_self();
#endif
}
#define TIMER_STATE_WAITING 0 #define TIMER_STATE_WAITING 0
#define TIMER_STATE_EXPIRED 1 #define TIMER_STATE_EXPIRED 1
#define TIMER_STATE_STOPPED 2 #define TIMER_STATE_STOPPED 2
...@@ -63,15 +54,15 @@ typedef struct tmr_obj_t { ...@@ -63,15 +54,15 @@ typedef struct tmr_obj_t {
uint8_t reserved1; uint8_t reserved1;
uint16_t reserved2; uint16_t reserved2;
union { union {
int64_t expireAt; int64_t expireAt;
uintptr_t executedBy; int64_t executedBy;
}; };
TAOS_TMR_CALLBACK fp; TAOS_TMR_CALLBACK fp;
void* param; void* param;
} tmr_obj_t; } tmr_obj_t;
typedef struct timer_list_t { typedef struct timer_list_t {
uintptr_t lockedBy; int64_t lockedBy;
tmr_obj_t* timers; tmr_obj_t* timers;
} timer_list_t; } timer_list_t;
...@@ -125,9 +116,9 @@ static void timerDecRef(tmr_obj_t* timer) { ...@@ -125,9 +116,9 @@ static void timerDecRef(tmr_obj_t* timer) {
} }
static void lockTimerList(timer_list_t* list) { static void lockTimerList(timer_list_t* list) {
uintptr_t tid = pthreadGetId(); int64_t tid = taosGetPthreadId();
int i = 0; int i = 0;
while (__sync_val_compare_and_swap_ptr(&(list->lockedBy), 0, tid) != 0) { while (__sync_val_compare_and_swap_64(&(list->lockedBy), 0, tid) != 0) {
if (++i % 1000 == 0) { if (++i % 1000 == 0) {
sched_yield(); sched_yield();
} }
...@@ -135,8 +126,8 @@ static void lockTimerList(timer_list_t* list) { ...@@ -135,8 +126,8 @@ static void lockTimerList(timer_list_t* list) {
} }
static void unlockTimerList(timer_list_t* list) { static void unlockTimerList(timer_list_t* list) {
uintptr_t tid = pthreadGetId(); int64_t tid = taosGetPthreadId();
if (__sync_val_compare_and_swap_ptr(&(list->lockedBy), tid, 0) != tid) { if (__sync_val_compare_and_swap_64(&(list->lockedBy), tid, 0) != tid) {
assert(false); assert(false);
tmrError("trying to unlock a timer list not locked by current thread."); tmrError("trying to unlock a timer list not locked by current thread.");
} }
...@@ -262,7 +253,7 @@ static bool removeFromWheel(tmr_obj_t* timer) { ...@@ -262,7 +253,7 @@ static bool removeFromWheel(tmr_obj_t* timer) {
static void processExpiredTimer(void* handle, void* arg) { static void processExpiredTimer(void* handle, void* arg) {
tmr_obj_t* timer = (tmr_obj_t*)handle; tmr_obj_t* timer = (tmr_obj_t*)handle;
timer->executedBy = pthreadGetId(); timer->executedBy = taosGetPthreadId();
uint8_t state = __sync_val_compare_and_swap_8(&timer->state, TIMER_STATE_WAITING, TIMER_STATE_EXPIRED); uint8_t state = __sync_val_compare_and_swap_8(&timer->state, TIMER_STATE_WAITING, TIMER_STATE_EXPIRED);
if (state == TIMER_STATE_WAITING) { if (state == TIMER_STATE_WAITING) {
const char* fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] execution start."; const char* fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] execution start.";
...@@ -402,12 +393,12 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) { ...@@ -402,12 +393,12 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param); tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param);
} else if (state != TIMER_STATE_EXPIRED) { } else if (state != TIMER_STATE_EXPIRED) {
// timer already stopped or cancelled, has nothing to do in this case // timer already stopped or cancelled, has nothing to do in this case
} else if (timer->executedBy == pthreadGetId()) { } else if (timer->executedBy == taosGetPthreadId()) {
// taosTmrReset is called in the timer callback, should do nothing in this // taosTmrReset is called in the timer callback, should do nothing in this
// case to avoid dead lock. note taosTmrReset must be the last statement // case to avoid dead lock. note taosTmrReset must be the last statement
// of the callback funtion, will be a bug otherwise. // of the callback funtion, will be a bug otherwise.
} else { } else {
assert(timer->executedBy != pthreadGetId()); assert(timer->executedBy != taosGetPthreadId());
const char* fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] fired, waiting..."; const char* fmt = "timer[label=%s, id=%lld, fp=%p, param=%p] fired, waiting...";
tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param); tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册