MCPcopy Create free account
hub / github.com/Amanieu/asyncplusplus / threadpool_data

Class threadpool_data

src/threadpool_scheduler.cpp:44–78  ·  view source on GitHub ↗

Internal data used by threadpool_scheduler

Source from the content-addressed store, hash-verified

42
43// Internal data used by threadpool_scheduler
44struct threadpool_data {
45 threadpool_data(std::size_t num_threads)
46 : thread_data(num_threads), shutdown(false), num_waiters(0), waiters(new task_wait_event*[num_threads]) {}
47
48 threadpool_data(std::size_t num_threads, std::function<void()>&& prerun_, std::function<void()>&& postrun_)
49 : thread_data(num_threads), shutdown(false), num_waiters(0), waiters(new task_wait_event*[num_threads]),
50 prerun(std::move(prerun_)), postrun(std::move(postrun_)) {}
51
52 // Mutex protecting everything except thread_data
53 std::mutex lock;
54
55 // Array of per-thread data
56 aligned_array<thread_data_t> thread_data;
57
58 // Global queue for tasks from outside the pool
59 fifo_queue public_queue;
60
61 // Shutdown request indicator
62 bool shutdown;
63
64 // List of threads waiting for tasks to run. num_waiters needs to be atomic
65 // because it is sometimes read outside the mutex.
66 std::atomic<std::size_t> num_waiters;
67 std::unique_ptr<task_wait_event*[]> waiters;
68
69 // Pre/Post run functions.
70 std::function<void()> prerun;
71 std::function<void()> postrun;
72
73#ifdef BROKEN_JOIN_IN_DESTRUCTOR
74 // Shutdown complete event, used instead of thread::join()
75 std::size_t shutdown_num_threads;
76 std::condition_variable shutdown_complete_event;
77#endif
78};
79
80// this wrapper encapsulates both the owning_threadpool pointer and the thread id.
81// this is done to improve performance on the emulated thread_local reducing the number

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected