|
1
|
1 #include "foobar2000-sdk-pch.h"
|
|
|
2 #include "app_close_blocker.h"
|
|
|
3
|
|
|
4 bool app_close_blocker::g_query()
|
|
|
5 {
|
|
|
6 for (auto ptr : enumerate()) {
|
|
|
7 if (!ptr->query()) return false;
|
|
|
8 }
|
|
|
9 return true;
|
|
|
10 }
|
|
|
11
|
|
|
12 service_ptr async_task_manager::g_acquire() {
|
|
|
13 #if FOOBAR2000_TARGET_VERSION >= 80
|
|
|
14 return get()->acquire();
|
|
|
15 #else
|
|
|
16 ptr obj;
|
|
|
17 if ( tryGet(obj) ) return obj->acquire();
|
|
|
18 return nullptr;
|
|
|
19 #endif
|
|
|
20 }
|
|
|
21
|
|
|
22 void fb2k::splitTask( std::function<void ()> f) {
|
|
|
23 auto taskref = async_task_manager::g_acquire();
|
|
|
24 pfc::splitThread( [f,taskref] {
|
|
|
25 f();
|
|
|
26 (void)taskref; // retain until here
|
|
|
27 } );
|
|
|
28 }
|
|
|
29
|
|
|
30 void fb2k::splitTask( pfc::thread::arg_t const & arg, std::function<void ()> f) {
|
|
|
31 auto taskref = async_task_manager::g_acquire();
|
|
|
32 pfc::splitThread( arg, [f,taskref] {
|
|
|
33 f();
|
|
|
34 (void)taskref; // retain until here
|
|
|
35 } );
|
|
|
36 }
|
|
|
37
|
|
|
38 abort_callback& fb2k::mainAborter() {
|
|
|
39 return async_task_manager::get()->get_aborter();
|
|
|
40 }
|
|
|
41
|
|
|
42 app_close_blocking_task_impl::app_close_blocking_task_impl(const char * name) : m_name(name) {
|
|
|
43 PFC_ASSERT( core_api::is_main_thread() );
|
|
|
44 app_close_blocking_task_manager::get()->register_task(this);
|
|
|
45 }
|
|
|
46 app_close_blocking_task_impl::app_close_blocking_task_impl(pfc::string8&& name) : m_name(std::move(name)) {
|
|
|
47 PFC_ASSERT(core_api::is_main_thread());
|
|
|
48 app_close_blocking_task_manager::get()->register_task(this);
|
|
|
49 }
|
|
|
50
|
|
|
51 app_close_blocking_task_impl::~app_close_blocking_task_impl() {
|
|
|
52 PFC_ASSERT( core_api::is_main_thread() );
|
|
|
53 app_close_blocking_task_manager::get()->unregister_task(this);
|
|
|
54 }
|
|
|
55
|
|
|
56 void app_close_blocking_task_impl::query_task_name(pfc::string_base & out) {
|
|
|
57 out = m_name;
|
|
|
58 }
|
|
|
59
|
|
|
60 void app_close_blocking_task_impl_dynamic::toggle_blocking(bool state) {
|
|
|
61 PFC_ASSERT( core_api::is_main_thread() );
|
|
|
62 if (state != m_taskActive) {
|
|
|
63 auto api = app_close_blocking_task_manager::get();
|
|
|
64 if (state) api->register_task(this);
|
|
|
65 else api->unregister_task(this);
|
|
|
66 m_taskActive = state;
|
|
|
67 }
|
|
|
68 }
|
|
|
69
|
|
|
70 void app_close_blocking_task_impl_dynamic::query_task_name(pfc::string_base& out) {
|
|
|
71 out = m_name;
|
|
|
72 }
|