X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fsystem%2FArbiterP.nc;h=b07f975dc4e5b2b2e762a90c020aff7772ec43cf;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hp=9650a7073a22cd6e0316fac6dd27063c10163601;hpb=d9c5479d38caf5e9b147f5f99c29af63fe6a33ae;p=tinyos-2.x.git diff --git a/tos/system/ArbiterP.nc b/tos/system/ArbiterP.nc index 9650a707..b07f975d 100644 --- a/tos/system/ArbiterP.nc +++ b/tos/system/ArbiterP.nc @@ -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]; @@ -66,6 +66,7 @@ implementation { enum {RES_CONTROLLED, RES_GRANTING, RES_IMM_GRANTING, RES_BUSY}; enum {default_owner_id = default_owner_id}; + enum {NO_RES = 0xFF}; uint8_t state = RES_CONTROLLED; norace uint8_t resId = default_owner_id; @@ -109,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; @@ -144,6 +148,10 @@ implementation { Check if the Resource is currently in use */ async command bool ArbiterInfo.inUse() { + atomic { + if (state == RES_CONTROLLED) + return FALSE; + } return TRUE; } @@ -153,7 +161,11 @@ implementation { will be 0xFF */ async command uint8_t ArbiterInfo.userId() { - atomic return resId; + atomic { + if(state != RES_BUSY) + return NO_RES; + return resId; + } } /** @@ -161,13 +173,15 @@ 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; } } 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() {