mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-09-20 09:04:43 +00:00
7ef15653fd
This adds generic APIs to libqb for handling thread's, mutex's, and condition variables. On Linux and OSX these are implemented via the ones provided by pthreads. On Windows they're implemented via the ones provided by the Win32 API. For compiling, the code itself is not conditional, but the Makefile includes logic to decide which implementation to pick. Note that it would have been nice to simply use std::thread and friends from C++11, however using them on MinGW appears to be a bit messy. Since using the Windows ones directly isn't that hard this was an easy compromise.
29 lines
680 B
C++
29 lines
680 B
C++
#ifndef INCLUDE_LIBQB_MUTEX_H
|
|
#define INCLUDE_LIBQB_MUTEX_H
|
|
|
|
struct libqb_mutex;
|
|
|
|
// Allocates and frees a Mutex. Mutex is created unlocked.
|
|
struct libqb_mutex *libqb_mutex_new();
|
|
void libqb_mutex_free(struct libqb_mutex *);
|
|
|
|
// Lock and unlock the Mutex
|
|
void libqb_mutex_lock(struct libqb_mutex *);
|
|
void libqb_mutex_unlock(struct libqb_mutex *);
|
|
|
|
// Locks a mutex when created, and unlocks when the guard goes out of scope
|
|
class libqb_mutex_guard {
|
|
public:
|
|
libqb_mutex_guard(struct libqb_mutex *mtx) : lock(mtx) {
|
|
libqb_mutex_lock(lock);
|
|
}
|
|
|
|
~libqb_mutex_guard() {
|
|
libqb_mutex_unlock(lock);
|
|
}
|
|
|
|
private:
|
|
struct libqb_mutex *lock;
|
|
};
|
|
|
|
#endif
|