|
|
| version 1.30, 2005/08/09 08:14:50 | version 1.36, 2020/12/15 11:28:40 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: mutex & helpers decls. | Parser: mutex & helpers decls. |
| Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| #ifndef PA_THREADS_H | #ifndef PA_THREADS_H |
| #define PA_THREADS_H | #define PA_THREADS_H |
| static const char * const IDENT_THREADS_H="$Date$"; | #define IDENT_PA_THREADS_H "$Id$" |
| #include "pa_config_includes.h" | #include "pa_config_includes.h" |
| #include "pa_types.h" | #include "pa_types.h" |
| /// thread ID type | #ifdef _MSC_VER |
| typedef unsigned int pa_thread_t; | #include <windows.h> |
| #endif | |
| /// get caller thread ID | /// get caller thread ID |
| pa_thread_t pa_get_thread_id(); | uint pa_get_thread_id(); |
| class AutoSYNCHRONIZED; | class AutoSYNCHRONIZED; |
| /// simple semaphore object | /// simple semaphore object |
| class Mutex { | class Mutex { |
| friend class AutoSYNCHRONIZED; | friend class AutoSYNCHRONIZED; |
| private: | |
| uint handle; | #ifdef _MSC_VER |
| HANDLE handle; | |
| #else | |
| pthread_mutex_t handle; | |
| #endif | |
| public: | public: |
| Mutex(); | Mutex(); |
| ~Mutex(); | ~Mutex(); |
| Line 34 private: // for AutoSYNCHRONIZED | Line 40 private: // for AutoSYNCHRONIZED |
| void release(); | void release(); |
| }; | }; |
| extern const bool parser_multithreaded; | |
| extern Mutex global_mutex; | extern Mutex global_mutex; |
| /** | /** |
| Helper to ensure paired Mutex::acquire() and Mutex::release(). | Helper to ensure paired Mutex::acquire() and Mutex::release(). |
| Use it with SYNCHRONIZED macro | Use it with SYNCHRONIZED macro |
| */ | */ |
| class AutoSYNCHRONIZED { | class AutoSYNCHRONIZED { |
| public: | public: |
| AutoSYNCHRONIZED() { global_mutex.acquire(); } | AutoSYNCHRONIZED() { global_mutex.acquire(); } |