]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/system/SimpleArbiterP.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tos / system / SimpleArbiterP.nc
index a3cfcae8106a4a6196dcc8a4e35f6a68acd4238a..30f185f2e99926602161b29f6652717f326437a4 100644 (file)
  * there are no pending requests, then the resource becomes idle and any
  * user can put in a request and immediately receive access to the
  * Resource.
- *
- * @param <b>resourceName</b> -- The name of the Resource being shared
  * 
  * @author Kevin Klues (klues@tkn.tu-berlin.de)
  * @author Philip Levis
  */
  
-generic module SimpleArbiterP() {
+generic module SimpleArbiterP() @safe() {
   provides {
     interface Resource[uint8_t id];
     interface ResourceRequested[uint8_t id];
@@ -101,6 +99,7 @@ implementation {
     atomic {
       if(state == RES_BUSY && resId == id) {
         if(call Queue.isEmpty() == FALSE) {
+          resId = NO_RES;
           reqResId = call Queue.dequeue();
           state = RES_GRANTING;
           post grantedTask();
@@ -136,7 +135,11 @@ implementation {
     will be 0xFF
   */      
   async command uint8_t ArbiterInfo.userId() {
-    atomic return resId;
+    atomic {
+      if(state != RES_BUSY)
+        return NO_RES;
+      return resId;
+    }
   }
 
   /**
@@ -144,7 +147,7 @@ implementation {
    */      
   async command uint8_t Resource.isOwner[uint8_t id]() {
     atomic {
-      if(resId == id) return TRUE;
+      if(resId == id && state == RES_BUSY) return TRUE;
       else return FALSE;
     }
   }