Exemple #1
0
int
main(int argc, char *argv[])
{
	struct timerinfo info;
	task_t task;
	char stack[16];
	u_long start, end;
	int i, pri, error;

	printf("Benchmark to create/terminate %d threads\n", NR_THREADS);

	sys_info(INFO_TIMER, &info);
	if (info.hz == 0)
		panic("can not get timer tick rate");

	thread_getpri(thread_self(), &pri);
	thread_setpri(thread_self(), pri - 1);

	task = task_self();
	error = vm_allocate(task, (void **)&thread,
			    sizeof(thread_t) * NR_THREADS, 1);
	if (error)
		panic("vm_allocate is failed");

	sys_time(&start);

	/*
	 * Create threads
	 */
	for (i = 0; i < NR_THREADS; i++) {
		if (thread_create(task, &thread[i]) != 0)
			panic("thread_create is failed");

		if (thread_load(thread[i], null_thread, &stack) != 0)
			panic("thread_load is failed");

		if (thread_resume(thread[i]) != 0)
			panic("thread_resume is failed");
	}

	/*
	 * Teminate threads
	 */
	for (i = 0; i < NR_THREADS; i++)
		thread_terminate(thread[i]);

	sys_time(&end);

	vm_free(task, thread);

	printf("Complete. The score is %d msec (%d ticks).\n",
	       (int)((end - start) * 1000 / info.hz),
	       (int)(end - start));

	return 0;
}
Exemple #2
0
static void thread_button_down(ClickRecognizerRef recognizer, void *context)
{
	int current = GetSelectedThreadID();
	subreddit_button_down(recognizer, context);
	if(current != GetSelectedThreadID())
	{
		window_stack_pop(false);
		thread_load();
	}
}
Exemple #3
0
t_status	interface_thread_load(o_syscall*	message)
{
  t_status error;

  error = thread_load(message->u.request.u.thread_load.arg1,
			message->u.request.u.thread_load.arg2);

  message->u.reply.error = error;

  return (STATUS_OK);
}
Exemple #4
0
static thread_t
thread_run(void (*start)(void), char *stack)
{
	thread_t t;

	if (thread_create(task_self(), &t) != 0)
		return 0;
	if (thread_load(t, start, stack) != 0)
		return 0;
	if (thread_resume(t) != 0)
		return 0;
	return t;
}
Exemple #5
0
thread_t
thread_run(void (*start)(void), void *stack)
{
	thread_t t;
	int error;

	error = thread_create(task_self(), &t);
	if (error)
		panic("thread_create is failed");

	error = thread_load(t, start, stack);
	if (error)
		panic("thread_load is failed");

	return t;
}
Exemple #6
0
void
thread_run(void (*start)(void), void *stack)
{
	thread_t t;

	if (thread_create(task_self(), &t) != 0)
		panic("thread_create is failed");

	if (thread_load(t, start, stack) != 0)
		panic("thread_load is failed");

	if (thread_resume(t) != 0)
		panic("thread_resume failed");

	return;
}
Exemple #7
0
static thread_t
thread_run(void (*start)(void), char *stack)
{
	thread_t th;
	int err;

	if ((err = thread_create(task_self(), &th)) != 0)
		panic("thread_create() is failed");

	if ((err = thread_load(th, start, stack)) != 0)
		panic("thread_load() is failed");

	if ((err = thread_resume(th)) != 0)
		panic("thread_resume() is failed");

	return th;
}
Exemple #8
0
/*
 * Run specified routine as a thread.
 */
static int
run_thread(void (*entry)(void))
{
    task_t self;
    thread_t t;
    void *stack, *sp;
    int error;

    self = task_self();
    if ((error = thread_create(self, &t)) != 0)
        return error;
    if ((error = vm_allocate(self, &stack, DFLSTKSZ, 1)) != 0)
        return error;

    sp = (void *)((u_long)stack + DFLSTKSZ - sizeof(u_long) * 3);
    if ((error = thread_load(t, entry, sp)) != 0)
        return error;

    return thread_resume(t);
}
Exemple #9
0
/*
 * Run specified thread
 */
static int
thread_run(void (*start)(void), void *stack)
{
	thread_t t;
	int error;

	error = thread_create(task_self(), &t);
	if (error)
		return error;

	error = thread_load(t, start, stack);
	if (error)
		return error;

	error = thread_resume(t);
	if (error)
		return error;

	return 0;
}
Exemple #10
0
static thread_t
thread_run(char *name, void (*start)(void),
	   void *stack, size_t stack_size, int nice)
{
	thread_t th = 0;
	int rc;

	if ((rc = thread_create(task_self(), &th)) != 0)
		errx(1, "thread_create: %s", strerror(rc));

	if ((rc = thread_load(th, start, (uint8_t*)stack + stack_size)) != 0)
		errx(1, "thread_load: %s", strerror(rc));

	thread_name(th, name);

	if ((rc = thread_setprio(th, PRIO_DFLT + nice)) != 0)
		errx(1, "thread_setprio: %s", strerror(rc));

	if ((rc = thread_resume(th)) != 0)
		errx(1, "thread_resume: %s", strerror(rc));

	return th;
}