Ejemplo n.º 1
0
static STATUS xsem_take(struct wind_sem *sem, int timeout)
{
	struct timespec ts, *timespec;
	struct syncstate syns;
	struct service svc;
	STATUS ret = OK;

	if (threadobj_irq_p())
		return S_intLib_NOT_ISR_CALLABLE;

	CANCEL_DEFER(svc);

	if (syncobj_lock(&sem->u.xsem.sobj, &syns)) {
		ret = S_objLib_OBJ_ID_ERROR;
		goto out;
	}

	if (--sem->u.xsem.value >= 0)
		goto done;

	if (timeout == NO_WAIT) {
		sem->u.xsem.value++;
		ret = S_objLib_OBJ_UNAVAILABLE;
		goto done;
	}

	if (timeout != WAIT_FOREVER) {
		timespec = &ts;
		clockobj_ticks_to_timeout(&wind_clock, timeout, timespec);
	} else
		timespec = NULL;

	ret = syncobj_wait_grant(&sem->u.xsem.sobj, timespec, &syns);
	if (ret == -EIDRM) {
		ret = S_objLib_OBJ_DELETED;
		goto out;
	}
	if (ret) {
		sem->u.xsem.value++;
		if (ret == -ETIMEDOUT)
			ret = S_objLib_OBJ_TIMEOUT;
		else if (ret == -EINTR)
			ret = OK;	/* Flushed. */
	}
done:
	syncobj_unlock(&sem->u.xsem.sobj, &syns);
out:
	CANCEL_RESTORE(svc);

	return ret;
}
Ejemplo n.º 2
0
u_long tm_evevery(u_long ticks, u_long events, u_long *tmid_r)
{
	struct itimerspec it;
	struct service svc;
	int ret;

	COPPERPLATE_PROTECT(svc);
	clockobj_ticks_to_timeout(&psos_clock, ticks, &it.it_value);
	clockobj_ticks_to_timespec(&psos_clock, ticks, &it.it_interval);
	ret = start_evtimer(events, &it, tmid_r);
	COPPERPLATE_UNPROTECT(svc);

	return ret;
}
Ejemplo n.º 3
0
int rt_cond_wait_until(RT_COND *cond, RT_MUTEX *mutex,
		       RTIME timeout)
{
	struct alchemy_mutex *mcb;
	struct alchemy_cond *ccb;
	struct service svc;
	struct timespec ts;
	int ret = 0;

	if (timeout == TM_NONBLOCK)
		return -EWOULDBLOCK;

	COPPERPLATE_PROTECT(svc);

	ccb = get_alchemy_cond(cond, &ret);
	if (ccb == NULL)
		goto out;

	mcb = find_alchemy_mutex(mutex, &ret);
	if (mcb == NULL)
		goto unlock;

	ccb->nwaiters++;
	put_alchemy_cond(ccb);

	if (timeout != TM_INFINITE) {
		clockobj_ticks_to_timeout(&alchemy_clock, timeout, &ts);
		ret = -__RT(pthread_cond_timedwait(&ccb->cond, &mcb->lock, &ts));
	} else
		ret = -__RT(pthread_cond_wait(&ccb->cond, &mcb->lock));

	/*
	 * Be cautious, grab the internal safe lock again to update
	 * the control block.
	 */
	ccb = __get_alchemy_cond(ccb, &ret);
	if (ccb == NULL)
		goto out;

	ccb->nwaiters--;
unlock:
	put_alchemy_cond(ccb);
out:
	COPPERPLATE_UNPROTECT(svc);

	return ret;
}
Ejemplo n.º 4
0
u_long tm_wkafter(u_long ticks)
{
	struct timespec rqt;
	struct service svc;

	if (ticks == 0) {
		sched_yield();	/* Manual round-robin. */
		return SUCCESS;
	}

	COPPERPLATE_PROTECT(svc);
	clockobj_ticks_to_timeout(&psos_clock, ticks, &rqt);
	COPPERPLATE_UNPROTECT(svc);
	threadobj_sleep(&rqt);

	return SUCCESS;
}
Ejemplo n.º 5
0
STATUS wdStart(WDOG_ID wdog_id, int delay, void (*handler)(long), long arg)
{
	struct itimerspec it;
	struct service svc;
	struct wind_wd *wd;
	int ret;

	wd = find_wd_from_id(wdog_id);
	if (wd == NULL)
		goto objid_error;

	/*
	 * FIXME: we have a small race window here in case the
	 * watchdog is wiped out while we set the timer up; we would
	 * then write to stale memory.
	 */
	wd->handler = handler;
	wd->arg = arg;

	COPPERPLATE_PROTECT(svc);

	clockobj_ticks_to_timeout(&wind_clock, delay, &it.it_value);
	it.it_interval.tv_sec = 0;
	it.it_interval.tv_nsec = 0;
	ret = timerobj_start(&wd->tmobj, watchdog_handler, &it);

	COPPERPLATE_UNPROTECT(svc);

	if (ret) {
	objid_error:
		errno = S_objLib_OBJ_ID_ERROR;
		return ERROR;
	}

	return OK;
}