/** @file Parser: simple Mutex realization class. Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ #include "pa_threads.h" volatile const char * IDENT_PA_THREADS_C="$Id: pa_threads.C,v 1.14 2026/10/29 20:33:33 moko Exp $" IDENT_PA_THREADS_H; Mutex global_mutex; #ifdef _MSC_VER uint pa_get_thread_id() { return GetCurrentThreadId(); } Mutex::Mutex() : handle(CreateMutex(NULL, FALSE, 0)) { } Mutex::~Mutex() { CloseHandle(handle); } void Mutex::acquire() { WaitForSingleObject(handle, INFINITE); } void Mutex::release() { ReleaseMutex(handle); } #else #include #ifdef HAVE_GETTID #include #endif #ifdef HAVE_THR_SELF extern "C" { // old FreeBSD requires it #include } #endif uint pa_get_thread_id() { #if defined(HAVE_GETTID) return syscall(__NR_gettid); #elif defined(HAVE_THR_SELF) long id; thr_self(&id); return id; #else return getpid(); #endif } Mutex::Mutex() { pthread_mutex_init(&handle, NULL); } Mutex::~Mutex() { pthread_mutex_destroy(&handle); } void Mutex::acquire() { pthread_mutex_lock(&handle); } void Mutex::release() { pthread_mutex_unlock(&handle); } #endif