]> 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 c5e82f290b1be35491db3e63e11f6e671e0d4a14..30f185f2e99926602161b29f6652717f326437a4 100644 (file)
@@ -46,7 +46,7 @@
  * @author Philip Levis
  */
  
-generic module SimpleArbiterP() {
+generic module SimpleArbiterP() @safe() {
   provides {
     interface Resource[uint8_t id];
     interface ResourceRequested[uint8_t id];
@@ -99,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();
@@ -134,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;
+    }
   }
 
   /**
@@ -142,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;
     }
   }