]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/system/ArbiterP.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tos / system / ArbiterP.nc
index 872b71f6fa8a99ad8ce3a4cb712f0e9988a391c4..b07f975dc4e5b2b2e762a90c020aff7772ec43cf 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];
@@ -110,15 +110,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 +179,9 @@ implementation {
   }
 
   async command uint8_t ResourceDefaultOwner.isOwner() {
-    return call Resource.isOwner[default_owner_id]();
+    atomic return (state == RES_CONTROLLED
+            || (resId == default_owner_id
+                && (state == RES_GRANTING || state == RES_IMM_GRANTING)));
   }
   
   task void grantedTask() {