1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include "mutex_posix.h"
- #include "core/os/memory.h"
- #if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
- void MutexPosix::lock() {
- pthread_mutex_lock(&mutex);
- }
- void MutexPosix::unlock() {
- pthread_mutex_unlock(&mutex);
- }
- Error MutexPosix::try_lock() {
- return (pthread_mutex_trylock(&mutex) == 0) ? OK : ERR_BUSY;
- }
- Mutex *MutexPosix::create_func_posix(bool p_recursive) {
- return memnew(MutexPosix(p_recursive));
- }
- void MutexPosix::make_default() {
- create_func = create_func_posix;
- }
- MutexPosix::MutexPosix(bool p_recursive) {
- pthread_mutexattr_init(&attr);
- if (p_recursive)
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&mutex, &attr);
- }
- MutexPosix::~MutexPosix() {
- pthread_mutex_destroy(&mutex);
- }
- #endif
|