void* pthread_user_data_get(pthread_t thread);
void pthread_user_data_set(pthread_t thread, void *usr);
void pthread_user_data_cleanup(void * arg);
+int pthread_user_data_internal_iterate(int (*routine)(pthread_t), void *arg);
// Pausing
void pthread_pause_disable();
int pthread_pause(pthread_t thread);
int pthread_unpause(pthread_t thread);
+int pthread_pause_all();
+int pthread_unpause_all();
int pthread_pause_reschedule(pthread_t thread);
int pthread_extra_yield();
///When this variable is nonzero, only referenced thread is allowed to run
///Access has to be protected by pthread_user_data_lock()
-pthread_t pthread_pause_holder = 0;
+pthread_t pthread_pause_holder = PTHREAD_XNULL;
void pthread_pause_handler(const int signal, siginfo_t *info, void *ptr) {
(void)signal; (void)info; (void)ptr;
//Check if thread has running flag
int run = (pthread_user_data_internal(thread)->running);
//Check if privileged (single thread) mode is active
- if((pthread_pause_holder != 0) && !pthread_equal(pthread_pause_holder, thread)) {
+ if((pthread_pause_holder != PTHREAD_XNULL) && !pthread_equal(pthread_pause_holder, thread)) {
run = 0;
}
pthread_user_data_unlock();
int pthread_pause_all() {
pthread_user_data_lock();
- if(pthread_pause_holder!=0) assert(pthread_equal(pthread_pause_holder, pthread_self()));
+ if(pthread_pause_holder!=PTHREAD_XNULL) assert(pthread_equal(pthread_pause_holder, pthread_self()));
pthread_pause_holder = pthread_self();
pthread_user_data_unlock();
- //todo reschedule all
+ pthread_user_data_internal_iterate(&pthread_pause_reschedule, NULL);
return 0;
}
int pthread_unpause_all() {
pthread_user_data_lock();
- if(pthread_pause_holder!=0) assert(pthread_equal(pthread_pause_holder, pthread_self()));
- pthread_pause_holder = 0;
+ if(pthread_pause_holder!=PTHREAD_XNULL) assert(pthread_equal(pthread_pause_holder, pthread_self()));
+ pthread_pause_holder = PTHREAD_XNULL;
pthread_user_data_unlock();
- //todo reschedule
+ pthread_user_data_internal_iterate(&pthread_pause_reschedule, NULL);
return 0;
}
return &pthread_user_data[i];
}
+//Iterate specified callback over all registered threads
+int pthread_user_data_internal_iterate(int (*routine)(pthread_t), void *arg) {
+ (void) arg;
+ int i;
+ pthread_user_data_lock();
+ for(i = 0; i<PTHREAD_XTHREADS_MAX; i++) {
+ if(pthread_equal(pthread_user_data[i].tid, PTHREAD_XNULL)) break;
+ routine(pthread_user_data[i].tid);
+ }
+ pthread_user_data_unlock();
+ return i;
+}
+
//Get pointer to user specified pointer of that thread
void** pthread_user_data_ptr(pthread_t thread) {
return &pthread_user_data_internal(thread)->usr;