Exemplo n.º 1
0
WDOG_ID wdCreate(void)
{
	struct wind_wd *wd;
	struct service svc;
	int ret;

	COPPERPLATE_PROTECT(svc);

	wd = pvmalloc(sizeof(*wd));
	if (wd == NULL)
		goto fail;

	ret = timerobj_init(&wd->tmobj);
	if (ret) {
		pvfree(wd);
	fail:
		errno = S_memLib_NOT_ENOUGH_MEMORY;
		wd = NULL;
		goto out;
	}

	wd->magic = wd_magic;
out:
	COPPERPLATE_UNPROTECT(svc);

	return (WDOG_ID)wd;
}
Exemplo n.º 2
0
char *pvstrdup(const char *ptr)
{
	char *str;

	str = pvmalloc(strlen(ptr) + 1);
	if (str == NULL)
		return NULL;

	return strcpy(str, ptr);
}
Exemplo n.º 3
0
static u_long start_evtimer(u_long events,
			    struct itimerspec *it, u_long *tmid_r)
{
	void (*handler)(struct timerobj *tmobj);
	struct psos_task *current;
	struct psos_tm *tm;
	int ret;

	tm = pvmalloc(sizeof(*tm));
	if (tm == NULL)
		return ERR_NOTIMERS;

	pvholder_init(&tm->link);
	tm->events = events;
	tm->magic = tm_magic;

	current = get_psos_task_or_self(0, &ret);
	if (current == NULL) {
		pvfree(tm);
		return ret;
	}

	tm->tid = mainheap_ref(current, u_long);
	pvlist_append(&tm->link, &current->timer_list);
	put_psos_task(current);

	*tmid_r = (u_long)tm;

	ret = timerobj_init(&tm->tmobj);
	if (ret) {
	fail:
		pvlist_remove(&tm->link);
		pvfree(tm);
		return ERR_NOTIMERS;
	}

	handler = post_event_periodic;
	if (it->it_interval.tv_sec == 0 &&
	    it->it_interval.tv_nsec == 0)
		handler = post_event_once;

	ret = timerobj_start(&tm->tmobj, handler, it);
	if (ret)
		goto fail;

	return SUCCESS;
}
Exemplo n.º 4
0
int traceobj_init(struct traceobj *trobj, const char *label, int nr_marks)
{
	pthread_mutexattr_t mattr;
	pthread_condattr_t cattr;
	int ret;

	pthread_mutexattr_init(&mattr);
	pthread_mutexattr_settype(&mattr, mutex_type_attribute);
	pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
	pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_PRIVATE);
	ret = __bt(-__RT(pthread_mutex_init(&trobj->lock, &mattr)));
	pthread_mutexattr_destroy(&mattr);
	if (ret)
		return ret;

	pthread_condattr_init(&cattr);
	pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_PRIVATE);
	ret = __bt(-__RT(pthread_cond_init(&trobj->join, &cattr)));
	pthread_condattr_destroy(&cattr);
	if (ret) {
		__RT(pthread_mutex_destroy(&trobj->lock));
		return ret;
	}

	/*
	 * We make sure not to unblock from threadobj_join() until at
	 * least one thread has called trace_enter() for this trace
	 * object.
	 */
	trobj->nr_threads = -1;

	trobj->label = label;
	trobj->nr_marks = nr_marks;
	trobj->cur_mark = 0;

	if (nr_marks > 0) {
		trobj->marks = pvmalloc(sizeof(struct tracemark) * nr_marks);
		if (trobj->marks == NULL)
			panic("cannot allocate mark table for tracing");
	}

	return 0;
}