/*===========================================================================* * key_c * *===========================================================================*/ static void *key_c(void *arg) { /* The only thing that this thread should do, is set a value. */ if (mthread_setspecific(key[0], (void *) mthread_self()) != 0) err(19, 1); mthread_yield(); if (!mthread_equal((thread_t) mthread_getspecific(key[0]), mthread_self())) err(19, 2); return(NULL); }
static void * threadfunc(void * arg) { char *name = arg; printf("je suis le thread %p, lancé avec l'argument %s\n", mthread_self(), name); mthread_yield(); printf("je suis encore le thread %p, lancé avec l'argument %s\n", mthread_self(), name); mthread_exit(arg); return NULL; }
/*===========================================================================* * check_vmnt_locks_by_me * *===========================================================================*/ PUBLIC void check_vmnt_locks_by_me(struct fproc *rfp) { /* Check whether this thread still has locks held on vmnts */ struct vmnt *vmp; for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) { if (tll_locked_by_me(&vmp->m_lock)) panic("Thread %d still holds vmnt lock on vmp %p call_nr=%d\n", mthread_self(), vmp, call_nr); } if (rfp->fp_vmnt_rdlocks != 0) panic("Thread %d still holds read locks on a vmnt (%d) call_nr=%d\n", mthread_self(), rfp->fp_vmnt_rdlocks, call_nr); }
/*===========================================================================* * worker_self * *===========================================================================*/ PUBLIC struct worker_thread *worker_self(void) { struct worker_thread *worker; worker = worker_get(mthread_self()); assert(worker != NULL); return(worker); }
/*===========================================================================* * check_vnode_locks_by_me * *===========================================================================*/ PUBLIC void check_vnode_locks_by_me(struct fproc *rfp) { /* Check whether this thread still has locks held on vnodes */ struct vnode *vp; for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; vp++) { if (tll_locked_by_me(&vp->v_lock)) { panic("Thread %d still holds vnode lock on vp %x call_nr=%d\n", mthread_self(), vp, call_nr); } } if (rfp->fp_vp_rdlocks != 0) panic("Thread %d still holds read locks on a vnode (%d) call_nr=%d\n", mthread_self(), rfp->fp_vp_rdlocks, call_nr); }
/*===========================================================================* * worker_init * *===========================================================================*/ void worker_init(struct worker_thread *wp) { /* Initialize worker thread */ if (!init) { threads_init(); if (mthread_attr_init(&tattr) != 0) panic("failed to initialize attribute"); if (mthread_attr_setstacksize(&tattr, TH_STACKSIZE) != 0) panic("couldn't set default thread stack size"); if (mthread_attr_setdetachstate(&tattr, MTHREAD_CREATE_DETACHED) != 0) panic("couldn't set default thread detach state"); invalid_thread_id = mthread_self(); /* Assuming we're the main thread*/ pending = 0; init = 1; } ASSERTW(wp); wp->w_job.j_func = NULL; /* Mark not in use */ wp->w_next = NULL; if (mutex_init(&wp->w_event_mutex, NULL) != 0) panic("failed to initialize mutex"); if (cond_init(&wp->w_event, NULL) != 0) panic("failed to initialize conditional variable"); if (mthread_create(&wp->w_tid, &tattr, worker_main, (void *) wp) != 0) panic("unable to start thread"); yield(); }
/*===========================================================================* * reply * *===========================================================================*/ void reply(endpoint_t whom, int result) { /* Send a reply to a user process. If the send fails, just ignore it. */ int r; m_out.reply_type = result; r = sendnb(whom, &m_out); if (r != OK) { printf("VFS: %d couldn't send reply %d to %d: %d\n", mthread_self(), result, whom, r); util_stacktrace(); } }
/*===========================================================================* * check_filp_locks * *===========================================================================*/ void check_filp_locks_by_me(void) { /* Check whether this thread still has filp locks held */ struct filp *f; int r; for (f = &filp[0]; f < &filp[NR_FILPS]; f++) { r = mutex_trylock(&f->filp_lock); if (r == -EDEADLK) panic("Thread %d still holds filp lock on filp %p call_nr=%d\n", mthread_self(), f, job_call_nr); else if (r == 0) { /* We just obtained the lock, release it */ mutex_unlock(&f->filp_lock); } } }