- Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEngineThread.h
More file actions
Latest commit
78 lines (62 loc) · 2.4 KB
/
Copy pathEngineThread.h
File metadata and controls
78 lines (62 loc) · 2.4 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
77
78
#pragma once
#include"BlockingQueue.h"
#include"utils.h"
classEngineWindow;
classStyleManager;
namespaceengine_messages {
structMessage;
}
classCallbackHolder {
std::shared_ptr<bool> deadPtr;
public:
CallbackHolder();
CallbackHolder(const CallbackHolder&) = delete;
CallbackHolder& operator=(const CallbackHolder&) = delete;
CallbackHolder(CallbackHolder&&) = delete;
CallbackHolder& operator=(CallbackHolder&&) = delete;
~CallbackHolder() noexcept;
voidaddCallback(std::function<void()> f);
};
classEngineThread : publicplay_callback_impl_base,
public library_callback_dynamic_impl_base {
public:
explicitEngineThread(EngineWindow& engineWindow, StyleManager& styleManager);
NO_MOVE_NO_COPY(EngineThread);
~EngineThread();
voidsendMessage(unique_ptr<engine_messages::Message>&& msg);
/// Sends a message and get a future to wait for the response.
/// You should only wait in the mainthread, as waiting in other threads
/// will deadlock if the Engine is shut down while you're waiting.
template <typename T, typename... _Types>
std::future<typename T::ValueType> sendSync(_Types&&... _Args) {
unique_ptr<T> msg = make_unique<T>(std::forward<_Types>(_Args)...);
std::future<typename T::ValueType> future = msg->promise.get_future();
sendMessage(std::move(msg));
returnstd::move(future);
};
template <typename T, typename... _Types>
voidsend(_Types&&... _Args) {
sendMessage(make_unique<T>(std::forward<_Types>(_Args)...));
};
voidinvalidateWindow();
voidon_style_change();
voidon_playback_new_track(metadb_handle_ptr p_track) final;
voidon_items_added(metadb_handle_list_cref p_data) final;
voidon_items_removed(metadb_handle_list_cref p_data) final;
voidon_items_modified(metadb_handle_list_cref p_data) final;
/// Runs a function in the foobar2000 mainthread
/// Guarantees that the callback runs only if this thread is still alive.
voidrunInMainThread(std::function<void()> f);
staticvoidforEach(std::function<void(EngineThread&)>);
/// Library version tag – only access from mainthread
t_uint64 libraryVersion{0};
private:
voidrun();
EngineWindow& engineWindow;
StyleManager& styleManager;
BlockingQueue<unique_ptr<engine_messages::Message>> messageQueue;
CallbackHolder callbackHolder;
std::thread thread;
static std::unordered_set<EngineThread*> instances;
friendclassEngine;
};