--- parser3/src/main/pa_threads.C 2001/01/29 11:53:42 1.2 +++ parser3/src/main/pa_threads.C 2020/12/11 14:59:36 1.4 @@ -1,57 +1,62 @@ -/* - $Id: pa_threads.C,v 1.2 2001/01/29 11:53:42 paf Exp $ +/** @file + Parser: simple Mutex realization class. + + Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ +#include #include "pa_threads.h" -#ifdef MULTITHREAD +volatile const char * IDENT_PA_THREADS_C="$Id: pa_threads.C,v 1.4 2020/12/11 14:59:36 moko Exp $" IDENT_PA_THREADS_H; Mutex global_mutex; -// either apache module or win32 prog for now -#ifdef MOD_PARSER -# include "ap_config.h" -#else// WIN32 -# include -#endif +#ifdef WIN32 +#include -#ifdef MOD_PARSER +uint pa_get_thread_id() { + return GetCurrentThreadId(); +} -Mutex::Mutex() { - handle=reinterpret_cast(ap_create_mutex(0)); +Mutex::Mutex() : + handle(reinterpret_cast(CreateMutex(NULL, FALSE, 0))) { } Mutex::~Mutex() { - ap_destroy_mutex(reinterpret_cast(handle)); + CloseHandle(reinterpret_cast(handle)); } void Mutex::acquire() { - ap_acquire_mutex(reinterpret_cast(handle)); + WaitForSingleObject(reinterpret_cast(handle), INFINITE); } void Mutex::release() { - ap_release_mutex(reinterpret_cast(handle)); + ReleaseMutex(reinterpret_cast(handle)); } -#else// WIN32 +#else + +#include +uint pa_get_thread_id() { + return syscall(__NR_gettid); +} Mutex::Mutex() { - handle=CreateMutex(NULL, FALSE, 0); + pthread_mutex_init(&handle, NULL); } Mutex::~Mutex() { - CloseHandle(handle); + pthread_mutex_destroy(&handle); } void Mutex::acquire() { - WaitForSingleObject(handle, INFINITE); + pthread_mutex_lock(&handle); } void Mutex::release() { - ReleaseMutex(handle); + pthread_mutex_unlock(&handle); } #endif - -#endif