changed to raise/lower the number of IO semaphores being waited on when a semaphore is added/removed to/from a semaphore group.

reverted semaphore removal disallowance implemented in the previous revision
This commit is contained in:
hyunghwan.chung 2017-11-04 03:41:08 +00:00
parent 27c2c5b404
commit 384c5702bf

View File

@ -2584,12 +2584,21 @@ static moo_pfrc_t pf_semaphore_group_add_semaphore (moo_t* moo, moo_ooi_t nargs)
MOO_APPEND_TO_OOP_LIST (moo, &rcv->sems[sems_idx], moo_oop_semaphore_t, sem, grm); MOO_APPEND_TO_OOP_LIST (moo, &rcv->sems[sems_idx], moo_oop_semaphore_t, sem, grm);
sem->group = rcv; sem->group = rcv;
if (MOO_OOP_TO_SMOOI(sem->io_index) >=0) if (MOO_OOP_TO_SMOOI(sem->io_index) >= 0)
{ {
moo_ooi_t count; moo_ooi_t count;
count = MOO_OOP_TO_SMOOI(rcv->sem_io_count); count = MOO_OOP_TO_SMOOI(rcv->sem_io_count);
MOO_ASSERT (moo, count >= 0);
count++; count++;
rcv->sem_io_count = MOO_SMOOI_TO_OOP(count); rcv->sem_io_count = MOO_SMOOI_TO_OOP(count);
if (count == 1)
{
moo_oop_process_t wp;
/* TODO: add sem_wait_count to process. no traversal... */
for (wp = rcv->waiting.first; (moo_oop_t)wp != moo->_nil; wp = wp->sem_wait.next)
moo->sem_io_wait_count++;
}
} }
MOO_STACK_SETRETTORCV (moo, nargs); MOO_STACK_SETRETTORCV (moo, nargs);
@ -2623,6 +2632,7 @@ static moo_pfrc_t pf_semaphore_group_remove_semaphore (moo_t* moo, moo_ooi_t nar
{ {
int sems_idx; int sems_idx;
#if 0
if ((moo_oop_t)rcv->waiting.first != moo->_nil) if ((moo_oop_t)rcv->waiting.first != moo->_nil)
{ {
/* there is a process waiting on this semaphore group. /* there is a process waiting on this semaphore group.
@ -2640,6 +2650,7 @@ static moo_pfrc_t pf_semaphore_group_remove_semaphore (moo_t* moo, moo_ooi_t nar
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EPERM); MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EPERM);
goto done; goto done;
} }
#endif
sems_idx = MOO_OOP_TO_SMOOI(sem->count) > 0? MOO_SEMAPHORE_GROUP_SEMS_SIG: MOO_SEMAPHORE_GROUP_SEMS_UNSIG; sems_idx = MOO_OOP_TO_SMOOI(sem->count) > 0? MOO_SEMAPHORE_GROUP_SEMS_SIG: MOO_SEMAPHORE_GROUP_SEMS_UNSIG;
MOO_DELETE_FROM_OOP_LIST (moo, &rcv->sems[sems_idx], sem, grm); MOO_DELETE_FROM_OOP_LIST (moo, &rcv->sems[sems_idx], sem, grm);
@ -2654,6 +2665,14 @@ static moo_pfrc_t pf_semaphore_group_remove_semaphore (moo_t* moo, moo_ooi_t nar
MOO_ASSERT (moo, count > 0); MOO_ASSERT (moo, count > 0);
count--; count--;
rcv->sem_io_count = MOO_SMOOI_TO_OOP(count); rcv->sem_io_count = MOO_SMOOI_TO_OOP(count);
if (count == 0)
{
moo_oop_process_t wp;
/* TODO: add sem_wait_count to process. no traversal... */
for (wp = rcv->waiting.first; (moo_oop_t)wp != moo->_nil; wp = wp->sem_wait.next)
moo->sem_io_wait_count--;
}
} }
MOO_STACK_SETRETTORCV (moo, nargs); MOO_STACK_SETRETTORCV (moo, nargs);