提交 a4f75510 编写于 作者: S Shengliang Guan

TD-4088

上级 ac3d6440
......@@ -74,17 +74,9 @@ extern "C" {
#define TAOS_OS_FUNC_FILE_SENDIFLE
#define TAOS_OS_FUNC_SEMPHONE
typedef struct tsem_s *tsem_t;
int tsem_init(tsem_t *sem, int pshared, unsigned int value);
int tsem_wait(tsem_t *sem);
int tsem_post(tsem_t *sem);
int tsem_destroy(tsem_t *sem);
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
#define TAOS_OS_FUNC_SYSINFO
#define TAOS_OS_FUNC_TIMER
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD
#define TAOS_OS_FUNC_TIMERD
// specific
typedef int(*__compar_fn_t)(const void *, const void *);
......@@ -104,8 +96,6 @@ typedef int(*__compar_fn_t)(const void *, const void *);
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
#endif
#define TAOS_OS_FUNC_PTHREAD_RWLOCK
#include "eok.h"
void taos_block_sigalrm(void);
......
......@@ -20,15 +20,21 @@
extern "C" {
#endif
#ifndef TAOS_OS_FUNC_SEMPHONE
#if defined (_TD_DARWIN_64)
typedef struct tsem_s *tsem_t;
int tsem_init(tsem_t *sem, int pshared, unsigned int value);
int tsem_wait(tsem_t *sem);
int tsem_post(tsem_t *sem);
int tsem_destroy(tsem_t *sem);
#else
#define tsem_t sem_t
#define tsem_init sem_init
int tsem_wait(tsem_t* sem);
int32_t tsem_wait(tsem_t* sem);
#define tsem_post sem_post
#define tsem_destroy sem_destroy
#endif
#ifdef TAOS_OS_FUNC_PTHREAD_RWLOCK
#if defined (_TD_DARWIN_64)
#define pthread_rwlock_t pthread_mutex_t
#define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL)
#define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock)
......@@ -43,7 +49,6 @@ extern "C" {
#define pthread_spin_unlock(lock) pthread_mutex_unlock(lock)
#endif
// TAOS_OS_FUNC_SEMPHONE_PTHREAD
bool taosCheckPthreadValid(pthread_t thread);
int64_t taosGetSelfPthreadId();
int64_t taosGetPthreadId(pthread_t thread);
......
......@@ -28,7 +28,7 @@ extern "C" {
#else
#define tstrdup(str) strdup(str)
#define tstrndup(str, size) strndup(str, size)
#define tgetline(lineptr, n, stream) getline(lineptr, n , stream)
#define tgetline(lineptr, n, stream) getline(lineptr, n, stream)
#define twcslen wcslen
#endif
......
......@@ -65,7 +65,6 @@ extern "C" {
#define TAOS_OS_FUNC_FILE_FTRUNCATE
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD
#define TAOS_OS_FUNC_SOCKET
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
......
......@@ -37,7 +37,7 @@
static pthread_t sem_thread;
static pthread_once_t sem_once;
static task_t sem_port;
static volatile int sem_inited = 0;
static volatile int32_t sem_inited = 0;
static semaphore_t sem_exit;
static void* sem_thread_routine(void *arg) {
......@@ -55,7 +55,7 @@ static void* sem_thread_routine(void *arg) {
}
static void once_init(void) {
int r = 0;
int32_t r = 0;
r = pthread_create(&sem_thread, NULL, sem_thread_routine, NULL);
if (r) {
fprintf(stderr, "==%s[%d]%s()==failed to create thread\n", basename(__FILE__), __LINE__, __func__);
......@@ -81,10 +81,10 @@ struct tsem_s {
dispatch_semaphore_t sem;
#endif // SEM_USE_PTHREAD
volatile unsigned int valid:1;
volatile unsigned int32_t valid:1;
};
int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
int32_t tsem_init(tsem_t *sem, int32_t pshared, unsigned int32_t value) {
// fprintf(stderr, "==%s[%d]%s():[%p]==creating\n", basename(__FILE__), __LINE__, __func__, sem);
if (*sem) {
fprintf(stderr, "==%s[%d]%s():[%p]==already initialized\n", basename(__FILE__), __LINE__, __func__, sem);
......@@ -97,7 +97,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
}
#ifdef SEM_USE_PTHREAD
int r = pthread_mutex_init(&p->lock, NULL);
int32_t r = pthread_mutex_init(&p->lock, NULL);
do {
if (r) break;
r = pthread_cond_init(&p->cond, NULL);
......@@ -124,7 +124,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
p->sem = sem_open(name, O_CREAT|O_EXCL, pshared, value);
p->id = id;
if (p->sem!=SEM_FAILED) break;
int e = errno;
int32_t e = errno;
if (e==EEXIST) continue;
if (e==EINTR) continue;
fprintf(stderr, "==%s[%d]%s():[%p]==not created[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e));
......@@ -158,7 +158,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
return 0;
}
int tsem_wait(tsem_t *sem) {
int32_t tsem_wait(tsem_t *sem) {
if (!*sem) {
fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem);
abort();
......@@ -194,7 +194,7 @@ int tsem_wait(tsem_t *sem) {
#endif // SEM_USE_PTHREAD
}
int tsem_post(tsem_t *sem) {
int32_t tsem_post(tsem_t *sem) {
if (!*sem) {
fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem);
abort();
......@@ -230,7 +230,7 @@ int tsem_post(tsem_t *sem) {
#endif // SEM_USE_PTHREAD
}
int tsem_destroy(tsem_t *sem) {
int32_t tsem_destroy(tsem_t *sem) {
// fprintf(stderr, "==%s[%d]%s():[%p]==destroying\n", basename(__FILE__), __LINE__, __func__, sem);
if (!*sem) {
// fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem);
......@@ -264,9 +264,9 @@ int tsem_destroy(tsem_t *sem) {
#elif defined(SEM_USE_POSIX)
char name[NAME_MAX-4];
snprintf(name, sizeof(name), "/t%ld", p->id);
int r = sem_unlink(name);
int32_t r = sem_unlink(name);
if (r) {
int e = errno;
int32_t e = errno;
fprintf(stderr, "==%s[%d]%s():[%p]==unlink failed[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e));
abort();
}
......@@ -284,7 +284,7 @@ int tsem_destroy(tsem_t *sem) {
bool taosCheckPthreadValid(pthread_t thread) {
uint64_t id = 0;
int r = pthread_threadid_np(thread, &id);
int32_t r = pthread_threadid_np(thread, &id);
return r ? false : true;
}
......
......@@ -16,9 +16,9 @@
#define _DEFAULT_SOURCE
#include "os.h"
#ifndef TAOS_OS_FUNC_SEMPHONE
#if !defined (_TD_DARWIN_64)
int tsem_wait(tsem_t* sem) {
int32_t tsem_wait(tsem_t* sem) {
int ret = 0;
do {
ret = sem_wait(sem);
......@@ -28,9 +28,9 @@ int tsem_wait(tsem_t* sem) {
#endif
#ifndef TAOS_OS_FUNC_SEMPHONE_PTHREAD
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64))
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
int64_t taosGetSelfPthreadId() {
static __thread int id = 0;
......
......@@ -22,6 +22,7 @@ General Public License for more details. */
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#if STDC_HEADERS
#include <stdlib.h>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册