29 #if defined(__clang__)
30 #pragma clang diagnostic push
31 #pragma clang diagnostic ignored "-Wconversion"
32 #pragma clang diagnostic ignored "-Wunreachable-code"
34 #include "boost/asio.hpp"
35 #if defined(__clang__)
36 #pragma clang diagnostic pop
39 #if (defined(ANDROID) || defined(__ANDROID__))
42 #include "pplx/pplx.h"
47 #if (defined(ANDROID) || defined(__ANDROID__))
49 extern std::atomic<JavaVM*> JVM;
50 JNIEnv* get_jvm_env();
52 struct java_local_ref_deleter
54 void operator()(jobject lref)
const
56 crossplat::get_jvm_env()->DeleteLocalRef(lref);
61 using java_local_ref = std::unique_ptr<typename std::remove_pointer<T>::type, java_local_ref_deleter>;
72 for (
size_t i = 0; i < n; i++)
81 for (
auto iter = m_threads.begin(); iter != m_threads.end(); ++iter)
85 pthread_join(t, &res);
95 boost::asio::io_service& service()
101 struct _cancel_thread { };
106 auto result = pthread_create(&t,
nullptr, &thread_start,
this);
108 m_threads.push_back(t);
113 schedule([]() ->
void {
throw _cancel_thread(); });
116 #if (defined(ANDROID) || defined(__ANDROID__))
117 static void detach_from_java(
void*)
119 JVM.load()->DetachCurrentThread();
123 static void* thread_start(
void *arg)
125 #if (defined(ANDROID) || defined(__ANDROID__))
128 pthread_cleanup_push(detach_from_java,
nullptr);
133 _this->m_service.run();
135 catch (
const _cancel_thread&)
142 #if (defined(ANDROID) || defined(__ANDROID__))
146 __pthread_cleanup_pop(&__cleanup,
true);
150 #if (defined(ANDROID) || defined(__ANDROID__))
151 pthread_cleanup_pop(
true);
156 std::vector<pthread_t> m_threads;
157 boost::asio::io_service m_service;
158 boost::asio::io_service::work m_work;
Definition: threadpool.h:45
Definition: threadpool.h:64