Created
April 13, 2014 20:33
-
-
Save aleksihakli/10601143 to your computer and use it in GitHub Desktop.
pthread_create cpp wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @brief create_fun creates pthreads from void* (*)(P*) typed functions. | |
* | |
* @param f function as void* (*)(P*) function pointer. | |
* @param p parameter as P pointer. | |
* | |
* @return possible error in thread creation, integer from pthread_create. | |
*/ | |
template <typename F, typename P> | |
int create_fun(pthread_t* thread, const pthread_attr_t* attr, F* f, P* p) { | |
void* (*fun)(void*) = reinterpret_cast<void* (*)(void*)>(f); | |
void* param = static_cast<void*>(p); | |
return pthread_create(thread, attr, fun, param); | |
} | |
template <typename F, typename P> | |
int create_fun(pthread_t* thread, F* f, P* p) { | |
return create_fun(thread, nullptr, f, p); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment