]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Implement proper request states in SharedArbiterP.
authorR. Steve McKown <rsmckown@gmail.com>
Fri, 24 Sep 2010 22:33:50 +0000 (16:33 -0600)
committerR. Steve McKown <rsmckown@gmail.com>
Fri, 24 Sep 2010 22:42:02 +0000 (16:42 -0600)
tos/system/SharedArbiterP.nc

index 40afb970ed91b670578ba4091ac385d323eb3115..b912fa19b5df67bfd594f7d4af1362a9dc82fd1c 100644 (file)
@@ -52,6 +52,7 @@ implementation {
   enum {
     S_IDLE = 0,                /* Resource is not in use; owned by default owner */
     S_REQUESTING,      /* Requesting the resource from the default owner */
+    S_IMMREQUESTING,   /* Immediate resource request from the default owner */
     S_GRANTED,         /* One or more clients have been granted the resource */
 
     NO_CLIENT = 0xff,
@@ -126,9 +127,9 @@ implementation {
       return EBUSY;
 
     addRequesting(id);
-    if (call State.isIdle())
+    if (call State.requestState(S_REQUESTING) == SUCCESS)
       signal ResourceDefaultOwner.requested();
-    if (call State.isState(S_GRANTED))
+    else if (call State.isState(S_GRANTED))
       post grantedTask();
     return SUCCESS;
   }
@@ -142,8 +143,11 @@ implementation {
     if (call RequestingVector.get(id) || call GrantedVector.get(id))
       return EBUSY;
 
-    if (call State.isIdle())
+    if (call State.requestState(S_IMMREQUESTING) == SUCCESS) {
       signal ResourceDefaultOwner.immediateRequested();
+      if (call State.isState(S_IMMREQUESTING))
+       call State.toIdle();
+    }
     if (call State.isState(S_GRANTED)) {
       addGranted(id);
       return SUCCESS;
@@ -165,9 +169,13 @@ implementation {
 
   async command error_t ResourceDefaultOwner.release()
   {
-    if (call State.requestState(S_GRANTED) == SUCCESS) {
+    if (call State.isState(S_REQUESTING)) {
+      call State.forceState(S_GRANTED);
       post grantedTask();
       return SUCCESS;
+    } else if (call State.isState(S_IMMREQUESTING)) {
+      call State.forceState(S_GRANTED);
+      return SUCCESS;
     } else
       return FAIL;
   }