Skip to content

Commit

Permalink
Merge pull request #1444 from Barenboim/master
Browse files Browse the repository at this point in the history
Add WFTaskFactory::release_guard_safe()
  • Loading branch information
Barenboim authored Dec 12, 2023
2 parents fdcd4c0 + 05798fa commit c91f8a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/factory/WFTaskFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ static class __NamedGuardMap

public:
WFConditional *create(const std::string& name, SubTask *task);
void release(const std::string& name);
struct __guard_node *release(const std::string& name);

void unref(GuardList *guards)
{
Expand Down Expand Up @@ -936,6 +936,10 @@ class __WFNamedGuard : public WFConditional
__guard_map.unref(guards_);
}

SubTask *get_task() const { return this->task; }

void set_task(SubTask *task) { this->task = task; }

protected:
virtual void dispatch();
virtual void signal(void *msg) { }
Expand Down Expand Up @@ -972,7 +976,7 @@ WFConditional *__NamedGuardMap::create(const std::string& name,
return guard;
}

void __NamedGuardMap::release(const std::string& name)
struct __guard_node *__NamedGuardMap::release(const std::string& name)
{
struct __guard_node *node = NULL;
GuardList *guards;
Expand Down Expand Up @@ -1002,8 +1006,8 @@ void __NamedGuardMap::release(const std::string& name)
mutex_.unlock();
if (guards)
delete guards;
else if (node)
node->guard->WFConditional::signal(NULL);

return node;
}

WFConditional *WFTaskFactory::create_guard(const std::string& name,
Expand All @@ -1014,7 +1018,26 @@ WFConditional *WFTaskFactory::create_guard(const std::string& name,

void WFTaskFactory::release_guard(const std::string& name)
{
__guard_map.release(name);
struct __guard_node *node = __guard_map.release(name);

if (node)
node->guard->WFConditional::signal(NULL);
}

void WFTaskFactory::release_guard_safe(const std::string& name)
{
struct __guard_node *node = __guard_map.release(name);
WFTimerTask *timer;

if (node)
{
timer = WFTaskFactory::create_timer_task(0, 0, [](WFTimerTask *timer) {
series_of(timer)->push_front((SubTask *)timer->user_data);
});
timer->user_data = node->guard->get_task();
node->guard->set_task(timer);
node->guard->WFConditional::signal(NULL);
}
}

/**************** Timed Go Task *****************/
Expand Down
2 changes: 2 additions & 0 deletions src/factory/WFTaskFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ class WFTaskFactory
and only after the task is finished, typically in its callback. */
static void release_guard(const std::string& resource_name);

static void release_guard_safe(const std::string& resource_name);

public:
template<class FUNC, class... ARGS>
static WFGoTask *create_go_task(const std::string& queue_name,
Expand Down

0 comments on commit c91f8a7

Please sign in to comment.