forked from microsoft/cpprestsdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadpool.h
More file actions
76 lines (61 loc) · 1.86 KB
/
threadpool.h
File metadata and controls
76 lines (61 loc) · 1.86 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/***
* Copyright (C) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
*
*
* Simple Linux implementation of a static thread pool.
*
* For the latest on this and related APIs, please see: https://github.com/Microsoft/cpprestsdk
*
* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
***/
#pragma once
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Winfinite-recursion"
#endif
#include "boost/asio.hpp"
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#if defined(__ANDROID__)
#include <atomic>
#include <jni.h>
#include "pplx/pplx.h"
#endif
#include "cpprest/details/cpprest_compat.h"
namespace crossplat {
#if defined(__ANDROID__)
// IDEA: Break this section into a separate android/jni header
extern std::atomic<JavaVM*> JVM;
JNIEnv* get_jvm_env();
struct java_local_ref_deleter
{
void operator()(jobject lref) const
{
crossplat::get_jvm_env()->DeleteLocalRef(lref);
}
};
template<class T>
using java_local_ref = std::unique_ptr<typename std::remove_pointer<T>::type, java_local_ref_deleter>;
#endif
class threadpool
{
public:
_ASYNCRTIMP static threadpool& shared_instance();
_ASYNCRTIMP static std::unique_ptr<threadpool> __cdecl construct(size_t num_threads);
virtual ~threadpool() = default;
template<typename T>
CASABLANCA_DEPRECATED("Use `.service().post(task)` directly.")
void schedule(T task)
{
service().post(task);
}
boost::asio::io_service& service() { return m_service; }
protected:
threadpool(size_t num_threads) : m_service(static_cast<int>(num_threads)) {}
boost::asio::io_service m_service;
};
}