osThread.c 10.4 KB
Newer Older
wafwerar's avatar
wafwerar 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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
wafwerar's avatar
wafwerar 已提交
17
#include <pthread.h>
wafwerar's avatar
wafwerar 已提交
18 19
#include "os.h"

wafwerar's avatar
wafwerar 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg) {
  return pthread_create(tid, attr, start, arg);
}

int32_t taosThreadAttrDestroy(TdThreadAttr * attr) {
  return pthread_attr_destroy(attr);
}

int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate) {
  return pthread_attr_getdetachstate(attr, detachstate);
}

int32_t taosThreadAttrGetInheritSched(const TdThreadAttr * attr, int32_t *inheritsched) {
  return pthread_attr_getinheritsched(attr, inheritsched);
}

int32_t taosThreadAttrGetSchedParam(const TdThreadAttr * attr, struct sched_param *param) {
  return pthread_attr_getschedparam(attr, param);
}

int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy) {
  return pthread_attr_getschedpolicy(attr, policy);
}

int32_t taosThreadAttrGetScope(const TdThreadAttr * attr, int32_t *contentionscope) {
  return pthread_attr_getscope(attr, contentionscope);
}

int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize) {
  return pthread_attr_getstacksize(attr, stacksize);
}

int32_t taosThreadAttrInit(TdThreadAttr * attr) {
  return pthread_attr_init(attr);
}

int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate) {
  return pthread_attr_setdetachstate(attr, detachstate);
}

int32_t taosThreadAttrSetInheritSched(TdThreadAttr * attr, int32_t inheritsched) {
  return pthread_attr_setinheritsched(attr, inheritsched);
}

int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_param *param) {
  return pthread_attr_setschedparam(attr, param);
}

int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy) {
  return pthread_attr_setschedpolicy(attr, policy);
}

int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope) {
  return pthread_attr_setscope(attr, contentionscope);
}

int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t 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) {
  return pthread_cancel(thread);
}

int32_t taosThreadCondDestroy(TdThreadCond * cond) {
  return pthread_cond_destroy(cond);
}

int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr) {
  return pthread_cond_init(cond, attr);
}

int32_t taosThreadCondSignal(TdThreadCond * cond) {
  return pthread_cond_signal(cond);
}

int32_t taosThreadCondBroadcast(TdThreadCond * cond) {
  return pthread_cond_broadcast(cond);
}

int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex) {
  return pthread_cond_wait(cond, mutex);
}

int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime) {
  return pthread_cond_timedwait(cond, mutex, abstime);
}

int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr) {
  return pthread_condattr_destroy(attr);
}

int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared) {
  return pthread_condattr_getpshared(attr, pshared);
}

int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr) {
  return pthread_condattr_init(attr);
}

int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared) {
  return pthread_condattr_setpshared(attr, pshared);
}

int32_t taosThreadDetach(TdThread thread) {
  return pthread_detach(thread);
}
wafwerar's avatar
wafwerar 已提交
155

wafwerar's avatar
wafwerar 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
  return pthread_equal(t1, t2);
}

void taosThreadExit(void *valuePtr) {
  return pthread_exit(valuePtr);
}

int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
  return pthread_getschedparam(thread, policy, param);
}

void *taosThreadGetSpecific(TdThreadKey key) {
  return pthread_getspecific(key);
wafwerar's avatar
wafwerar 已提交
170 171
}

wafwerar's avatar
wafwerar 已提交
172 173
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
  return pthread_join(thread, valuePtr);
wafwerar's avatar
wafwerar 已提交
174 175
}

wafwerar's avatar
wafwerar 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189
int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *)) {
  return pthread_key_create(key, destructor);
}

int32_t taosThreadKeyDelete(TdThreadKey key) {
  return pthread_key_delete(key);
}

int32_t taosThreadKill(TdThread thread, int32_t sig) {
  return pthread_kill(thread, sig);
}

int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) {
  return pthread_mutex_consistent(mutex);
wafwerar's avatar
wafwerar 已提交
190 191 192
}

int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) {
wafwerar's avatar
wafwerar 已提交
193
  return pthread_mutex_destroy(mutex);
wafwerar's avatar
wafwerar 已提交
194 195
}

wafwerar's avatar
wafwerar 已提交
196 197
int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr) {
  return pthread_mutex_init(mutex, attr);
wafwerar's avatar
wafwerar 已提交
198 199
}

wafwerar's avatar
wafwerar 已提交
200 201
int32_t taosThreadMutexLock(TdThreadMutex * mutex) {
  return pthread_mutex_lock(mutex);
wafwerar's avatar
wafwerar 已提交
202 203
}

wafwerar's avatar
wafwerar 已提交
204 205
int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime) {
  return pthread_mutex_timedlock(mutex, abstime);
wafwerar's avatar
wafwerar 已提交
206 207
}

wafwerar's avatar
wafwerar 已提交
208 209
int32_t taosThreadMutexTryLock(TdThreadMutex * mutex) {
  return pthread_mutex_trylock(mutex);
wafwerar's avatar
wafwerar 已提交
210 211
}

wafwerar's avatar
wafwerar 已提交
212 213
int32_t taosThreadMutexUnlock(TdThreadMutex * mutex) {
  return pthread_mutex_unlock(mutex);
wafwerar's avatar
wafwerar 已提交
214 215
}

wafwerar's avatar
wafwerar 已提交
216 217
int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr) {
  return pthread_mutexattr_destroy(attr);
wafwerar's avatar
wafwerar 已提交
218 219
}

