blob: 3405e794782e3c2d9233b0e8b4b28b0112cdd5c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/**
* @file llcoromutex.h
* @author Nat Goodspeed
* @date 2024-09-04
* @brief Coroutine-aware synchronization primitives
*
* $LicenseInfo:firstyear=2024&license=viewerlgpl$
* Copyright (c) 2024, Linden Research, Inc.
* $/LicenseInfo$
*/
#if ! defined(LL_LLCOROMUTEX_H)
#define LL_LLCOROMUTEX_H
#include "mutex.h"
#include <boost/fiber/future/promise.hpp>
#include <boost/fiber/future/future.hpp>
// e.g. #include LLCOROS_MUTEX_HEADER
#define LLCOROS_MUTEX_HEADER <boost/fiber/mutex.hpp>
#define LLCOROS_CONDVAR_HEADER <boost/fiber/condition_variable.hpp>
namespace boost {
namespace fibers {
class mutex;
enum class cv_status;
class condition_variable;
}
}
namespace llcoro
{
/**
* Aliases for promise and future. An older underlying future implementation
* required us to wrap future; that's no longer needed. However -- if it's
* important to restore kill() functionality, we might need to provide a
* proxy, so continue using the aliases.
*/
template <typename T>
using Promise = boost::fibers::promise<T>;
template <typename T>
using Future = boost::fibers::future<T>;
template <typename T>
inline
static Future<T> getFuture(Promise<T>& promise) { return promise.get_future(); }
// use mutex, lock, condition_variable suitable for coroutines
using Mutex = boost::fibers::mutex;
using LockType = std::unique_lock<Mutex>;
using cv_status = boost::fibers::cv_status;
using ConditionVariable = boost::fibers::condition_variable;
} // namespace llcoro
#endif /* ! defined(LL_LLCOROMUTEX_H) */
|