Skip to content

Commit

Permalink
worker: fix start barrier (required for shared_from_this) & move most…
Browse files Browse the repository at this point in the history
… member initialization into {}
  • Loading branch information
michaelsippel committed Aug 31, 2023
1 parent 00d3525 commit 3066157
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions redGrapes/dispatch/thread/worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,41 @@ struct WorkerThread : std::enable_shared_from_this<WorkerThread>
* executing the jobs in its queue
* and request rescheduling if empty
*/
std::atomic_bool m_start;
std::atomic_bool m_start{ false };

/*! if true, the thread shall stop
* instead of waiting when it is out of jobs
*/
std::atomic_bool m_stop;
std::atomic_bool m_stop{ false };

public:
std::atomic_bool ready;
unsigned id;

std::atomic<unsigned> task_count{ 0 };

std::atomic_bool ready{false};

//! condition variable for waiting if queue is empty
CondVar cv;

static constexpr size_t queue_capacity = 32;

public:
task::Queue emplacement_queue;
task::Queue ready_queue;
task::Queue emplacement_queue{ queue_capacity };
task::Queue ready_queue{ queue_capacity };
std::thread thread;

unsigned id;

public:
WorkerThread( unsigned id ) :
m_start( false ),
m_stop( false ),
id( id ),
ready( false ),
emplacement_queue( 32 ),
ready_queue( 32 ),
thread(
[this]
{
ready = true;

while( ! m_start.load(std::memory_order_consume) )
cv.wait();

this->cpubind();
this->membind();

Expand All @@ -99,11 +104,6 @@ struct WorkerThread : std::enable_shared_from_this<WorkerThread>
current_waker_id = this->get_waker_id();
memory::current_arena = get_worker_id();

ready = true;

while( ! m_start.load(std::memory_order_consume) )
cv.wait();

while( ! m_stop.load(std::memory_order_consume) )
{
SPDLOG_TRACE("Worker: work on queue");
Expand Down

0 comments on commit 3066157

Please sign in to comment.