+
+
+
+// Wrappers ///////////////////////////////////////////////////////////
+
+
+typedef struct pthread_extra_wrapper_t {
+ void *(*start_routine)(void *);
+ void *restrict arg;
+} pthread_extra_wrapper_t;
+
+void *pthread_extra_thread_wrapper(void *arg) {
+ pthread_extra_wrapper_t task = *((pthread_extra_wrapper_t*)arg);
+ free(arg);
+
+ //Register new thread to user data structure
+ pthread_user_data_internal(pthread_self());
+
+ //TODO: user_data should do this automaticaly?
+ pthread_cleanup_push(pthread_user_data_cleanup, (void *)pthread_self());
+
+ //Check if we should be running according to pthread_pause sub-scheduler
+ pthread_pause_reschedule(pthread_self());
+
+ return task.start_routine(task.arg);
+
+ pthread_cleanup_pop(1); //Needed by pthread_cleanup_push() macro
+}
+
+int pthread_extra_create(pthread_t *restrict thread,
+ const pthread_attr_t *restrict attr,
+ void *(*start_routine)(void *),
+ void *restrict arg) {
+
+ pthread_extra_wrapper_t *task = malloc(sizeof(pthread_extra_wrapper_t));
+ assert(task != NULL);
+ task->start_routine=start_routine;
+ task->arg=arg;
+ return pthread_create(thread, attr, pthread_extra_thread_wrapper, task);
+}