Пример #1
0
int if_boot_interface(ifnet *i)
{
    int err;

    // create the receive thread
    i->rx_thread = thread_create_kernel_thread("net_rx_thread", &if_rx_thread, i);
    if(i->rx_thread < 0) {
        err = i->rx_thread;
        goto err1;
    }

    // create the transmit thread
    i->tx_thread = thread_create_kernel_thread("net_tx_thread", &if_tx_thread, i);
    if(i->tx_thread < 0) {
        err = i->tx_thread;
        goto err2;
    }

    // start the threads
    //thread_resume_thread(i->rx_thread);
    //thread_resume_thread(i->tx_thread);

    return NO_ERROR;

err2:
    //thread_kill_thread_nowait(i->rx_thread);
    t_kill_thread(i->rx_thread);
err1:
    return err;
}
Пример #2
0
int if_boot_interface(ifnet *i)
{
	int err;

	// create the receive thread
	i->rx_thread = thread_create_kernel_thread("net_rx_thread", &if_rx_thread, i);
	if(i->rx_thread < 0) {
		err = i->rx_thread;
		goto err1;
	}
	thread_set_priority(i->rx_thread, THREAD_MAX_RT_PRIORITY - 2);

	// create the transmit thread
	i->tx_thread = thread_create_kernel_thread("net_tx_thread", &if_tx_thread, i);
	if(i->tx_thread < 0) {
		err = i->tx_thread;
		goto err2;
	}
	thread_set_priority(i->tx_thread, THREAD_MAX_RT_PRIORITY - 2);

	// start the threads
	thread_resume_thread(i->rx_thread);
	thread_resume_thread(i->tx_thread);

	return NO_ERROR;

err2:
	thread_kill_thread_nowait(i->rx_thread);
err1:
	return err;
}
Пример #3
0
static int
hc_init_callback(void *hooks, void *hc_cookie)
{
	usb_hc *hc;

	SHOW_FLOW(1, "cookie %p", hc_cookie);

	hc = (usb_hc *)kmalloc(sizeof(usb_hc));
	if(!hc)
		return ERR_NO_MEMORY;

	memset(hc, 0, sizeof(*hc));

	hc->hooks = hooks;
	hc->hc_cookie = hc_cookie;

	// add it to the list of host controllers
	hc->next = usb->hc_list;
	usb->hc_list = hc;

	// create an enumerator thread
	hc->enumerator_thread = thread_create_kernel_thread("usb bus enumerator", &usb_enumerator_thread, hc);
	thread_set_priority(hc->enumerator_thread, THREAD_MIN_RT_PRIORITY);
	thread_resume_thread(hc->enumerator_thread);

	return NO_ERROR;
}
Пример #4
0
void port_test()
{
	char testdata[5];
	thread_id t;
	int res;
	int32 dummy;
	int32 dummy2;

	strcpy(testdata, "abcd");

	dprintf("porttest: port_create()\n");
	test_p1 = port_create(1,    "test port #1");
	test_p2 = port_create(10,   "test port #2");
	test_p3 = port_create(1024, "test port #3");
	test_p4 = port_create(1024, "test port #4");

	dprintf("porttest: port_find()\n");
	dprintf("'test port #1' has id %d (should be %d)\n", port_find("test port #1"), test_p1);

	dprintf("porttest: port_write() on 1, 2 and 3\n");
	port_write(test_p1, 1, &testdata, sizeof(testdata));
	port_write(test_p2, 666, &testdata, sizeof(testdata));
	port_write(test_p3, 999, &testdata, sizeof(testdata));
	dprintf("porttest: port_count(test_p1) = %d\n", port_count(test_p1));

	dprintf("porttest: port_write() on 1 with timeout of 1 sec (blocks 1 sec)\n");
	port_write_etc(test_p1, 1, &testdata, sizeof(testdata), PORT_FLAG_TIMEOUT, 1000000);
	dprintf("porttest: port_write() on 2 with timeout of 1 sec (wont block)\n");
	res = port_write_etc(test_p2, 777, &testdata, sizeof(testdata), PORT_FLAG_TIMEOUT, 1000000);
	dprintf("porttest: res=%d, %s\n", res, res == 0 ? "ok" : "BAD");

	dprintf("porttest: port_read() on empty port 4 with timeout of 1 sec (blocks 1 sec)\n");
	res = port_read_etc(test_p4, &dummy, &dummy2, sizeof(dummy2), PORT_FLAG_TIMEOUT, 1000000);
	dprintf("porttest: res=%d, %s\n", res, res == ERR_PORT_TIMED_OUT ? "ok" : "BAD");

	dprintf("porttest: spawning thread for port 1\n");
	t = thread_create_kernel_thread("port_test", port_test_thread_func, NULL);
	// resume thread
	thread_resume_thread(t);

	dprintf("porttest: write\n");
	port_write(test_p1, 1, &testdata, sizeof(testdata));

	// now we can write more (no blocking)
	dprintf("porttest: write #2\n");
	port_write(test_p1, 2, &testdata, sizeof(testdata));
	dprintf("porttest: write #3\n");
	port_write(test_p1, 3, &testdata, sizeof(testdata));

	dprintf("porttest: waiting on spawned thread\n");
	thread_wait_on_thread(t, NULL);

	dprintf("porttest: close p1\n");
	port_close(test_p2);
	dprintf("porttest: attempt write p1 after close\n");
	res = port_write(test_p2, 4, &testdata, sizeof(testdata));
	dprintf("porttest: port_write ret %d\n", res);

	dprintf("porttest: testing delete p2\n");
	port_delete(test_p2);

	dprintf("porttest: end test main thread\n");

}