VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
Concurrency.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "Chrono.h"
16#include <thread>
17#include <future>
18
19namespace vc64::util {
20
21class Mutex
22{
23 std::mutex mutex;
24
25public:
26
27 void lock() { mutex.lock(); }
28 void unlock() { mutex.unlock(); }
29};
30
31class ReentrantMutex
32{
33 std::recursive_mutex mutex;
34
35public:
36
37 void lock() { mutex.lock(); }
38 void unlock() { mutex.unlock(); }
39};
40
41class AutoMutex
42{
43 ReentrantMutex &mutex;
44
45public:
46
47 bool active = true;
48
49 AutoMutex(ReentrantMutex &ref) : mutex(ref) { mutex.lock(); }
50 ~AutoMutex() { mutex.unlock(); }
51};
52
53}