THROW0(system_error,errcode,"pthread_key_create failed for xbt_self_thread_key");
main_thread=xbt_new(s_xbt_os_thread_t,1);
+ main_thread->name = (char*)"main";
main_thread->start_routine = NULL;
main_thread->param = NULL;
main_thread->exception = xbt_new(ex_ctx_t, 1);
XBT_CTX_INITIALIZE(main_thread->exception);
+ __xbt_ex_ctx = _os_thread_ex_ctx;
+ __xbt_ex_terminate = _os_thread_ex_terminate;
+
thread_mod_inited = 1;
}
void xbt_os_thread_mod_exit(void) {
return res_thread;
}
+const char* xbt_os_thread_name(xbt_os_thread_t t) {
+ return t->name;
+}
+
+const char* xbt_os_thread_self_name(void) {
+ xbt_os_thread_t self = xbt_os_thread_self();
+ return self?self->name:"main";
+}
void
xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return) {
int errcode;
struct timespec ts_end;
double end = delay + xbt_os_time();
- ts_end.tv_sec = (time_t) floor(end);
- ts_end.tv_nsec = (long) ( ( end - ts_end.tv_sec) * 1000000000);
- DEBUG3("pthread_cond_timedwait(%p,%p,%p)",&(cond->c),&(mutex->m), &ts_end);
- switch ( (errcode=pthread_cond_timedwait(&(cond->c),&(mutex->m), &ts_end)) ) {
- case ETIMEDOUT:
- THROW3(timeout_error,errcode,"condition %p (mutex %p) wasn't signaled before timeout (%f)",
- cond,mutex, delay);
- default:
- THROW4(system_error,errcode,"pthread_cond_timedwait(%p,%p,%f) failed: %s",
- cond,mutex, delay, strerror(errcode));
- }
+
+ if (delay < 0) {
+ xbt_os_cond_wait(cond,mutex);
+ } else {
+ ts_end.tv_sec = (time_t) floor(end);
+ ts_end.tv_nsec = (long) ( ( end - ts_end.tv_sec) * 1000000000);
+ DEBUG3("pthread_cond_timedwait(%p,%p,%p)",&(cond->c),&(mutex->m), &ts_end);
+ switch ( (errcode=pthread_cond_timedwait(&(cond->c),&(mutex->m), &ts_end)) ) {
+ case 0:
+ return;
+ case ETIMEDOUT:
+ THROW3(timeout_error,errcode,"condition %p (mutex %p) wasn't signaled before timeout (%f)",
+ cond,mutex, delay);
+ default:
+ THROW4(system_error,errcode,"pthread_cond_timedwait(%p,%p,%f) failed: %s",
+ cond,mutex, delay, strerror(errcode));
+ }
+ }
}
void xbt_os_cond_signal(xbt_os_cond_t cond) {
return t;
}
+const char* xbt_os_thread_name(xbt_os_thread_t t) {
+ return t->name;
+}
+
+const char* xbt_os_thread_self_name(void) {
+ xbt_os_thread_t t = xbt_os_thread_self();
+ return t?t->name:"main";
+}
+
void
xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return) {