X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fsystem%2FSharedArbiterP.nc;h=40afb970ed91b670578ba4091ac385d323eb3115;hb=63b3ea113fdeca4b51bf68fec23354e6a78fafae;hp=c3503131cde02a93edb6d775de6a5b9d807ad0d6;hpb=d8f0e6966930184e8b584a6c9d39849a2f47986c;p=tinyos-2.x.git diff --git a/tos/system/SharedArbiterP.nc b/tos/system/SharedArbiterP.nc index c3503131..40afb970 100644 --- a/tos/system/SharedArbiterP.nc +++ b/tos/system/SharedArbiterP.nc @@ -33,14 +33,11 @@ * switched subsystem. For example, a communications bus that can handle IO * for multiple clients simultaneously, but is powered down when not in use. * - * p_dfltOwnerId = uniqueCount() use by the resource. see SharedArbiterC - * * @author R. Steve McKown */ -generic module SharedArbiterP(uint8_t p_dfltOwnerId) { +generic module SharedArbiterP() { provides { - interface Init; interface Resource[uint8_t id]; interface ResourceDefaultOwner; interface ArbiterInfo; @@ -119,17 +116,14 @@ 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 + * Resource.request() after the resource has already been granted. We + * elect to call EBUSY, as if the request was still in process. + */ if (call RequestingVector.get(id) || call GrantedVector.get(id)) - return FAIL; + return EBUSY; addRequesting(id); if (call State.isIdle()) @@ -141,8 +135,12 @@ implementation { async command error_t Resource.immediateRequest[uint8_t id]() { + /* The Resource docs do not say what happens when a user calls + * Resource.request() after the resource has already been granted. We + * elect to call EBUSY, as if the request was still in process. + */ if (call RequestingVector.get(id) || call GrantedVector.get(id)) - return FAIL; + return EBUSY; if (call State.isIdle()) signal ResourceDefaultOwner.immediateRequested(); @@ -167,14 +165,11 @@ 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.requestState(S_GRANTED) == SUCCESS) { + post grantedTask(); + return SUCCESS; + } else + return FAIL; } async command bool ArbiterInfo.inUse()