X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fsystem%2FSharedArbiterP.nc;h=b912fa19b5df67bfd594f7d4af1362a9dc82fd1c;hb=ae00d087aa959de065570bcd79090480097b69e6;hp=f13e03c2cc3cc503568d9e12864fca1e64d16e8e;hpb=ae0ac21f5f88b0b8cc8e6a3a440be198d3a74bd6;p=tinyos-2.x.git diff --git a/tos/system/SharedArbiterP.nc b/tos/system/SharedArbiterP.nc index f13e03c2..b912fa19 100644 --- a/tos/system/SharedArbiterP.nc +++ b/tos/system/SharedArbiterP.nc @@ -38,7 +38,6 @@ generic module SharedArbiterP() { provides { - interface Init; interface Resource[uint8_t id]; interface ResourceDefaultOwner; interface ArbiterInfo; @@ -53,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, @@ -117,13 +117,6 @@ implementation { } } - command error_t Init.init() - { - call GrantedVector.clearAll(); - call RequestingVector.clearAll(); - return SUCCESS; - } - async command error_t Resource.request[uint8_t id]() { /* The Resource docs do not say what happens when a user calls @@ -134,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; } @@ -150,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; @@ -173,14 +169,15 @@ implementation { async command error_t ResourceDefaultOwner.release() { - atomic { - if (m_requesting > 0) { - call State.forceState(S_GRANTED); - post grantedTask(); - return SUCCESS; - } else - return FAIL; - } + 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; } async command bool ArbiterInfo.inUse()