From: liang_mike Date: Tue, 10 Feb 2009 03:42:45 +0000 (+0000) Subject: Use SystemCallC to pass control to the TinyOS thread X-Git-Tag: rc_6_tinyos_2_1_1~494 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=1a81ad6e619bb7803f151a2f4d025366e7e73604 Use SystemCallC to pass control to the TinyOS thread --- diff --git a/tos/lib/tosthreads/lib/net/BlockingCollectionControlC.nc b/tos/lib/tosthreads/lib/net/BlockingCollectionControlC.nc index e7b21822..4a775542 100644 --- a/tos/lib/tosthreads/lib/net/BlockingCollectionControlC.nc +++ b/tos/lib/tosthreads/lib/net/BlockingCollectionControlC.nc @@ -32,11 +32,15 @@ configuration BlockingCollectionControlC { } implementation { - components BlockingCollectionControlP, - CollectionC as Collector; + components CollectionC as Collector, + SystemCallC, + MutexC, + BlockingCollectionControlP; RoutingControl = BlockingCollectionControlP.BlockingStdControl; RootControl = Collector; BlockingCollectionControlP.RoutingControl -> Collector.StdControl; + BlockingCollectionControlP.SystemCall -> SystemCallC; + BlockingCollectionControlP.Mutex -> MutexC; } diff --git a/tos/lib/tosthreads/lib/net/BlockingCollectionControlP.nc b/tos/lib/tosthreads/lib/net/BlockingCollectionControlP.nc index b2d920af..1bb62b19 100644 --- a/tos/lib/tosthreads/lib/net/BlockingCollectionControlP.nc +++ b/tos/lib/tosthreads/lib/net/BlockingCollectionControlP.nc @@ -26,22 +26,59 @@ module BlockingCollectionControlP { provides { - interface BlockingStdControl; + interface BlockingStdControl; + interface Init; } uses { interface StdControl as RoutingControl; + interface SystemCall; + interface Mutex; } } implementation { - command error_t BlockingStdControl.start() + typedef struct params { + error_t error; + } params_t; + + syscall_t* start_call = NULL; + mutex_t my_mutex; + + command error_t Init.init() { - return call RoutingControl.start(); + call Mutex.init(&my_mutex); + return SUCCESS; } - command error_t BlockingStdControl.stop() + void startTask(syscall_t* s) { + params_t* p = s->params; + p->error = call RoutingControl.start(); + call SystemCall.finish(s); + } + + command error_t BlockingStdControl.start() + { + syscall_t s; + params_t p; + + call Mutex.lock(&my_mutex); + if (start_call == NULL) { + start_call = &s; + call SystemCall.start(&startTask, &s, INVALID_ID, &p); + start_call = NULL; + } else { + p.error = EBUSY; + } + + atomic { + call Mutex.unlock(&my_mutex); + return p.error; + } + } + + command error_t BlockingStdControl.stop() { return call RoutingControl.stop(); } }