Skip to content

Commit

Permalink
liblegacy: Optionally using a std::function as thread callback
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 22, 2015
1 parent f7db964 commit 09a5e46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions doomsday/sdk/liblegacy/include/de/concurrency.h
Expand Up @@ -27,8 +27,6 @@
#include <de/liblegacy.h>

typedef void *thread_t;
typedef int (*systhreadfunc_t) (void *parm);

typedef void *mutex_t;
typedef void *sem_t;

Expand All @@ -40,6 +38,9 @@ typedef enum systhreadexitstatus_e {

#ifdef __cplusplus

#include <functional>
typedef std::function<int (void *)> systhreadfunc_t;

#ifdef __DENG__ // libdeng internal
#include <QThread>
/**
Expand Down Expand Up @@ -69,8 +70,11 @@ protected slots:
systhreadexitstatus_t _exitStatus;
void (*_terminationFunc)(systhreadexitstatus_t);
};

#endif // __DENG__

DENG_PUBLIC thread_t Sys_StartThread(systhreadfunc_t startpos, void *parm);

extern "C" {
#endif // __cplusplus

Expand All @@ -93,7 +97,7 @@ extern "C" {
*
* @return Thread handle.
*/
DENG_PUBLIC thread_t Sys_StartThread(systhreadfunc_t startpos, void *parm);
DENG_PUBLIC thread_t Sys_StartThread(int (*startpos)(void *), void *parm);

DENG_PUBLIC void Thread_Sleep(int milliseconds);

Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/liblegacy/src/concurrency.cpp
Expand Up @@ -134,6 +134,11 @@ thread_t Sys_StartThread(systhreadfunc_t startpos, void *parm)
return t;
}

thread_t Sys_StartThread(int (*startpos)(void *), void *parm)
{
return Sys_StartThread(systhreadfunc_t(startpos), parm);
}

void Thread_KillAbnormally(thread_t handle)
{
QThread *t = reinterpret_cast<QThread *>(handle);
Expand Down

0 comments on commit 09a5e46

Please sign in to comment.