Skip to content

Commit

Permalink
Add return value for WFTaskFactory::release_guard().
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Dec 19, 2023
1 parent 6e4e29d commit 63b40ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
30 changes: 17 additions & 13 deletions src/factory/WFTaskFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1039,28 +1039,32 @@ WFConditional *WFTaskFactory::create_guard(const std::string& name,
return __guard_map.create(name, task, msgbuf);
}

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

if (node)
node->guard->WFConditional::signal(msg);
if (!node)
return 0;

node->guard->WFConditional::signal(msg);
return 1;
}

void WFTaskFactory::release_guard_safe(const std::string& name, void *msg)
int WFTaskFactory::release_guard_safe(const std::string& name, void *msg)
{
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(msg);
}
if (!node)
return 0;

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(msg);
return 1;
}

/**************** Timed Go Task *****************/
Expand Down
11 changes: 6 additions & 5 deletions src/factory/WFTaskFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,21 @@ class WFTaskFactory
SubTask *task, void **msgbuf);

/* The 'guard' is acquired after started, so call 'release_guard' after
and only after the task is finished, typically in its callback. */
static void release_guard(const std::string& resource_name)
and only after the task is finished, typically in its callback.
The function returns 1 if another is signaled, otherwise returns 0. */
static int release_guard(const std::string& resource_name)
{
return WFTaskFactory::release_guard(resource_name, NULL);
}

static void release_guard(const std::string& resaource_name, void *msg);
static int release_guard(const std::string& resaource_name, void *msg);

static void release_guard_safe(const std::string& resource_name)
static int release_guard_safe(const std::string& resource_name)
{
return WFTaskFactory::release_guard_safe(resource_name, NULL);
}

static void release_guard_safe(const std::string& resource_name, void *msg);
static int release_guard_safe(const std::string& resource_name, void *msg);

public:
template<class FUNC, class... ARGS>
Expand Down

0 comments on commit 63b40ae

Please sign in to comment.