提交 caf1e0e8 编写于 作者: wafwerar's avatar wafwerar

[TD-13759]<fix>: redefine thread api.

上级 2eb40c24
......@@ -22,7 +22,6 @@ extern "C" {
#include <assert.h>
#include <ctype.h>
#include <pthread.h>
#include <semaphore.h>
#include <regex.h>
......@@ -83,6 +82,7 @@ extern "C" {
#include "osMath.h"
#include "osMemory.h"
#include "osRand.h"
#include "osThread.h"
#include "osSemaphore.h"
#include "osSignal.h"
#include "osSleep.h"
......@@ -90,7 +90,6 @@ extern "C" {
#include "osString.h"
#include "osSysinfo.h"
#include "osSystem.h"
#include "osThread.h"
#include "osTime.h"
#include "osTimer.h"
#include "osTimezone.h"
......
......@@ -20,7 +20,6 @@
extern "C" {
#endif
#include <pthread.h>
#include <semaphore.h>
#if defined (_TD_DARWIN_64)
......@@ -38,25 +37,25 @@ extern "C" {
#endif
#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)
// #define pthread_rwlock_wrlock(lock) pthread_mutex_lock(lock)
// #define pthread_rwlock_rdlock(lock) pthread_mutex_lock(lock)
// #define pthread_rwlock_unlock(lock) pthread_mutex_unlock(lock)
// #define TdThreadRwlock TdThreadMutex
// #define taosThreadRwlockInit(lock, NULL) taosThreadMutexInit(lock, NULL)
// #define taosThreadRwlockDestroy(lock) taosThreadMutexDestroy(lock)
// #define taosThreadRwlockWrlock(lock) taosThreadMutexLock(lock)
// #define taosThreadRwlockRdlock(lock) taosThreadMutexLock(lock)
// #define taosThreadRwlockUnlock(lock) taosThreadMutexUnlock(lock)
#define pthread_spinlock_t pthread_mutex_t
#define pthread_spin_init(lock, NULL) pthread_mutex_init(lock, NULL)
#define pthread_spin_destroy(lock) pthread_mutex_destroy(lock)
#define pthread_spin_lock(lock) pthread_mutex_lock(lock)
#define pthread_spin_unlock(lock) pthread_mutex_unlock(lock)
#define TdThreadSpinlock TdThreadMutex
#define taosThreadSpinInit(lock, NULL) taosThreadMutexInit(lock, NULL)
#define taosThreadSpinDestroy(lock) taosThreadMutexDestroy(lock)
#define taosThreadSpinLock(lock) taosThreadMutexLock(lock)
#define taosThreadSpinUnlock(lock) taosThreadMutexUnlock(lock)
#endif
bool taosCheckPthreadValid(pthread_t thread);
bool taosCheckPthreadValid(TdThread thread);
int64_t taosGetSelfPthreadId();
int64_t taosGetPthreadId(pthread_t thread);
void taosResetPthread(pthread_t* thread);
bool taosComparePthread(pthread_t first, pthread_t second);
int64_t taosGetPthreadId(TdThread thread);
void taosResetPthread(TdThread* thread);
bool taosComparePthread(TdThread first, TdThread second);
int32_t taosGetPId();
int32_t taosGetAppName(char* name, int32_t* len);
......
......@@ -35,7 +35,7 @@ typedef int32_t TdUcs4;
#define wctomb WCTOMB_FUNC_TAOS_FORBID
#define wcstombs WCSTOMBS_FUNC_TAOS_FORBID
#define wcsncpy WCSNCPY_FUNC_TAOS_FORBID
#define wchar_t WCHAR_T_FUNC_TAOS_FORBID
#define wchar_t WCHAR_T_TYPE_TAOS_FORBID
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
......
......@@ -22,6 +22,94 @@
extern "C" {
#endif
typedef pthread_t TdThread;
typedef pthread_spinlock_t TdThreadSpinlock;
typedef pthread_mutex_t TdThreadMutex;
typedef pthread_mutexattr_t TdThreadMutexAttr;
typedef pthread_rwlock_t TdThreadRwlock;
typedef pthread_attr_t TdThreadAttr;
typedef pthread_once_t TdThreadOnce;
typedef pthread_rwlockattr_t TdThreadRwlockAttr;
typedef pthread_cond_t TdThreadCond;
typedef pthread_condattr_t TdThreadCondAttr;
#define taosThreadCleanupPush pthread_cleanup_push
#define taosThreadCleanupPop pthread_cleanup_pop
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define pthread_t PTHREAD_T_TYPE_TAOS_FORBID
#define pthread_spinlock_t PTHREAD_SPINLOCK_T_TYPE_TAOS_FORBID
#define pthread_mutex_t PTHREAD_MUTEX_T_TYPE_TAOS_FORBID
#define pthread_mutexattr_t PTHREAD_MUTEXATTR_T_TYPE_TAOS_FORBID
#define pthread_rwlock_t PTHREAD_RWLOCK_T_TYPE_TAOS_FORBID
#define pthread_attr_t PTHREAD_ATTR_T_TYPE_TAOS_FORBID
#define pthread_once_t PTHREAD_ONCE_T_TYPE_TAOS_FORBID
#define pthread_rwlockattr_t PTHREAD_RWLOCKATTR_T_TYPE_TAOS_FORBID
#define pthread_cond_t PTHREAD_COND_T_TYPE_TAOS_FORBID
#define pthread_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID
#define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID
#define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID
#define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID
#define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID
#define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID
#define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID
#define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID
#define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID
#define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID
#define pthread_attr_init PTHREAD_ATTR_INIT_FUNC_TAOS_FORBID
#define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID
#define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID
#define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE_FUNC_TAOS_FORBID
#define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID
#define pthread_join PTHREAD_JOIN_FUNC_TAOS_FORBID
#define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID
#define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID
#define pthread_cond_signal PTHREAD_COND_SIGNAL_FUNC_TAOS_FORBID
#define pthread_cond_init PTHREAD_COND_INIT_FUNC_TAOS_FORBID
#define pthread_cond_broadcast PTHREAD_COND_BROADCAST_FUNC_TAOS_FORBID
#define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID
#define pthread_cond_wait PTHREAD_COND_WAIT_FUNC_TAOS_FORBID
#define pthread_self PTHREAD_SELF_FUNC_TAOS_FORBID
#define pthread_equal PTHREAD_EQUAL_FUNC_TAOS_FORBID
#define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID
#define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID
#define pthread_kill PTHREAD_KILL_FUNC_TAOS_FORBID
#endif
int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int pshared);
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr);
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock);
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex);
int32_t taosThreadSpinLock(TdThreadSpinlock *lock);
int32_t taosThreadMutexLock(TdThreadMutex *mutex);
int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock);
int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock);
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex);
int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock);
int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock);
void taosThreadTestCancel(void);
int32_t taosThreadAttrInit(TdThreadAttr *attr);
int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void*(*start)(void*), void *arg);
int32_t taosThreadOnce(TdThreadOnce *onceControl, void(*initRoutine)(void));
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachState);
int32_t taosThreadAttrDestroy(TdThreadAttr *attr);
int32_t taosThreadJoin(TdThread thread, void **pValue);
int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr);
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock);
int32_t taosThreadCondSignal(TdThreadCond *cond);
int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr);
int32_t taosThreadCondBroadcast(TdThreadCond *cond);
int32_t taosThreadCondDestroy(TdThreadCond *cond);
int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex);
TdThread taosThreadSelf(void);
int32_t taosThreadEqual(TdThread t1, TdThread t2);
int32_t taosThreadSigmask(int how, sigset_t const *set, sigset_t *oset);
int32_t taosThreadCancel(TdThread thread);
int32_t taosThreadKill(TdThread thread, int sig);
#ifdef __cplusplus
}
#endif
......
......@@ -20,6 +20,11 @@
extern "C" {
#endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define tzset TZSET_FUNC_TAOS_FORBID
#endif
void taosGetSystemTimezone(char *outTimezone);
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight);
......
#include <assert.h>
#include <pthread.h>
#include <uv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "task.h"
#include <uv.h>
#define NUM_OF_THREAD 1
#define TIMEOUT 10000
typedef struct SThreadObj {
pthread_t thread;
TdThread thread;
uv_pipe_t *pipe;
uv_loop_t *loop;
uv_async_t *workerAsync; //
......@@ -183,7 +182,7 @@ int main() {
server->pThreadObj[i]->fd = fds[0];
server->pThreadObj[i]->pipe = &(server->pipe[i][1]); // init read
int err = pthread_create(&(server->pThreadObj[i]->thread), NULL,
int err = taosThreadCreate(&(server->pThreadObj[i]->thread), NULL,
worker_thread, (void *)(server->pThreadObj[i]));
if (err == 0) {
printf("thread %d create\n", i);
......
......@@ -24,11 +24,11 @@
#include <windows.h>
bool taosCheckPthreadValid(pthread_t thread) { return thread.p != NULL; }
bool taosCheckPthreadValid(TdThread thread) { return thread.p != NULL; }
void taosResetPthread(pthread_t* thread) { thread->p = 0; }
void taosResetPthread(TdThread* thread) { thread->p = 0; }
int64_t taosGetPthreadId(pthread_t thread) {
int64_t taosGetPthreadId(TdThread thread) {
#ifdef PTW32_VERSION
return pthread_getw32threadid_np(thread);
#else
......@@ -38,7 +38,7 @@ int64_t taosGetPthreadId(pthread_t thread) {
int64_t taosGetSelfPthreadId() { return GetCurrentThreadId(); }
bool taosComparePthread(pthread_t first, pthread_t second) { return first.p == second.p; }
bool taosComparePthread(TdThread first, TdThread second) { return first.p == second.p; }
int32_t taosGetPId() { return GetCurrentProcessId(); }
......@@ -84,10 +84,9 @@ int32_t tsem_wait(tsem_t* sem) {
#include <mach/mach_init.h>
#include <mach/semaphore.h>
#include <mach/task.h>
#include <pthread.h>
static pthread_t sem_thread;
static pthread_once_t sem_once;
static TdThread sem_thread;
static TdThreadOnce sem_once;
static task_t sem_port;
static volatile int sem_inited = 0;
static semaphore_t sem_exit;
......@@ -110,7 +109,7 @@ static void *sem_thread_routine(void *arg) {
static void once_init(void) {
int r = 0;
r = pthread_create(&sem_thread, NULL, sem_thread_routine, NULL);
r = taosThreadCreate(&sem_thread, NULL, sem_thread_routine, NULL);
if (r) {
fprintf(stderr, "==%s[%d]%s()==failed to create thread\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__);
return;
......@@ -123,8 +122,8 @@ static void once_init(void) {
struct tsem_s {
#ifdef SEM_USE_PTHREAD
pthread_mutex_t lock;
pthread_cond_t cond;
TdThreadMutex lock;
TdThreadCond cond;
volatile int64_t val;
#elif defined(SEM_USE_POSIX)
size_t id;
......@@ -151,12 +150,12 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
}
#ifdef SEM_USE_PTHREAD
int r = pthread_mutex_init(&p->lock, NULL);
int r = taosThreadMutexInit(&p->lock, NULL);
do {
if (r) break;
r = pthread_cond_init(&p->cond, NULL);
r = taosThreadCondInit(&p->cond, NULL);
if (r) {
pthread_mutex_destroy(&p->lock);
taosThreadMutexDestroy(&p->lock);
break;
}
p->val = value;
......@@ -186,7 +185,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
abort();
} while (p->sem == SEM_FAILED);
#elif defined(SEM_USE_SEM)
pthread_once(&sem_once, once_init);
taosThreadOnce(&sem_once, once_init);
if (sem_inited != 1) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal resource init failed\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
errno = ENOMEM;
......@@ -224,18 +223,18 @@ int tsem_wait(tsem_t *sem) {
abort();
}
#ifdef SEM_USE_PTHREAD
if (pthread_mutex_lock(&p->lock)) {
if (taosThreadMutexLock(&p->lock)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
p->val -= 1;
if (p->val < 0) {
if (pthread_cond_wait(&p->cond, &p->lock)) {
if (taosThreadCondWait(&p->cond, &p->lock)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
}
if (pthread_mutex_unlock(&p->lock)) {
if (taosThreadMutexUnlock(&p->lock)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
......@@ -260,18 +259,18 @@ int tsem_post(tsem_t *sem) {
abort();
}
#ifdef SEM_USE_PTHREAD
if (pthread_mutex_lock(&p->lock)) {
if (taosThreadMutexLock(&p->lock)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
p->val += 1;
if (p->val <= 0) {
if (pthread_cond_signal(&p->cond)) {
if (taosThreadCondSignal(&p->cond)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
}
if (pthread_mutex_unlock(&p->lock)) {
if (taosThreadMutexUnlock(&p->lock)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
......@@ -299,20 +298,20 @@ int tsem_destroy(tsem_t *sem) {
return 0;
}
#ifdef SEM_USE_PTHREAD
if (pthread_mutex_lock(&p->lock)) {
if (taosThreadMutexLock(&p->lock)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
p->valid = 0;
if (pthread_cond_destroy(&p->cond)) {
if (taosThreadCondDestroy(&p->cond)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
if (pthread_mutex_unlock(&p->lock)) {
if (taosThreadMutexUnlock(&p->lock)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
if (pthread_mutex_destroy(&p->lock)) {
if (taosThreadMutexDestroy(&p->lock)) {
fprintf(stderr, "==%s[%d]%s():[%p]==internal logic error\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__, sem);
abort();
}
......@@ -338,23 +337,23 @@ int tsem_destroy(tsem_t *sem) {
return 0;
}
bool taosCheckPthreadValid(pthread_t thread) {
bool taosCheckPthreadValid(TdThread thread) {
uint64_t id = 0;
int r = pthread_threadid_np(thread, &id);
int r = TdThreadhreadid_np(thread, &id);
return r ? false : true;
}
int64_t taosGetSelfPthreadId() {
uint64_t id;
pthread_threadid_np(0, &id);
TdThreadhreadid_np(0, &id);
return (int64_t)id;
}
int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; }
int64_t taosGetPthreadId(TdThread thread) { return (int64_t)thread; }
void taosResetPthread(pthread_t *thread) { *thread = NULL; }
void taosResetPthread(TdThread *thread) { *thread = NULL; }
bool taosComparePthread(pthread_t first, pthread_t second) { return pthread_equal(first, second) ? true : false; }
bool taosComparePthread(TdThread first, TdThread second) { return taosThreadEqual(first, second) ? true : false; }
int32_t taosGetPId() { return (int32_t)getpid(); }
......@@ -378,7 +377,7 @@ int32_t taosGetAppName(char *name, int32_t *len) {
#include <sys/syscall.h>
#include <unistd.h>
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
bool taosCheckPthreadValid(TdThread thread) { return thread != 0; }
int64_t taosGetSelfPthreadId() {
static __thread int id = 0;
......@@ -387,9 +386,9 @@ int64_t taosGetSelfPthreadId() {
return id;
}
int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; }
void taosResetPthread(pthread_t* thread) { *thread = 0; }
bool taosComparePthread(pthread_t first, pthread_t second) { return first == second; }
int64_t taosGetPthreadId(TdThread thread) { return (int64_t)thread; }
void taosResetPthread(TdThread* thread) { *thread = 0; }
bool taosComparePthread(TdThread first, TdThread second) { return first == second; }
int32_t taosGetPId() { return getpid(); }
int32_t taosGetAppName(char* name, int32_t* len) {
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#include "os.h"
// int32_t taosThreadSetnameNp(TdThread thread, const char *name) {
// return pthread_setname_np(thread,name);
// }
int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int pshared) {
return pthread_spin_init(lock, pshared);
}
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) {
return pthread_mutex_init(mutex, attr);
}
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) {
return pthread_spin_destroy(lock);
}
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) {
return pthread_mutex_destroy(mutex);
}
int32_t taosThreadSpinLock(TdThreadSpinlock *lock) {
return pthread_spin_lock(lock);
}
int32_t taosThreadMutexLock(TdThreadMutex *mutex) {
return pthread_mutex_lock(mutex);
}
int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) {
return pthread_spin_unlock(lock);
}
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) {
return pthread_mutex_unlock(mutex);
}
int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) {
return pthread_rwlock_rdlock(rwlock);
}
int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) {
return pthread_rwlock_wrlock(rwlock);
}
int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) {
return pthread_rwlock_unlock(rwlock);
}
void taosThreadTestCancel(void) {
return pthread_testcancel();
}
int32_t taosThreadAttrInit(TdThreadAttr *attr) {
return pthread_attr_init(attr);
}
int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void*(*start)(void*), void *arg) {
return pthread_create(tid, attr, start, arg);
}
int32_t taosThreadOnce(TdThreadOnce *onceControl, void(*initRoutine)(void)) {
return pthread_once(onceControl, initRoutine);
}
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachState) {
return pthread_attr_setdetachstate(attr, detachState);
}
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) {
return pthread_attr_destroy(attr);
}
int32_t taosThreadJoin(TdThread thread, void **pValue) {
return pthread_join(thread, pValue);
}
int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr) {
return pthread_rwlock_init(rwlock, attr);
}
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) {
return pthread_rwlock_destroy(rwlock);
}
int32_t taosThreadCondSignal(TdThreadCond *cond) {
return pthread_cond_signal(cond);
}
int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) {
return pthread_cond_init(cond, attr);
}
int32_t taosThreadCondBroadcast(TdThreadCond *cond) {
return pthread_cond_broadcast(cond);
}
int32_t taosThreadCondDestroy(TdThreadCond *cond) {
return pthread_cond_destroy(cond);
}
int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) {
return pthread_cond_wait(cond, mutex);
}
TdThread taosThreadSelf(void) {
return pthread_self();
}
// int32_t taosThreadGetW32ThreadIdNp(TdThread thread) {
// return pthread_getw32threadid_np(thread);
// }
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
return pthread_equal(t1, t2);
}
int32_t taosThreadSigmask(int how, sigset_t const *set, sigset_t *oset) {
return pthread_sigmask(how, set, oset);
}
int32_t taosThreadCancel(TdThread thread) {
return pthread_cancel(thread);
}
int32_t taosThreadKill(TdThread thread, int sig) {
return pthread_kill(thread, sig);
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include "os.h"
......
......@@ -5,10 +5,6 @@ target_include_directories(
util
PUBLIC "${CMAKE_SOURCE_DIR}/include/util"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
IF(${TD_WINDOWS})
PRIVATE "${CMAKE_SOURCE_DIR}/contrib/pthread-win32"
PRIVATE "${CMAKE_SOURCE_DIR}/contrib/gnuregex"
ENDIF ()
)
target_link_libraries(
util
......
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include "os.h"
......@@ -102,18 +101,18 @@ void *openRefSpace(void *param) {
pSpace->p = (void **) calloc(sizeof(void *), pSpace->refNum);
pSpace->rid = calloc(pSpace->refNum, sizeof(int64_t));
pthread_attr_t thattr;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
TdThreadAttr thattr;
taosThreadAttrInit(&thattr);
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
pthread_t thread1, thread2, thread3;
pthread_create(&(thread1), &thattr, addRef, (void *)(pSpace));
pthread_create(&(thread2), &thattr, removeRef, (void *)(pSpace));
pthread_create(&(thread3), &thattr, acquireRelease, (void *)(pSpace));
TdThread thread1, thread2, thread3;
taosThreadCreate(&(thread1), &thattr, addRef, (void *)(pSpace));
taosThreadCreate(&(thread2), &thattr, removeRef, (void *)(pSpace));
taosThreadCreate(&(thread3), &thattr, acquireRelease, (void *)(pSpace));
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
pthread_join(thread3, NULL);
taosThreadJoin(thread1, NULL);
taosThreadJoin(thread2, NULL);
taosThreadJoin(thread3, NULL);
for (int i=0; i<pSpace->refNum; ++i) {
taosRemoveRef(pSpace->rsetId, pSpace->rid[i]);
......@@ -161,22 +160,22 @@ int main(int argc, char *argv[]) {
taosInitLog("tref.log", 10);
SRefSpace *pSpaceList = (SRefSpace *) calloc(sizeof(SRefSpace), threads);
pthread_t *pThreadList = (pthread_t *) calloc(sizeof(pthread_t), threads);
TdThread *pThreadList = (TdThread *) calloc(sizeof(TdThread), threads);
pthread_attr_t thattr;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
TdThreadAttr thattr;
taosThreadAttrInit(&thattr);
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
for (int i=0; i<loops; ++i) {
printf("\nloop: %d\n", i);
for (int j=0; j<threads; ++j) {
pSpaceList[j].steps = steps;
pSpaceList[j].refNum = refNum;
pthread_create(&(pThreadList[j]), &thattr, openRefSpace, (void *)(pSpaceList+j));
taosThreadCreate(&(pThreadList[j]), &thattr, openRefSpace, (void *)(pSpaceList+j));
}
for (int j=0; j<threads; ++j) {
pthread_join(pThreadList[j], NULL);
taosThreadJoin(pThreadList[j], NULL);
}
}
......
// TAOS standard API example. The same syntax as MySQL, but only a subet
// to compile: gcc -o prepare prepare.c -ltaos
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -5067,11 +5066,11 @@ int main(int argc, char *argv[])
exit(1);
}
pthread_t *pThreadList = (pthread_t *) calloc(sizeof(pthread_t), 4);
TdThread *pThreadList = (TdThread *) calloc(sizeof(TdThread), 4);
pthread_attr_t thattr;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
TdThreadAttr thattr;
taosThreadAttrInit(&thattr);
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
T_par par[4];
par[0].taos = taos[0];
......@@ -5083,10 +5082,10 @@ int main(int argc, char *argv[])
par[3].taos = taos[3];
par[3].idx = 3;
pthread_create(&(pThreadList[0]), &thattr, runcase, (void *)&par[0]);
//pthread_create(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]);
//pthread_create(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]);
//pthread_create(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
taosThreadCreate(&(pThreadList[0]), &thattr, runcase, (void *)&par[0]);
//taosThreadCreate(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]);
//taosThreadCreate(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]);
//taosThreadCreate(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
while(1) {
taosSsleep(1);
......
// TAOS standard API example. The same syntax as MySQL, but only a subet
// to compile: gcc -o prepare prepare.c -ltaos
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -5080,7 +5079,7 @@ int main(int argc, char *argv[])
#if 0
printf("server:%s, threadNum:%d, rows:%d\n\n", serverIp, threadNum, g_rows);
pthread_t *pThreadList = (pthread_t *) calloc(sizeof(pthread_t), (size_t)threadNum);
TdThread *pThreadList = (TdThread *) calloc(sizeof(TdThread), (size_t)threadNum);
ThreadInfo* threadInfo = (ThreadInfo *) calloc(sizeof(ThreadInfo), (size_t)threadNum);
ThreadInfo* tInfo = threadInfo;
......@@ -5094,16 +5093,16 @@ int main(int argc, char *argv[])
tInfo->taos = taos;
tInfo->idx = i;
if (0 == i) {
//pthread_create(&(pThreadList[0]), NULL, runCase, (void *)tInfo);
pthread_create(&(pThreadList[0]), NULL, SpecifyColumnBatchCase, (void *)tInfo);
//taosThreadCreate(&(pThreadList[0]), NULL, runCase, (void *)tInfo);
taosThreadCreate(&(pThreadList[0]), NULL, SpecifyColumnBatchCase, (void *)tInfo);
} else if (1 == i){
pthread_create(&(pThreadList[0]), NULL, runCase_long, (void *)tInfo);
taosThreadCreate(&(pThreadList[0]), NULL, runCase_long, (void *)tInfo);
}
tInfo++;
}
for (int i = 0; i < threadNum; i++) {
pthread_join(pThreadList[i], NULL);
taosThreadJoin(pThreadList[i], NULL);
}
free(pThreadList);
......
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......
......@@ -5,12 +5,11 @@
#include <unistd.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <pthread.h>
#define MAXLINE 1024
typedef struct {
pthread_t pid;
TdThread pid;
int threadId;
int rows;
int tables;
......@@ -107,16 +106,16 @@ void multiThread() {
ThreadObj *threads = calloc((size_t)numOfThreads, sizeof(ThreadObj));
for (int i = 0; i < numOfThreads; i++) {
ThreadObj *pthread = threads + i;
pthread_attr_t thattr;
TdThreadAttr thattr;
pthread->threadId = i + 1;
pthread->rows = numOfRows;
pthread->tables = numOfTables;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
pthread_create(&pthread->pid, &thattr, (void *(*)(void *))execute, pthread);
taosThreadAttrInit(&thattr);
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
taosThreadCreate(&pthread->pid, &thattr, (void *(*)(void *))execute, pthread);
}
for (int i = 0; i < numOfThreads; i++) {
pthread_join(threads[i].pid, NULL);
taosThreadJoin(threads[i].pid, NULL);
}
free(threads);
}
......
......@@ -5,12 +5,11 @@
#include <unistd.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <pthread.h>
#define MAXLINE 1024
typedef struct {
pthread_t pid;
TdThread pid;
int threadId;
int rows;
int tables;
......@@ -107,16 +106,16 @@ void multiThread() {
ThreadObj *threads = calloc((size_t)numOfThreads, sizeof(ThreadObj));
for (int i = 0; i < numOfThreads; i++) {
ThreadObj *pthread = threads + i;
pthread_attr_t thattr;
TdThreadAttr thattr;
pthread->threadId = i + 1;
pthread->rows = numOfRows;
pthread->tables = numOfTables;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
pthread_create(&pthread->pid, &thattr, (void *(*)(void *))execute, pthread);
taosThreadAttrInit(&thattr);
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
taosThreadCreate(&pthread->pid, &thattr, (void *(*)(void *))execute, pthread);
}
for (int i = 0; i < numOfThreads; i++) {
pthread_join(threads[i].pid, NULL);
taosThreadJoin(threads[i].pid, NULL);
}
free(threads);
}
......
......@@ -5,12 +5,11 @@
#include <unistd.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <pthread.h>
#define MAXLINE 1024
typedef struct {
pthread_t pid;
TdThread pid;
int threadId;
int rows;
int tables;
......@@ -107,16 +106,16 @@ void multiThread() {
ThreadObj *threads = calloc((size_t)numOfThreads, sizeof(ThreadObj));
for (int i = 0; i < numOfThreads; i++) {
ThreadObj *pthread = threads + i;
pthread_attr_t thattr;
TdThreadAttr thattr;
pthread->threadId = i + 1;
pthread->rows = numOfRows;
pthread->tables = numOfTables;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
pthread_create(&pthread->pid, &thattr, (void *(*)(void *))execute, pthread);
taosThreadAttrInit(&thattr);
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
taosThreadCreate(&pthread->pid, &thattr, (void *(*)(void *))execute, pthread);
}
for (int i = 0; i < numOfThreads; i++) {
pthread_join(threads[i].pid, NULL);
taosThreadJoin(threads[i].pid, NULL);
}
free(threads);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册