// PIDs
const int MAX_THREADS = 3;
typedef scalar[MAX_THREADS] pid_t;
// Conditions
const int MAX_CONDS = 1;
typedef scalar[MAX_CONDS] cid_t;
// PID Queues
const int CAPACITY = MAX_THREADS;
typedef int[0,CAPACITY-1] index_t;
typedef int[0,CAPACITY] cont_t;
index_t inc(index_t i)
{
if (i == CAPACITY - 1)
return 0;
else
return i+1;
}
typedef struct {
pid_t data[CAPACITY];
index_t first;
index_t next;
cont_t n;
} pid_queue_t;
void reset(pid_queue_t &q)
{
q.n = 0;
q.first = 0;
q.next = 0;
}
cont_t size(pid_queue_t q)
{
return q.n;
}
void push(pid_queue_t &q, pid_t pid)
{
q.data[q.next] = pid;
q.next := inc(q.next);
q.n++;
}
pid_t first(pid_queue_t q)
{
return q.data[q.first];
}
pid_t pop(pid_queue_t &q)
{
index_t i = q.first;
q.first := inc(q.first);
q.n--;
return q.data[i];
}
void requeue(pid_queue_t &from, pid_queue_t &to)
{
if (size(from) > 0) {
push(to,pop(from));
}
}
// Channels
chan lock[pid_t];
chan lock_granted[pid_t];
chan unlock[pid_t];
chan await[cid_t][pid_t];
chan signal[cid_t];
Lockpid_queue_t lq;
pid_queue_t cq[cid_t];
LockedUnlockedThreadpid_t pidAwaitingHasTheLockLockingOut// Place template instantiations here.
// Process = Monitor();
// List one or more processes to be composed into a system.
system Lock, Thread;