Add mailbox task's factory functions

This commit is contained in:
XieHan
2021-06-20 17:42:05 +08:00
parent fba1f93c7e
commit 832800a9b5
3 changed files with 46 additions and 0 deletions
+8
View File
@@ -620,6 +620,14 @@ public:
this->mailbox = mailbox;
}
WFMailboxTask(std::function<void (WFMailboxTask *)>&& cb) :
next(&this->user_data),
value(2),
callback(std::move(cb))
{
this->mailbox = &this->user_data;
}
protected:
virtual ~WFMailboxTask() { }
};
+27
View File
@@ -295,6 +295,33 @@ void WFTaskFactory::count_by_name(const std::string& counter_name, unsigned int
__CounterMap::get_instance()->count_n(counter_name, n);
}
/********MailboxTask*************/
class __WFMailboxTask : public WFMailboxTask
{
public:
__WFMailboxTask(size_t size, mailbox_callback_t&& cb) :
WFMailboxTask(new void *[size], size, std::move(cb))
{
}
virtual ~__WFMailboxTask()
{
delete []this->mailbox;
}
};
WFMailboxTask *WFTaskFactory::create_mailbox_task(size_t size,
mailbox_callback_t callback)
{
return new __WFMailboxTask(size, std::move(callback));
}
WFMailboxTask *WFTaskFactory::create_mailbox_task(mailbox_callback_t callback)
{
return new WFMailboxTask(std::move(callback));
}
WFDNSTask *WFTaskFactory::create_dns_task(const std::string& host,
unsigned short port,
dns_callback_t callback)
+11
View File
@@ -83,6 +83,10 @@ using fsync_callback_t = std::function<void (WFFileSyncTask *)>;
using timer_callback_t = std::function<void (WFTimerTask *)>;
using counter_callback_t = std::function<void (WFCounterTask *)>;
// Mailbox is like counter with data passing
using mailbox_callback_t = std::function<void (WFMailboxTask *)>;
// Graph (DAG) task.
using graph_callback_t = std::function<void (WFGraphTask *)>;
// DNS task. For internal usage only.
@@ -214,6 +218,13 @@ public:
* creation, and more than one counter may reach target value. */
static void count_by_name(const std::string& counter_name, unsigned int n);
public:
static WFMailboxTask *create_mailbox_task(size_t size,
mailbox_callback_t callback);
/* Use 'user_data' as mailbox. Store only one message. */
static WFMailboxTask *create_mailbox_task(mailbox_callback_t callback);
public:
template<class FUNC, class... ARGS>
static WFGoTask *create_go_task(const std::string& queue_name,