Skip to content

Commit

Permalink
Switched bare_lambda internal signal to pconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
zajo committed Jul 25, 2020
1 parent 5ee2d3e commit 56b4edb
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/thread_local_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,21 @@ namespace boost { namespace synapse {
for( unsigned serial_number=last_poll_serial_number; serial_number!=current; ++serial_number )
{
bool found = std::find_if( same_thread_different_signals_.begin(), same_thread_different_signals_.end(),
[&count,serial_number]( cl_rec const & r )
[&count,serial_number]( cl_rec const & r )
{
if( shared_ptr<thread_local_signal_data> sp=r.lock() )
{
if( shared_ptr<thread_local_signal_data> sp=r.lock() )
int n=sp->ps_->emit_if_serial_number_matches(serial_number,*sp);
if( n>=0 )
{
int n=sp->ps_->emit_if_serial_number_matches(serial_number,*sp);
if( n>=0 )
{
count+=n;
return true;
}
else
BOOST_SYNAPSE_ASSERT(n==-1);
count+=n;
return true;
}
return false;
} )!=same_thread_different_signals_.end();
else
BOOST_SYNAPSE_ASSERT(n==-1);
}
return false;
} )!=same_thread_different_signals_.end();
BOOST_SYNAPSE_ASSERT(found);
}
return count;
Expand Down Expand Up @@ -314,20 +314,12 @@ namespace boost { namespace synapse {

std::thread::id const tid_;
shared_ptr<synapse_detail::thread_local_connection_list_list> const tlcll_;
shared_ptr<connection const> const conn_bare_lambda_;

static void call_bare_lambda( function<void()> const & f )
{
BOOST_SYNAPSE_ASSERT(f);
f();
}

public:

thread_local_queue():
tid_(std::this_thread::get_id()),
tlcll_(synapse_detail::get_thread_local_connection_list_list()),
conn_bare_lambda_(connect<bare_lambda>(this,&call_bare_lambda))
tlcll_(synapse_detail::get_thread_local_connection_list_list())
{
tlcll_->enable_tlq();
}
Expand Down Expand Up @@ -358,7 +350,13 @@ namespace boost { namespace synapse {

shared_ptr<thread_local_queue> create_thread_local_queue()
{
return make_shared<thread_local_queue>();
std::shared_ptr<thread_local_queue> tlq = make_shared<thread_local_queue>();
(void) connect<bare_lambda>(tlq, []( std::function<void()> const & f )
{
BOOST_SYNAPSE_ASSERT(f);
f();
} );
return tlq;
}

int poll( thread_local_queue & tlq )
Expand Down

0 comments on commit 56b4edb

Please sign in to comment.