提交 f2e9c64d 编写于 作者: dengyihao's avatar dengyihao

add timeout to auth

上级 ac22fa74
...@@ -195,6 +195,7 @@ int tsem_wait(tsem_t *sem) { ...@@ -195,6 +195,7 @@ int tsem_wait(tsem_t *sem) {
#endif // SEM_USE_PTHREAD #endif // SEM_USE_PTHREAD
} }
int tsem_post(tsem_t *sem) { int tsem_post(tsem_t *sem) {
if (!*sem) { if (!*sem) {
fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#if !defined (_TD_DARWIN_64) #if !defined(_TD_DARWIN_64)
int32_t tsem_wait(tsem_t* sem) { int32_t tsem_wait(tsem_t* sem) {
int ret = 0; int ret = 0;
...@@ -28,7 +28,25 @@ int32_t tsem_wait(tsem_t* sem) { ...@@ -28,7 +28,25 @@ int32_t tsem_wait(tsem_t* sem) {
#endif #endif
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64)) #if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_64))
int32_t tsem_timewait(tsem_t* sem, int64_t ms) {
int ret = 0;
struct timespec ts = {0};
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
return -1;
}
ts.tv_nsec += ms * 1000000;
ts.tv_sec += ts.tv_nsec / 1000000000;
ts.tv_nsec %= 1000000000;
while ((ret = sem_timedwait(sem, &ts)) == -1 && errno == EINTR) continue;
return ret;
}
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
...@@ -40,13 +58,13 @@ int64_t taosGetSelfPthreadId() { ...@@ -40,13 +58,13 @@ int64_t taosGetSelfPthreadId() {
} }
int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; } int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; }
void taosResetPthread(pthread_t *thread) { *thread = 0; } void taosResetPthread(pthread_t* thread) { *thread = 0; }
bool taosComparePthread(pthread_t first, pthread_t second) { return first == second; } bool taosComparePthread(pthread_t first, pthread_t second) { return first == second; }
int32_t taosGetPId() { return getpid(); } int32_t taosGetPId() { return getpid(); }
int32_t taosGetCurrentAPPName(char *name, int32_t* len) { int32_t taosGetCurrentAPPName(char* name, int32_t* len) {
const char* self = "/proc/self/exe"; const char* self = "/proc/self/exe";
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
if (readlink(self, path, PATH_MAX) <= 0) { if (readlink(self, path, PATH_MAX) <= 0) {
return -1; return -1;
...@@ -70,3 +88,43 @@ int32_t taosGetCurrentAPPName(char *name, int32_t* len) { ...@@ -70,3 +88,43 @@ int32_t taosGetCurrentAPPName(char *name, int32_t* len) {
} }
#endif #endif
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
int32_t tsem_timewait(tsem_t* sem, int64_t ms) {
struct timespec ts;
taosClockGetTime(0, &ts);
ts.tv_nsec += ms * 1000000;
ts.tv_sec += ts.tv_nsec / 1000000000;
ts.tv_nsec %= 1000000000;
int rc;
while ((rc = sem_timedwait(sem, &ts)) == -1 && errno == EINTR) continue;
return rc;
/* This should have timed out */
// ASSERT(errno == ETIMEDOUT);
// ASSERT(rc != 0);
// GetSystemTimeAsFileTime(&ft_after);
// // We specified a non-zero wait. Time must advance.
// if (ft_before.dwLowDateTime == ft_after.dwLowDateTime && ft_before.dwHighDateTime == ft_after.dwHighDateTime)
// {
// printf("nanoseconds: %d, rc: %d, code:0x%x. before filetime: %d, %d; after filetime: %d, %d\n",
// nanosecs, rc, errno,
// (int)ft_before.dwLowDateTime, (int)ft_before.dwHighDateTime,
// (int)ft_after.dwLowDateTime, (int)ft_after.dwHighDateTime);
// printf("time must advance during sem_timedwait.");
// return 1;
// }
}
#endif
#if defined(_TD_DARWIN_64)
int tsem_timewait(tsem_t* psem, int64_t milis) {
if (psem == NULL || *psem == NULL) return -1;
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(milis * USEC_PER_SEC));
dispatch_semaphore_wait(*psem, time);
return 0;
}
#endif
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册