inLimbo
TUI Music Player that keeps you in Limbo.
 
Loading...
Searching...
No Matches
thread_manager.hpp
Go to the documentation of this file.
1
5
6#ifndef THREAD_MANAGER_HPP
7#define THREAD_MANAGER_HPP
8
9#include <atomic>
10#include <future>
11#include <mutex>
12#include <thread>
13
19{
20public:
26 {
30 std::mutex play_mutex;
31
35 std::atomic<bool> is_processing{false};
36
40 std::atomic<bool> is_playing{false};
41
45 std::future<void> play_future;
46 };
47
52 ThreadState& getThreadState() { return thread_state; }
53
62 void lockPlayMutex(ThreadState& thread_state)
63 {
64 std::unique_lock<std::mutex> lock(thread_state.play_mutex);
65 }
66
76 void unlockPlayMutex(ThreadState& thread_state) { thread_state.play_mutex.unlock(); }
77
78private:
82 ThreadState thread_state;
83};
84
85#endif // THREAD_MANAGER_HPP
A class that manages thread states and provides utilities for thread handling.
Definition thread_manager.hpp:19
void unlockPlayMutex(ThreadState &thread_state)
Unlocks the play mutex for the provided thread state.
Definition thread_manager.hpp:76
ThreadState & getThreadState()
Retrieves the thread state managed by this ThreadManager.
Definition thread_manager.hpp:52
void lockPlayMutex(ThreadState &thread_state)
Locks the play mutex for the provided thread state.
Definition thread_manager.hpp:62
Represents the state of a thread managed by ThreadManager.
Definition thread_manager.hpp:26
std::future< void > play_future
A future object associated with the play operation.
Definition thread_manager.hpp:45
std::mutex play_mutex
A mutex to synchronize access to the play state.
Definition thread_manager.hpp:30
std::atomic< bool > is_processing
Indicates whether the thread is currently processing.
Definition thread_manager.hpp:35
std::atomic< bool > is_playing
Indicates whether the thread is currently playing.
Definition thread_manager.hpp:40