Пример #1
0
int el_loader_init(void)
{
  PRINTF("entrylist_load_init...\n");

  spinlock_init(&loader_mutex);
  memset(&loader, 0, sizeof(loader));
  loader_status = LOADER_INIT;
  loader_thd = 0;
  PRINTF("entrylist_load_init : create semaphore.\n");
  loader_sem = sem_create(1);
  PRINTF("entrylist_load_init : semaphore [%p].\n",loader_sem);
  if (!loader_sem) {
    printf("entrylist_load_init : can not create semaphore.\n");
    return -1;
  }
  PRINTF("entrylist_load_init : first wait semaphore.\n");
  sem_wait(loader_sem);

  PRINTF("entrylist_load_init : create thread.\n");
  loader_thd = thd_create(THD_DEFAULTS, loader_thread, loader_sem);
  if (!loader_thd) {
    printf("entrylist_load_init : thread failed.\n");
    sem_signal(loader_sem);
    sem_destroy(loader_sem);
    loader_sem = 0;
    printf("entrylist_load_init : can not create loader thread.\n");
    return -1;
  }
  PRINTF("entrylist_load_init : thread created, rename it.\n");
  thd_set_label((kthread_t *)loader_thd, "Loader-thd");
  PRINTF("entrylist_load_init : complete (thd=%p).\n", loader_thd);
  return 0;
}
Пример #2
0
int Mix_OpenAudio(int frequency, uint16 format, int channels, int chunksize)
{
    /* register all the drivers */
    MikMod_RegisterAllDrivers();

    /* register all the module loaders */
    MikMod_RegisterAllLoaders();

    /* initialize the library */
    md_mode |= DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX;
    
    if (MikMod_Init("")) {
        printf("Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno));
		return 1;
    }
    
    /* One for music and one for sfx */
    MikMod_SetNumVoices(-1,8);
    MikMod_EnableOutput();
    
    loaded = 1;
	gfrequency = frequency;
	gchannels = channels;
	
	thd_create(0, snd_thread, NULL);
	return 0;
}
Пример #3
0
static void
no_lazy_lock(void)
{
	thd_t thd;

	thd_create(&thd, thd_start, NULL);
	thd_join(thd, NULL);
}
Пример #4
0
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
{
	thread->handle = thd_create(SDL_RunThread,args);
	if (thread->handle == NULL) {
		SDL_SetError("Not enough resources to create thread");
		return(-1);
	}
	return(0);
}
Пример #5
0
TEST_END

TEST_BEGIN(test_subthread)
{
	thd_t thd;

	thd_create(&thd, thd_start, NULL);
	thd_join(thd, NULL);
}
Пример #6
0
TEST_END

TEST_BEGIN(test_tsd_sub_thread)
{
    thd_t thd;

    data_cleanup_executed = false;
    thd_create(&thd, thd_start, (void *)THREAD_DATA);
    thd_join(thd, NULL);
    assert_true(data_cleanup_executed,
                "Cleanup function should have executed");
}
Пример #7
0
TEST_END

TEST_BEGIN(test_tsd_sub_thread) {
	thd_t thd;

	data_cleanup_count = 0;
	thd_create(&thd, thd_start, (void *)MALLOC_TSD_TEST_DATA_INIT);
	thd_join(thd, NULL);
	/*
	 * We reincarnate twice in the data cleanup, so it should execute at
	 * least 3 times.
	 */
	assert_x_ge(data_cleanup_count, 3,
	    "Cleanup function should have executed multiple times.");
}
Пример #8
0
int pthread_create(pthread_t *thread, const pthread_attr_t  *attr,
	void *(*start_routine)( void * ), void *arg)
{
	kthread_t * nt;

	assert( thread );
	assert( start_routine );

	nt = thd_create( (void (*)(void *))start_routine, arg );
	if (nt) {
		*thread = nt;
		return 0;
	} else {
		return EAGAIN;
	}
}
Пример #9
0
int sndoggvorbis_init() {
	if (thd) {
		printf("sndserver: already initialized!\n");
		return -1;
	}

	printf("sndserver: initializing sndoggvorbis 0.7 [OggVorbis 1.0 based]\n");
	thd = thd_create(sndserver_thread, NULL);
	if (thd != NULL) {
		/* Wait until the oggvorbis decoder thread is ready */
		sndoggvorbis_wait_start();
		printf("sndserver: successfully created thread\n");
		return 0;
	} else {
		printf("sndserver: error creating thread\n");
		return -1;
	}
}
Пример #10
0
/* Main rendering of the song menu */
void song_menu_render() {
    if(mut == NULL) {
        mut = mutex_create();
        hookmut = mutex_create();
    }

    if(!filtinitted) {
        snd_stream_filter_add(0, snd_hook, NULL);
        filtinitted = 1;
    }

    /* Draw a background box */
    draw_poly_box(30.0f, 80.0f, 610.0f, 440.0f - 96.0f, 90.0f,
                  0.2f, 0.8f, 0.5f, 0.0f, 0.2f, 0.8f, 0.8f, 0.2f);

    /* If we don't have a file listing, get it now */
    if(num_entries == 0 && !load_queued) {
        load_queued = 1;
        thd_create(1, load_song_list, NULL);
    }

    /* if (load_queued)
        draw_poly_strf(32.0f, 82.0f, 100.0f, 1.0f, 1.0f, 1.0f, 1.0f,
            "Scanning Directory..."); */

    /* Draw the song listing */
    mutex_lock(mut);
    draw_listing();
    mutex_unlock(mut);

    /* Adjust the throbber */
    throb += dthrob;

    if(throb < 0.2f || throb > 0.8f) {
        dthrob = -dthrob;
        throb += dthrob;
    }

    /* Check maple inputs */
    check_inputs();

    framecnt++;
}
Пример #11
0
/* initialize the console I/O stuffs */
int conio_init(int ttymode, int inputmode) {
	conio_ttymode = ttymode;
	conio_inputmode = inputmode;

	switch (conio_ttymode) {
		case CONIO_TTY_PVR:
#ifdef GFX
			conio_draw_init();
#endif
			break;
		case CONIO_TTY_STDIO:
			break;
		case CONIO_TTY_SERIAL:
			conio_serial_fd = 1;
			break;
		default:
			assert_msg( false, "Unknown CONIO TTY mode" );
			conio_ttymode = CONIO_TTY_PVR;
			break;
	}
	assert_msg( conio_inputmode == CONIO_INPUT_LINE, "Non-Line input modes not supported yet" );

	conio_input_init();
	if (conio_ttymode == CONIO_TTY_PVR) {
		conio_clear();
		conio_gotoxy(0, 0);
	}

	ft_mutex = sem_create(1);

	/* create the conio thread */
	conio_exit = 0;
	if (thd_create(conio_thread, 0) < 0)
		return -1;

	/* Wait for it to actually start */
	while (!conio_entered)
		thd_pass();
	
	return 0;
}
Пример #12
0
void httpd(void) {
	int listenfd;
	struct sockaddr_in saddr;
	fd_set readset;
	fd_set writeset;
	int i, maxfdp1;
	http_state_t *hs;

	listenfd = socket(AF_INET, SOCK_STREAM, 0);
	if (listenfd < 0) {
		printf("httpd: socket create failed\n");
		return;
	}

	memset(&saddr, 0, sizeof(saddr));
	saddr.sin_family = AF_INET;
	saddr.sin_addr.s_addr = htonl(INADDR_ANY);
	saddr.sin_port = htons(80);

	if (bind(listenfd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
		printf("httpd: bind failed\n");
		close(listenfd);
		return;
	}

	if (listen(listenfd, 10) < 0) {
		printf("httpd: listen failed\n");
		close(listenfd);
		return;
	}

	st_init();
	printf("httpd: listening for connections on socket %d\n", listenfd);

	for ( ; ; ) {
		maxfdp1 = listenfd + 1;

		FD_ZERO(&readset);
		FD_ZERO(&writeset);
		FD_SET(listenfd, &readset);
		// maxfdp1 = st_add_fds(&readset, maxfdp1);
		// st_add_fds(&writeset);

		i = select(maxfdp1, &readset, &writeset, 0, 0);

		if (i == 0)
			continue;

		// Check for new incoming connections
		if (FD_ISSET(listenfd, &readset)) {
			int tmp = 1;

			hs = st_create();
			hs->client_size = sizeof(hs->client);
			hs->socket = accept(listenfd,
				(struct sockaddr *)&hs->client,
				&hs->client_size);
			printf("httpd: connect from %08lx, port %d, socket %d\n",
				hs->client.sin_addr.s_addr, hs->client.sin_port, hs->socket);
			if (hs->socket < 0) {
				st_destroy(hs);
			} else {
				hs->thd = thd_create(client_thread, hs);
				// hs->thd = sys_thread_new(client_thread, hs, 0);
			}
			/* else if (ioctl(hs->socket, FIONBIO, &tmp) < 0) {
				printf("httpd: failed to set non-blocking\n");
				st_destroy(hs);
			} */
		}

#if 0
		// Process data from connected clients
		st_foreach(hs) {
			if (FD_ISSET(hs->socket, &readset)) {
				if (handle_read(hs) < 0) {
					printf("httpd: disconnected socket %d\n", hs->socket);
					close(hs->socket);
					st_destroy(hs);
					break;
				}
			}
			/* if (FD_ISSET(hs->socket, &writeset)) {
			} */
		}
#endif
	}
}
Пример #13
0
static void start_audio() {
	aud_set = 1;
	//snd_stream_prefill(shnd);
	snd_stream_start(shnd, sample_rate, chans-1);
	loop_thread = thd_create(0, play_loop, NULL);
}
Пример #14
0
void ser_console_init() {
	thd_create(real_start, NULL);
}