summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/block_handlers.cpp9
-rw-r--r--lib/element_impl.hpp2
-rw-r--r--lib/gras_impl/block_actor.hpp21
-rw-r--r--lib/top_block_stats.cpp2
4 files changed, 23 insertions, 11 deletions
diff --git a/lib/block_handlers.cpp b/lib/block_handlers.cpp
index a3e030a..9865331 100644
--- a/lib/block_handlers.cpp
+++ b/lib/block_handlers.cpp
@@ -31,11 +31,11 @@ void BlockActor::handle_top_inert(
){
MESSAGE_TRACER();
- ASSERT(this->prio_count.Load() != 0);
- this->prio_count.Decrement();
this->mark_done();
this->Send(0, from); //ACK
+
+ this->highPrioAck();
}
void BlockActor::handle_top_token(
@@ -136,13 +136,12 @@ void BlockActor::handle_get_stats(
const Theron::Address from
){
MESSAGE_TRACER();
- this->prio_count.Decrement();
+
GetStatsMessage message;
message.block_id = this->block_ptr->to_string();
message.stats = this->stats;
message.stats_time = time_now();
this->Send(message, from); //ACK
- //high prio message may have deferred handle task
- this->handle_task();
+ this->highPrioAck();
}
diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp
index e127e01..62feaba 100644
--- a/lib/element_impl.hpp
+++ b/lib/element_impl.hpp
@@ -50,7 +50,7 @@ struct ElementImpl
{
BOOST_FOREACH(Apology::Worker *worker, this->executor->get_workers())
{
- dynamic_cast<BlockActor *>(worker)->prio_count.Increment();
+ dynamic_cast<BlockActor *>(worker)->highPrioPreNotify();
}
}
diff --git a/lib/gras_impl/block_actor.hpp b/lib/gras_impl/block_actor.hpp
index d7429f1..8efc388 100644
--- a/lib/gras_impl/block_actor.hpp
+++ b/lib/gras_impl/block_actor.hpp
@@ -33,7 +33,22 @@ struct BlockActor : Apology::Worker
ThreadPool thread_pool;
//! Priority count to hack in high-prio worker queue
- Theron::Detail::Atomic::UInt32 prio_count;
+ Theron::Detail::Atomic::UInt32 prioCount;
+ GRAS_FORCE_INLINE void highPrioPreNotify(void)
+ {
+ this->prioCount.Increment();
+ }
+ GRAS_FORCE_INLINE void highPrioAck(void)
+ {
+ ASSERT(this->prioCount.Load() != 0);
+ this->prioCount.Decrement();
+ this->handle_task();
+ }
+ GRAS_FORCE_INLINE bool hasHighPrioMsg(void)
+ {
+ //high prio when the count is positive and there are enqueued messages (avoids race)
+ return this->prioCount.Load() and this->GetNumQueuedMessages();
+ }
//do it here so we can match w/ the handler declarations
void register_handlers(void)
@@ -123,10 +138,8 @@ struct BlockActor : Apology::Worker
GRAS_FORCE_INLINE bool is_work_allowed(void)
{
- //high prio when the count is positive and there are enqueued messages (avoids race)
- const bool has_high_prio_msg = this->prio_count.Load() and this->GetNumQueuedMessages();
return (
- not has_high_prio_msg and
+ not this->hasHighPrioMsg() and
this->block_state == BLOCK_STATE_LIVE and
this->input_queues.all_ready() and
this->inputs_available.any() and
diff --git a/lib/top_block_stats.cpp b/lib/top_block_stats.cpp
index 8cbdb0c..e5fd96d 100644
--- a/lib/top_block_stats.cpp
+++ b/lib/top_block_stats.cpp
@@ -29,7 +29,7 @@ std::string TopBlock::get_stats(const std::string &)
size_t outstandingCount(0);
BOOST_FOREACH(Apology::Worker *worker, (*this)->executor->get_workers())
{
- dynamic_cast<BlockActor *>(worker)->prio_count.Increment();
+ dynamic_cast<BlockActor *>(worker)->highPrioPreNotify();
worker->Push(GetStatsMessage(), receiver.GetAddress());
outstandingCount++;
}