Originally Posted by
awsdert
Dunno what that is, gimme a moment to look it up
Judging from what I saw on wikipedia I'd say yes but without any knowledge of the resources, this is merely to prevent changes occurring to the accompanying data while another is trying to change or glance at it, simple example of intent:
Code:
typdef struct zthread {
uint count;
zque_t zque;
} zthread_t;
...
ret = zque_get_change_perm( &(zthread->zque), 1 );
if ( ret == -1 ) return;
zthread->count++;
zque_rem_change_perm( &(zthread->zque) );
// here on only reads of non-allocated data should occur
Also after thinking about it while waiting for a reply I decided to merge the glance & change variables into one for the sake of avoiding more race based scenarios I thought of that would occur otherwise so the code now looks like this:
Code:
typedef struct zque {
int id;
int ret;
_Bool active;
uint pos;
uint que;
} zque_t;
#define zque_null ((zque_t){-1,0})
int zque_get_rwperm( zque_t *zque, uint sec )
{
uint pos = ++(zque->que);
while ( zque->pos != pos )
{
sleep(sec);
if ( !(zque->active) ) return -1;
}
return 0;
}
void zque_rem_rwperm( zque_t *zque )
{
zque->pos = 0;
}