1 /* 2 * Copyright (C) 2021 Alibaba Group Holding Limited 3 */ 4 5 /* Support newlib internal locks */ 6 7 #ifndef _SYS_LOCK_H 8 #define _SYS_LOCK_H 9 10 #include <pthread.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #define _LOCK_T pthread_mutex_t 17 #define _LOCK_RECURSIVE_T pthread_mutex_t 18 19 #define __LOCK_INIT(class, lock) \ 20 class _LOCK_T lock = PTHREAD_MUTEX_INITIALIZER; 21 #define __LOCK_INIT_RECURSIVE(class, lock) __LOCK_INIT(class, lock) 22 23 #define __lock_init(_lock) pthread_mutex_init(&_lock, NULL) 24 #define __lock_acquire(_lock) pthread_mutex_lock(&_lock) 25 #define __lock_try_acquire(lock) pthread_mutex_trylock(&_lock) 26 #define __lock_release(_lock) pthread_mutex_unlock(&_lock) 27 #define __lock_close(_lock) pthread_mutex_destroy(&_lock) 28 29 #define __lock_init_recursive(_lock) pthread_mutex_init(&_lock, NULL) 30 #define __lock_acquire_recursive(_lock) pthread_mutex_lock(&_lock) 31 #define __lock_try_acquire_recursive(lock) pthread_mutex_trylock(&_lock) 32 #define __lock_release_recursive(_lock) pthread_mutex_unlock(&_lock) 33 #define __lock_close_recursive(_lock) pthread_mutex_destroy(&_lock) 34 35 #ifdef __cplusplus 36 } 37 #endif 38 39 #endif /*_SYS_LOCK_H*/ 40