TDengine/include/os/osSemaphore.h

114 lines
3.4 KiB
C
Raw Normal View History

2020-07-31 06:18:23 +00:00
/*
* 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/>.
*/
2021-09-30 09:10:36 +00:00
#ifndef _TD_OS_SEMPHONE_H_
#define _TD_OS_SEMPHONE_H_
2020-07-31 06:18:23 +00:00
#ifdef __cplusplus
extern "C" {
#endif
#include <semaphore.h>
2022-04-22 11:47:00 +00:00
#if defined(_TD_DARWIN_64)
2022-08-26 08:03:28 +00:00
#include <dispatch/dispatch.h>
2022-07-02 09:40:23 +00:00
// typedef struct tsem_s *tsem_t;
2022-08-26 08:03:28 +00:00
typedef dispatch_semaphore_t tsem_t;
2022-04-22 11:47:00 +00:00
int tsem_init(tsem_t *sem, int pshared, unsigned int value);
int tsem_wait(tsem_t *sem);
2022-11-25 04:41:54 +00:00
int tsem_timewait(tsem_t *sim, int64_t milis);
2022-04-22 11:47:00 +00:00
int tsem_post(tsem_t *sem);
int tsem_destroy(tsem_t *sem);
2024-05-15 08:18:36 +00:00
#define tsem2_t tsem_t
#define tsem2_init tsem_init
2024-05-15 06:57:14 +00:00
#define tsem2_wait tsem_wait
#define tsem2_timewait tsem_timewait
2024-05-15 08:18:36 +00:00
#define tsem2_post tsem_post
#define tsem2_destroy tsem_destroy
2024-05-15 06:57:14 +00:00
2023-09-26 12:48:56 +00:00
#elif defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#include <windows.h>
#define tsem_t HANDLE
int tsem_init(tsem_t *sem, int pshared, unsigned int value);
int tsem_wait(tsem_t *sem);
int tsem_timewait(tsem_t *sim, int64_t milis);
int tsem_post(tsem_t *sem);
int tsem_destroy(tsem_t *sem);
2024-05-15 08:18:36 +00:00
#define tsem2_t tsem_t
#define tsem2_init tsem_init
2024-05-15 06:57:14 +00:00
#define tsem2_wait tsem_wait
#define tsem2_timewait tsem_timewait
2024-05-15 08:18:36 +00:00
#define tsem2_post tsem_post
#define tsem2_destroy tsem_destroy
2024-05-15 06:57:14 +00:00
2021-05-08 07:19:15 +00:00
#else
2022-04-22 11:47:00 +00:00
2024-05-15 06:57:14 +00:00
#define tsem_t sem_t
#define tsem_init sem_init
int tsem_wait(tsem_t *sem);
int tsem_timewait(tsem_t *sim, int64_t milis);
#define tsem_post sem_post
#define tsem_destroy sem_destroy
typedef struct tsem2_t {
2024-05-14 03:04:42 +00:00
TdThreadMutex mutex;
TdThreadCond cond;
TdThreadCondAttr attr;
int count;
2024-05-15 06:57:14 +00:00
} tsem2_t;
// #define tsem2_t sem_t
int tsem2_init(tsem2_t* sem, int pshared, unsigned int value);
int tsem2_wait(tsem2_t* sem);
int tsem2_timewait(tsem2_t* sem, int64_t milis);
int tsem2_post(tsem2_t* sem);
int tsem2_destroy(tsem2_t* sem);
2022-04-22 11:47:00 +00:00
2020-07-31 06:18:23 +00:00
#endif
2022-04-22 11:47:00 +00:00
#if defined(_TD_DARWIN_64)
2022-03-19 16:45:00 +00:00
// #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)
2021-02-01 07:59:17 +00:00
2022-07-02 09:40:23 +00:00
// #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)
2021-02-01 07:39:45 +00:00
#endif
2022-03-19 16:45:00 +00:00
bool taosCheckPthreadValid(TdThread thread);
2020-12-30 06:43:50 +00:00
int64_t taosGetSelfPthreadId();
2022-03-19 16:45:00 +00:00
int64_t taosGetPthreadId(TdThread thread);
2022-04-22 11:47:00 +00:00
void taosResetPthread(TdThread *thread);
2022-03-19 16:45:00 +00:00
bool taosComparePthread(TdThread first, TdThread second);
2020-10-10 01:45:18 +00:00
int32_t taosGetPId();
2022-04-22 11:47:00 +00:00
int32_t taosGetAppName(char *name, int32_t *len);
2020-07-31 07:23:05 +00:00
2020-07-31 06:18:23 +00:00
#ifdef __cplusplus
}
#endif
2021-09-30 09:10:36 +00:00
#endif /*_TD_OS_SEMPHONE_H_*/