--- parser3/src/main/pa_threads.C 2001/01/29 11:53:42 1.2 +++ parser3/src/main/pa_threads.C 2020/12/15 17:10:37 1.7 @@ -1,57 +1,67 @@ -/* - $Id: pa_threads.C,v 1.2 2001/01/29 11:53:42 paf Exp $ +/** @file + Parser: simple Mutex realization class. + + Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ #include "pa_threads.h" -#ifdef MULTITHREAD +volatile const char * IDENT_PA_THREADS_C="$Id: pa_threads.C,v 1.7 2020/12/15 17:10:37 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 _MSC_VER -#ifdef MOD_PARSER +uint pa_get_thread_id() { + return GetCurrentThreadId(); +} -Mutex::Mutex() { - handle=reinterpret_cast(ap_create_mutex(0)); +Mutex::Mutex() : + handle(CreateMutex(NULL, FALSE, 0)) { } Mutex::~Mutex() { - ap_destroy_mutex(reinterpret_cast(handle)); + CloseHandle(handle); } void Mutex::acquire() { - ap_acquire_mutex(reinterpret_cast(handle)); + WaitForSingleObject(handle, INFINITE); } void Mutex::release() { - ap_release_mutex(reinterpret_cast(handle)); + ReleaseMutex(handle); } -#else// WIN32 +#else + +#include +#ifdef HAVE_GETTID +#include +#endif + +uint pa_get_thread_id() { +#ifdef HAVE_GETTID + return syscall(__NR_gettid); +#else + return 1; +#endif +} 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