Skip to content

Commit

Permalink
Add template type on WFTaskFactory::send_by_name()/signal_by_name().
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Jan 3, 2025
1 parent 6a5399e commit 6eaf84f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/client/WFKafkaClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void KafkaClientTask::kafka_rebalance_callback(__WFKafkaTask *task)
snprintf(name, 64, "%p.cgroup", member);
member->mutex.unlock();

WFTaskFactory::signal_by_name(name, (void *)NULL, max);
WFTaskFactory::signal_by_name(name, NULL, max);
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/factory/WFTaskFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ int WFTaskFactory::send_by_name(const std::string& name, void *msg,
return __mailbox_map.send(name, &msg, max, 0);
}

template<>
int WFTaskFactory::send_by_name(const std::string& name, void *const msg[],
size_t max)
{
Expand Down Expand Up @@ -707,6 +708,7 @@ int WFTaskFactory::signal_by_name(const std::string& name, void *msg,
return __conditional_map.signal(name, &msg, max, 0);
}

template<>
int WFTaskFactory::signal_by_name(const std::string& name, void *const msg[],
size_t max)
{
Expand Down
53 changes: 5 additions & 48 deletions src/factory/WFTaskFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ class WFTaskFactory

/* Count by a counter's name. When count_by_name(), it's safe to count
* exceeding target_value. When multiple counters share a same name,
* this operation will be performed on the first created. If no counter
* matches the name, nothing is performed. */
* this operation will be performed on the first created. */
static int count_by_name(const std::string& counter_name)
{
return WFTaskFactory::count_by_name(counter_name, 1);
Expand Down Expand Up @@ -258,7 +257,8 @@ class WFTaskFactory
static int send_by_name(const std::string& mailbox_name, void *msg,
size_t max);

static int send_by_name(const std::string& mailbox_name, void *const msg[],
template<typename T>
static int send_by_name(const std::string& mailbox_name, T *const msg[],
size_t max);

public:
Expand Down Expand Up @@ -293,7 +293,8 @@ class WFTaskFactory
static int signal_by_name(const std::string& cond_name, void *msg,
size_t max);

static int signal_by_name(const std::string& cond_name, void *const msg[],
template<typename T>
static int signal_by_name(const std::string& cond_name, T *const msg[],
size_t max);

public:
Expand Down Expand Up @@ -371,50 +372,6 @@ class WFTaskFactory
task->sub_series()->set_last_task(last);
return task;
}

private:
/* Some compilers don't declare 'nullptr_t' although required by C++11. */
using nullptr_t = std::nullptr_t;

public:
/* The following functions are for overload resolution only. */

#ifdef _WIN32
static int send_by_name(const std::string& mailbox_name, int msg,
size_t max)
{
return WFTaskFactory::send_by_name(mailbox_name, (void *)msg, max);
}

static int signal_by_name(const std::string& cond_name, int msg,
size_t max)
{
return WFTaskFactory::signal_by_name(cond_name, (void *)msg, max);
}
#else
static int send_by_name(const std::string& mailbox_name, intptr_t msg,
size_t max)
{
return WFTaskFactory::send_by_name(mailbox_name, (void *)msg, max);
}

static int signal_by_name(const std::string& cond_name, intptr_t msg,
size_t max)
{
return WFTaskFactory::signal_by_name(cond_name, (void *)msg, max);
}
#endif
static int send_by_name(const std::string& mailbox_name, nullptr_t msg,
size_t max)
{
return WFTaskFactory::send_by_name(mailbox_name, (void *)0, max);
}

static int signal_by_name(const std::string& cond_name, nullptr_t msg,
size_t max)
{
return WFTaskFactory::signal_by_name(cond_name, (void *)0, max);
}
};

template<class REQ, class RESP>
Expand Down
30 changes: 25 additions & 5 deletions src/factory/WFTaskFactory.inl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ WFTaskFactory::create_dynamic_task(dynamic_create_t create)
return new __WFDynamicTask(std::move(create));
}

template<>
int WFTaskFactory::send_by_name(const std::string&, void *const *, size_t);

template<typename T>
int WFTaskFactory::send_by_name(const std::string& mailbox_name, T *const msg[],
size_t max)
{
return WFTaskFactory::send_by_name(mailbox_name, (void *const *)msg, max);
}

template<>
int WFTaskFactory::signal_by_name(const std::string&, void *const *, size_t);

template<typename T>
int WFTaskFactory::signal_by_name(const std::string& cond_name, T *const msg[],
size_t max)
{
return WFTaskFactory::signal_by_name(cond_name, (void *const *)msg, max);
}

template<class REQ, class RESP, typename CTX = bool>
class WFComplexClientTask : public WFClientTask<REQ, RESP>
{
Expand Down Expand Up @@ -712,7 +732,7 @@ void WFTaskFactory::reset_go_task(WFGoTask *task, FUNC&& func, ARGS&&... args)

template<> inline
WFGoTask *WFTaskFactory::create_go_task(const std::string& queue_name,
nullptr_t&& func)
std::nullptr_t&& func)
{
return new __WFGoTask(WFGlobal::get_exec_queue(queue_name),
WFGlobal::get_compute_executor(),
Expand All @@ -722,7 +742,7 @@ WFGoTask *WFTaskFactory::create_go_task(const std::string& queue_name,
template<> inline
WFGoTask *WFTaskFactory::create_timedgo_task(time_t seconds, long nanoseconds,
const std::string& queue_name,
nullptr_t&& func)
std::nullptr_t&& func)
{
return new __WFTimedGoTask(seconds, nanoseconds,
WFGlobal::get_exec_queue(queue_name),
Expand All @@ -732,21 +752,21 @@ WFGoTask *WFTaskFactory::create_timedgo_task(time_t seconds, long nanoseconds,

template<> inline
WFGoTask *WFTaskFactory::create_go_task(ExecQueue *queue, Executor *executor,
nullptr_t&& func)
std::nullptr_t&& func)
{
return new __WFGoTask(queue, executor, nullptr);
}

template<> inline
WFGoTask *WFTaskFactory::create_timedgo_task(time_t seconds, long nanoseconds,
ExecQueue *queue, Executor *executor,
nullptr_t&& func)
std::nullptr_t&& func)
{
return new __WFTimedGoTask(seconds, nanoseconds, queue, executor, nullptr);
}

template<> inline
void WFTaskFactory::reset_go_task(WFGoTask *task, nullptr_t&& func)
void WFTaskFactory::reset_go_task(WFGoTask *task, std::nullptr_t&& func)
{
((__WFGoTask *)task)->set_go_func(nullptr);
}
Expand Down

0 comments on commit 6eaf84f

Please sign in to comment.