wafwerar's avatar
wafwerar 已提交
220 221
int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared) {
  return pthread_mutexattr_getpshared(attr, pshared);
wafwerar's avatar
wafwerar 已提交
222 223
}

wafwerar's avatar
wafwerar 已提交
224 225
int32_t taosThreadMutexAttrGetRobust(const TdThreadMutexAttr * attr, int32_t * robust) {
  return pthread_mutexattr_getrobust(attr, robust);
wafwerar's avatar
wafwerar 已提交
226 227
}

wafwerar's avatar
wafwerar 已提交
228 229
int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind) {
  return pthread_mutexattr_gettype(attr, kind);
wafwerar's avatar
wafwerar 已提交
230 231
}

wafwerar's avatar
wafwerar 已提交
232 233
int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr) {
  return pthread_mutexattr_init(attr);
wafwerar's avatar
wafwerar 已提交
234 235
}

wafwerar's avatar
wafwerar 已提交
236 237
int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared) {
  return pthread_mutexattr_setpshared(attr, pshared);
wafwerar's avatar
wafwerar 已提交
238 239
}

wafwerar's avatar
wafwerar 已提交
240 241
int32_t taosThreadMutexAttrSetRobust(TdThreadMutexAttr * attr, int32_t robust) {
  return pthread_mutexattr_setrobust(attr, robust);
wafwerar's avatar
wafwerar 已提交
242 243
}

wafwerar's avatar
wafwerar 已提交
244 245
int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr * attr, int32_t kind) {
  return pthread_mutexattr_settype(attr, kind);
wafwerar's avatar
wafwerar 已提交
246 247
}

wafwerar's avatar
wafwerar 已提交
248 249
int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void)) {
  return pthread_once(onceControl, initRoutine);
wafwerar's avatar
wafwerar 已提交
250 251
}

wafwerar's avatar
wafwerar 已提交
252 253
int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock) {
  return pthread_rwlock_destroy(rwlock);
wafwerar's avatar
wafwerar 已提交
254 255
}

wafwerar's avatar
wafwerar 已提交
256 257
int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr) {
  return pthread_rwlock_init(rwlock, attr);
wafwerar's avatar
wafwerar 已提交
258 259
}

wafwerar's avatar
wafwerar 已提交
260 261
int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) {
  return pthread_rwlock_rdlock(rwlock);
wafwerar's avatar
wafwerar 已提交
262 263
}

wafwerar's avatar
wafwerar 已提交
264 265
int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime) {
  return pthread_rwlock_timedrdlock(rwlock, abstime);
wafwerar's avatar
wafwerar 已提交
266 267
}

wafwerar's avatar
wafwerar 已提交
268 269
int32_t taosThreadRwlockTimedWrlock(TdThreadRwlock * rwlock, const struct timespec *abstime) {
  return pthread_rwlock_timedwrlock(rwlock, abstime);
wafwerar's avatar
wafwerar 已提交
270 271
}

wafwerar's avatar
wafwerar 已提交
272 273
int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock) {
  return pthread_rwlock_tryrdlock(rwlock);
wafwerar's avatar
wafwerar 已提交
274 275
}

wafwerar's avatar
wafwerar 已提交
276 277
int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock) {
  return pthread_rwlock_trywrlock(rwlock);
wafwerar's avatar
wafwerar 已提交
278 279
}

wafwerar's avatar
wafwerar 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock) {
  return pthread_rwlock_unlock(rwlock);
}

int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock) {
  return pthread_rwlock_wrlock(rwlock);
}

int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr) {
  return pthread_rwlockattr_destroy(attr);
}

int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared) {
  return pthread_rwlockattr_getpshared(attr, pshared);
}

int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr) {
  return pthread_rwlockattr_init(attr);
}

int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared) {
  return pthread_rwlockattr_setpshared(attr, pshared);
wafwerar's avatar
wafwerar 已提交
302 303 304
}

TdThread taosThreadSelf(void) {
wafwerar's avatar
wafwerar 已提交
305
  return pthread_self();
wafwerar's avatar
wafwerar 已提交
306 307
}

wafwerar's avatar
wafwerar 已提交
308 309 310
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
  return pthread_setcancelstate(state, oldstate);
}
wafwerar's avatar
wafwerar 已提交
311

wafwerar's avatar
wafwerar 已提交
312 313
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
  return pthread_setcanceltype(type, oldtype);
wafwerar's avatar
wafwerar 已提交
314 315
}

wafwerar's avatar
wafwerar 已提交
316 317
int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
  return pthread_setschedparam(thread, policy, param);
wafwerar's avatar
wafwerar 已提交
318 319
}

wafwerar's avatar
wafwerar 已提交
320 321
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
  return pthread_setspecific(key, value);
wafwerar's avatar
wafwerar 已提交
322 323
}

wafwerar's avatar
wafwerar 已提交
324 325
int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) {
  return pthread_spin_destroy(lock);
wafwerar's avatar
wafwerar 已提交
326 327
}

wafwerar's avatar
wafwerar 已提交
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) {
  return pthread_spin_init(lock, pshared);
}

int32_t taosThreadSpinLock(TdThreadSpinlock * lock) {
  return pthread_spin_lock(lock);
}

int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) {
  return pthread_spin_trylock(lock);
}

int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) {
  return pthread_spin_unlock(lock);
}

void taosThreadTestCancel(void) {
  return pthread_testcancel();
}

int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset) {
  return pthread_sigmask(how, set, oset);
}

int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig) {
  return sigwait(set, sig);
wafwerar's avatar
wafwerar 已提交
354
}