Res is a double bounded (n>=0 && n<=max number of token) token abstract resource for synchronising Process objects. A process is blocked if it tries to acquire more token than are left or if it tries to release more token than there is room left. It is reactivated when enough token are released or acquired. If multiple processes are waiting for reactivation process-priority and FIFO-strategy are used to choose the process. Res is generally used for strong limited resource modelling or producer consumer synchronisation with limited storage capacity.
Public Member Functions | |
Res (Simulation *s, Label l, unsigned int startTokenNumber, unsigned int maxTokenNumber, ResObserver *o=0) | |
Construction. | |
~Res () | |
Destruction. | |
const std::list< Process * > & | getWaitingForAcquire () const |
Get list of blocked processes. | |
virtual Trace * | getTrace () const |
Pointer to trace. | |
virtual void | report (Report *r) |
Generate report. | |
Token management | |
unsigned int | acquire (unsigned int n) |
Acquire n token. | |
void | release (unsigned int n) |
Release n token. | |
void | control (unsigned int n) |
Add token to resource. | |
unsigned int | unControl (unsigned int n) |
Remove n token from resource. | |
unsigned int | getTokenNumber () const |
Current number of token availiable. | |
unsigned int | getTokenLimit () const |
Maximum number of token. | |
Statistics | |
Statistics | |
virtual void | reset () |
Reset statistics. | |
unsigned int | getAcquires () const |
Number of takes. | |
unsigned int | getReleases () const |
Number of gives. | |
unsigned int | getInitial () const |
Init number of token. | |
unsigned int | getMin () const |
Min number of token. | |
unsigned int | getMax () const |
Max number of token. | |
double | getAVFreeToken () const |
Average free token. | |
double | getAVWaitTime () const |
Average waiting time. | |
Static Public Attributes | |
Res specific marks | |
const MarkTypeId | baseMarkId = 1000 |
const MarkType | markCreate = MarkType("create", baseMarkId+1, typeid(Res)) |
const MarkType | markDestroy = MarkType("destroy", baseMarkId+2, typeid(Res)) |
const MarkType | markAcquireFail = MarkType("acquireFail", baseMarkId+10, typeid(Res)) |
const MarkType | markAcquireSucceed = MarkType("acquireSucceed", baseMarkId+11, typeid(Res)) |
const MarkType | markReleaseFail = MarkType("releaseFail", baseMarkId+12, typeid(Res)) |
const MarkType | markReleaseSucceed = MarkType("releaseSucceed", baseMarkId+13, typeid(Res)) |
const MarkType | markChangeTokenNumber = MarkType("changeTokenNumber", baseMarkId+20, typeid(Res)) |
const TagId | baseTagId = 1000 |
const Tag | tagCurrent = Tag(baseTagId+1) |
const Tag | tagTokenNumber = Tag(baseTagId+2) |
|
Construction.
|
|
Acquire
If there aren't enough token in Res the current process is blocked. If a blocked process is interrupted it is reactivated and acquire() returns 0. Otherwise the function returns |
|
Release
Returns |
|
Add token to resource. Add token to the managed token set. |
|
Remove Remove token from the managed token set. If there are not enough token left in the resource, the current process is blocked. When a blocked process is interrupted, the attempt to take token is cancelled and the function returns 0. |