30 #include <cugar/basic/types.h> 31 #include <cugar/basic/numbers.h> 32 #include <cugar/basic/atomics.h> 33 #include <cugar/basic/shared_pointer.h> 56 CUGAR_API uint32 num_physical_cores();
57 CUGAR_API uint32 num_logical_cores();
59 struct ThreadBaseImpl;
66 CUGAR_API ~ThreadBase();
68 void set_id(
const uint32
id) { m_id = id; }
69 uint32 get_id()
const {
return m_id; }
72 CUGAR_API
void create(
void* (*func)(
void*),
void* arg);
75 CUGAR_API
void join();
102 template <
typename DerivedThreadType>
114 static void* execute(
void* arg)
116 DerivedThreadType* data =
reinterpret_cast<DerivedThreadType*
>( arg );
199 template <
typename WorkItemT,
typename ProgressCallbackT>
203 typedef WorkItemT WorkItem;
204 typedef ProgressCallbackT ProgressCallback;
210 void push(
const WorkItem work) { m_queue.push( work ); m_size++; }
216 m_queue.push( work ); m_size++;
226 work = m_queue.front();
229 m_callback( m_size - (uint32)m_queue.size() - 1u, m_size );
234 void set_callback(
const ProgressCallback callback) { m_callback = callback; }
237 ProgressCallback m_callback;
238 std::queue<WorkItem> m_queue;
247 const uint32 batch_count =
divide_ri(total_count, batch_size);
249 const uint32 rounds =
divide_ri(batch_count, thread_count);
252 const uint32 bal_batches = rounds * thread_count;
254 return divide_ri(total_count, bal_batches);
257 CUGAR_API
void yield();
void locked_push(const WorkItem work)
push a work item in the queue
Definition: threads.h:213
void set_callback(const ProgressCallback callback)
set a callback
Definition: threads.h:234
CUGAR_API void join()
join the thread
Definition: threads.cpp:286
void push(const WorkItem work)
push a work item in the queue
Definition: threads.h:210
bool pop(WorkItem &work)
pop the next work item from the queue
Definition: threads.h:220
Definition: shared_pointer.h:345
Definition: threads.h:181
uint32 balance_batch_size(uint32 batch_size, uint32 total_count, uint32 thread_count)
return a number close to batch_size that achieves best threading balance
Definition: threads.h:244
CUGAR_HOST_DEVICE L divide_ri(const L x, const R y)
Definition: numbers.h:180
Definition: threads.h:200
Definition: threads.h:145
WorkQueue()
empty constructor
Definition: threads.h:207
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
void join()
join the thread
Definition: threads.h:110
void create()
create the thread
Definition: threads.h:107
CUGAR_API void create(void *(*func)(void *), void *arg)
create the thread
Definition: threads.cpp:281
Definition: threads.h:103