Skip to content

Commit

Permalink
Add void(void) work thread support for ThreadPool.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcb33 committed May 25, 2020
1 parent 612d486 commit 816da8d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 97 deletions.
14 changes: 14 additions & 0 deletions univ/threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,17 @@ int Sloong::Universal::CThreadPool::AddWorkThread(std::function<void(SMARTER)> p
}



int Sloong::Universal::CThreadPool::AddWorkThread(std::function<void(void)> pJob, int nNum/* = 1*/)
{
int nIndex = CThreadPool::m_pThreadList.size();
for (int i = 0; i < nNum; i++)
{
thread* pThread = new thread(pJob);
CThreadPool::m_pThreadList.push_back(pThread);
}

return nIndex;
}


8 changes: 5 additions & 3 deletions univ/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ namespace Sloong
{
/// C style define
typedef LPVOID(*pTaskJobFunc)(LPVOID);
typedef void(*pTaskCallBack)(long long, LPVOID);
typedef void(*pTaskCallBack)(int64_t, LPVOID);
typedef pTaskJobFunc LPTASKFUNC;
typedef pTaskCallBack LPTASKCALLBACK;

/// C++ std style define
typedef shared_ptr<void> SMARTER;
typedef SMARTER(*pSmartJobFunc)(SMARTER);
typedef void(*pSmartCallBack)(long long, SMARTER);
typedef void(*pSmartCallBack)(int64_t, SMARTER);
typedef pSmartJobFunc LPSMARTFUNC;
typedef pSmartCallBack LPSMARTCALLBACK;
typedef std::function<SMARTER(SMARTER)> SmartFunction;
typedef std::function<SMARTER(long long,SMARTER)> SmartCallbackFunction;
typedef std::function<SMARTER(int64_t,SMARTER)> SmartCallbackFunction;
enum TaskType {
Normal,
SmartParam,
Expand Down Expand Up @@ -78,6 +78,8 @@ namespace Sloong

static int AddWorkThread(std::function<void(SMARTER)> pJob, SMARTER pParam = nullptr, int nNum = 1);

static int AddWorkThread(std::function<void(void)> pJob, int nNum = 1);

protected:
static map<ULONG, shared_ptr<TaskParam>> m_oJobList;
static vector<thread*> m_pThreadList;
Expand Down
Loading

0 comments on commit 816da8d

Please sign in to comment.