X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Flib%2Ftosthreads%2Fsystem%2FTinyThreadSchedulerP.nc;h=e93af1916ba4dbc45ae2f1e745f04d7b2a22a693;hb=4f00f40a7c40b8ba3493abc904f895aeba5d7a09;hp=1ae67708558488bad103d2c6760a5a5d2dd75864;hpb=729c2ae97fd4657e60118af9793374124358a925;p=tinyos-2.x.git diff --git a/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc b/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc index 1ae67708..e93af191 100644 --- a/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc +++ b/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc @@ -43,6 +43,7 @@ module TinyThreadSchedulerP { interface Boot as ThreadSchedulerBoot; interface ThreadInfo[uint8_t id]; interface ThreadQueue; + interface BitArrayUtils; interface McuSleep; interface Leds; interface Timer as PreemptionAlarm; @@ -138,8 +139,13 @@ implementation { * threads by the thread scheduler. */ void stop(thread_t* t) { + int i; t->state = TOSTHREAD_STATE_INACTIVE; num_started_threads--; + for(i=0; ijoinedOnMe, i)) + call ThreadScheduler.wakeupThread(i); + } if(num_started_threads == 1) call PreemptionAlarm.stop(); signal ThreadCleanup.cleanup[t->id](); @@ -178,6 +184,7 @@ implementation { thread_t* t = (call ThreadInfo.get[id]()); t->state = TOSTHREAD_STATE_INACTIVE; t->init_block = current_thread->init_block; + call BitArrayUtils.clrArray(t->joinedOnMe, sizeof(t->joinedOnMe)); PREPARE_THREAD(t, threadWrapper); return SUCCESS; } @@ -232,6 +239,20 @@ implementation { } } + async command error_t ThreadScheduler.joinThread(thread_id_t id) { + thread_t* t = call ThreadInfo.get[id](); + atomic { + if(current_thread == tos_thread) + return FAIL; + if (t->state != TOSTHREAD_STATE_INACTIVE) { + call BitArrayUtils.setBit(t->joinedOnMe, current_thread->id); + call ThreadScheduler.suspendCurrentThread(); + return SUCCESS; + } + } + return EALREADY; + } + async command error_t ThreadScheduler.wakeupThread(uint8_t id) { thread_t* t = call ThreadInfo.get[id](); if((t->state) == TOSTHREAD_STATE_SUSPENDED) {