]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/tosthreads/lib/net/BlockingCollectionControlP.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tos / lib / tosthreads / lib / net / BlockingCollectionControlP.nc
index b2d920af885872a2b0cd6f5c3d248abe90f9ccd8..1bb62b19fe4d89e9570613f3da4141515c561539 100644 (file)
 
 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();
   }
 }