]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/system/ArbiterP.nc
Inserted a check into Resource.request() that controls if the current caller id has...
[tinyos-2.x.git] / tos / system / ArbiterP.nc
index c25f69f4a04f35855416a816581e12809c29d8d6..bf66c2c58d047c6636fc5df0e505fbd38bd8261b 100644 (file)
@@ -49,7 +49,7 @@
  * @author Philip Levis
  */
  
-generic module ArbiterP(uint8_t default_owner_id) {
+generic module ArbiterP(uint8_t default_owner_id) @safe() {
   provides {
     interface Resource[uint8_t id];
     interface ResourceRequested[uint8_t id];
@@ -81,6 +81,9 @@ implementation {
         state = RES_GRANTING;
         reqResId = id;
       }
+      else if (reqResId == id) {
+       return SUCCESS;
+      }
       else return call Queue.enqueue(id);
     }
     signal ResourceDefaultOwner.requested();
@@ -110,15 +113,18 @@ implementation {
       if(state == RES_BUSY && resId == id) {
         if(call Queue.isEmpty() == FALSE) {
           reqResId = call Queue.dequeue();
+          resId = NO_RES;
           state = RES_GRANTING;
           post grantedTask();
+          call ResourceConfigure.unconfigure[id]();
         }
         else {
           resId = default_owner_id;
           state = RES_CONTROLLED;
+          call ResourceConfigure.unconfigure[id]();
           signal ResourceDefaultOwner.granted();
         }
-        call ResourceConfigure.unconfigure[id]();
+        return SUCCESS;
       }
     }
     return FAIL;
@@ -176,7 +182,9 @@ implementation {
   }
 
   async command uint8_t ResourceDefaultOwner.isOwner() {
-    atomic return (state == RES_CONTROLLED);
+    atomic return (state == RES_CONTROLLED
+            || (resId == default_owner_id
+                && (state == RES_GRANTING || state == RES_IMM_GRANTING)));
   }
   
   task void grantedTask() {