Exemplo n.º 1
0
void FrameExporter::stop() {
    if(!thread) return;
    
    if(dumper_thread_state == FRAME_EXPORTER_STOPPED || dumper_thread_state == FRAME_EXPORTER_EXIT) return;

    SDL_mutexP(mutex);

        dumper_thread_state = FRAME_EXPORTER_EXIT;

        SDL_CondSignal(cond);

    SDL_mutexV(mutex);

    SDL_WaitThread(thread, 0);
    
    thread = 0;
}
Exemplo n.º 2
0
inline static void ijkmp_destroy(IjkMediaPlayer *mp)
{
    if (!mp)
        return;

    ffp_destroy_p(&mp->ffplayer);
    if (mp->msg_thread) {
        SDL_WaitThread(mp->msg_thread, NULL);
        mp->msg_thread = NULL;
    }

    pthread_mutex_destroy(&mp->mutex);

    freep((void**)&mp->data_source);
    memset(mp, 0, sizeof(IjkMediaPlayer));
    freep((void**)&mp);
}
Exemplo n.º 3
0
Arquivo: thread.c Projeto: dns/CLove
static int l_thread_newThread(lua_State* state) {
    thread_Data* data = (thread_Data*) lua_newuserdata(state, sizeof(thread_Data));
    moduleData.state = state;

    const char* name = luaL_optstring(state, 2, NULL);
    data->thread = SDL_CreateThread((SDL_ThreadFunction)callback, name, (void *)NULL);

    if (NULL == data->thread) 
        luaL_error(state, "\n Create thread failed: %s\n", SDL_GetError());
    else 
        SDL_WaitThread(data->thread, &data->res);
    
    lua_rawgeti(state, LUA_REGISTRYINDEX, moduleData.threadDataMT);
    lua_setmetatable(state, -2);

    return 1;
}
AutoPilotWindow::~AutoPilotWindow() {
	//destroy parser thread
	parser_wait=0;
	if(parser_thread)
		SDL_WaitThread(parser_thread,NULL);
	parser_thread=NULL;
    if(tasker)
    	delete tasker;
	if(parser)
		delete parser;
	if(port)
		delete port;
	if(logs)
	   delete logs;
	if(input)
		delete input;
}
Exemplo n.º 5
0
int main(int argc, char **argv) {
    if (argc < 2 || argc > 2) {
        printf("Usage:  %s  image.flif\n",argv[0]);
        return 0;
    }
    d = flif_create_decoder();
    if (!d) return 1;

    SDL_Init(SDL_INIT_VIDEO);
    window = SDL_CreateWindow("FLIF Viewer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 200, 200, 0);
    flif_decoder_set_quality(d, 100);   // this is the default
    flif_decoder_set_scale(d, 1);       // this is the default
#ifdef PROGRESSIVE_DECODING
    flif_decoder_set_callback(d, &(progressive_render));
    flif_decoder_set_first_callback_quality(d, 500);   // do the first callback when at least 5.00% quality has been decoded
    printf("Decoding progressively...\n");
    SDL_Thread *decode_thread = SDL_CreateThread(decodeThread,"Decode_FLIF",argv);
    if (!decode_thread) {
        printf("Error: failed to create decode thread\n");
        return 1;
    }
#else
    printf("Decoding entire image...\n");
    decodeThread(argv);
    progressive_render(10000,-1);
#endif
    SDL_Event e;
    int result = 0;
    while (!quit) {
        draw_image();
        if (animation) {
            SDL_Delay(frame_delay[frame]);
            frame++;
            frame %= flif_decoder_num_images(d);
        } else { SDL_WaitEvent(&e); if (!do_event(e)) break; SDL_Delay(100); }
        while (SDL_PollEvent(&e)) if (!do_event(e)) break;
    }
#ifdef PROGRESSIVE_DECODING
    while(flif_abort_decoder(d)) SDL_Delay(100);
    SDL_WaitThread(decode_thread, &result);
#endif
    flif_destroy_decoder(d);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return result;
}
Exemplo n.º 6
0
/**
 * Thread_Shutdown_
 */
static void Thread_Shutdown_(void) {

	if (thread_pool.num_threads) {
		thread_t *t = thread_pool.threads;
		uint16_t i = 0;

		for (i = 0; i < thread_pool.num_threads; i++, t++) {
			Thread_Wait(t);
			SDL_CondSignal(t->cond);
			SDL_WaitThread(t->thread, NULL);
			SDL_DestroyCond(t->cond);
			SDL_DestroyMutex(t->mutex);
		}

		Mem_Free(thread_pool.threads);
	}
}
Exemplo n.º 7
0
int AVIWrapper::play(bool click_flag)
{
    int ret = 0;
    time_start = 0;
    status = AVI_PLAYING;
    if (v_stream)
        thread_id = SDL_CreateThread(::playVideo, this);

    if (a_stream)
        Mix_HookMusic(::audioCallback, this);

    bool done_flag = false;
    while (!(done_flag & click_flag) && status == AVI_PLAYING) {
        SDL_Event event;

        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_KEYDOWN:
                if (((SDL_KeyboardEvent*) &event)->keysym.sym == SDLK_RETURN
                    || ((SDL_KeyboardEvent*) &event)->keysym.sym == SDLK_KP_ENTER
                    || ((SDL_KeyboardEvent*) &event)->keysym.sym == SDLK_SPACE
                    || ((SDL_KeyboardEvent*) &event)->keysym.sym == SDLK_ESCAPE)
                    done_flag = true;

                break;
            case SDL_QUIT:
                ret = 1;
            case SDL_MOUSEBUTTONDOWN:
                done_flag = true;
                break;
            default:
                break;
            }
        }
        SDL_Delay(10);
    }

    status = AVI_STOP;
    if (v_stream)
        SDL_WaitThread(thread_id, NULL);

    if (a_stream)
        Mix_HookMusic(NULL, NULL);

    return ret;
}
Exemplo n.º 8
0
int main(int argc, char **argv)
{
	SDL_Thread *threads[NUM_THREADS];
	uintptr_t i;
	int init_sem;

	if(argc < 2) {
		fprintf(stderr,"Usage: %s init_value\n", argv[0]);
		return(1);
	}

	/* Load the SDL library */
	if ( SDL_Init(0) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		return(1);
	}
	signal(SIGTERM, killed);
	signal(SIGINT, killed);
	
	init_sem = atoi(argv[1]);
	sem = SDL_CreateSemaphore(init_sem);
	
	printf("Running %d threads, semaphore value = %d\n", NUM_THREADS, init_sem);
#if 0 
	/* Create all the threads */
	for( i = 0; i < NUM_THREADS; ++i ) {
		threads[i] = SDL_CreateThread(ThreadFunc, (void*)i);
	}

	/* Wait 10 seconds */
	SDL_Delay(10 * 1000);

	/* Wait for all threads to finish */
	printf("Waiting for threads to finish\n");
	alive = 0;
	for( i = 0; i < NUM_THREADS; ++i ) {
		SDL_WaitThread(threads[i], NULL);
	}

	printf("Finished waiting for threads\n");
#endif
	SDL_DestroySemaphore(sem);
	SDL_Quit();
	return(0);
}
Exemplo n.º 9
0
int main(){

	mainData = malloc(sizeof(struct main_ProgramData));
		//initialze the webcam
	mainData->LocalWebcamData = VIDEO_webcamload("/dev/video0");
	//So we can know to print debug shit
	mainData->verbose = 1;
	//Right now we don't want the render thread to do anything until we SemPost this
	mainData->UI_renderhold = SDL_CreateSemaphore(0);
	//This is the thread that sets up the video surface and handles events
	mainData->UI_initandeventthread = SDL_CreateThread(UI_Initialize, NULL);
	//Thread where the rendering happens
	mainData->UI_renderthread = SDL_CreateThread( UI_thread, NULL);
	
	SDL_WaitThread(mainData->UI_initandeventthread, NULL);
	return 0;

}
Exemplo n.º 10
0
void tilt_free(void)
{
    if (mutex)
    {
        /* Get/set the status of the tilt sensor thread. */

        SDL_mutexP(mutex);
        state.status = 0;
        SDL_mutexV(mutex);

        /* Wait for the thread to terminate and destroy the mutex. */

        SDL_WaitThread(thread, NULL);
        SDL_DestroyMutex(mutex);
        mutex  = NULL;
        thread = NULL;
    }
}
Exemplo n.º 11
0
	Thread::~Thread() {
		SDL_Thread *th = NULL;
		{
			AutoLocker locker(&lock);
			th = (SDL_Thread *)threadInfo;
			if(!th)
				return;
		}
		
		// we have to ensure thread handle is destroyed.
		if(SDL_ThreadID() == threadId) {
			// thread is deleting itself.
			// SDL_WaitThread would cause deadlock.
			cleanuper->Add(th);
		}else{
			SDL_WaitThread(th, NULL);
		}
	}
Exemplo n.º 12
0
void Graphics::DeinitGraphics()
{
	if (Graphics::Handle)
		Graphics::ThreadData.flag = 0;
		SDL_WaitThread(Graphics::ThreadData.thread, NULL);
		for (int i = 0; Graphics::dlObjectList[i]; i++ )
		{
			free(Graphics::dlObjectList[i]);
			Graphics::dlObjectList[i] = NULL;
		}
		for (int i = 0; Graphics::dlSpriteList[i]; i++ )
		{
			free(Graphics::dlSpriteList[i]);
			Graphics::dlSpriteList[i] = NULL;
		}
		delete Graphics::Handle;
		SDL_Quit();
}
Exemplo n.º 13
0
WhoIsOnline::~WhoIsOnline()
{
    config.removeListeners(this);

    if (mThread && SDL_GetThreadID(mThread))
        SDL_WaitThread(mThread, nullptr);

    free(mMemoryBuffer);
    mMemoryBuffer = nullptr;

    // Remove possibly leftover temporary download
    delete []mCurlError;

    FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
        delete *itd;
    mOnlinePlayers.clear();
    mOnlineNicks.clear();
}
Exemplo n.º 14
0
static EEL_xno n2s_destruct(EEL_object *eo)
{
	EB_socket *ebs = o2EB_socket(eo);
	if(!ebs->rs)
		return 0;	/* Detached! We're done here. */
	if(ebs->rs->sender)
	{
		ebs->rs->closed = 1;
		SDL_WaitThread(ebs->rs->sender, NULL);
		sfifo_close(&ebs->rs->fifo);
	}
	NET2_TCPClose(ebs->rs->n2socket);
	if(ebs->rs->n2socket >= 0)
		if(eb_sockets)
			eb_sockets[ebs->rs->n2socket] = NULL;
	free(ebs->rs);
	return 0;
}
Exemplo n.º 15
0
void NetworkManager::cleanUp()
{
    network_running = false;

    SDL_SemPost(semaphore);
    int st;
    SDL_WaitThread(resolverThread, &st);

    SDL_DestroySemaphore(semaphore);
    semaphore = 0;
    resolverThread = 0;

    rqueue.clear();

#ifdef _WIN32
    WSACleanup();
#endif
}
Exemplo n.º 16
0
	Thread::~Thread() {
		SDL_Thread *th = NULL;
		{
			std::lock_guard<std::recursive_mutex> _lock{this->lock};
			th = (SDL_Thread *)threadInfo;
			if (!th)
				return;
		}

		// we have to ensure thread handle is destroyed.
		if (SDL_ThreadID() == threadId) {
			// thread is deleting itself.
			// SDL_WaitThread would cause deadlock.
			cleanuper->Add(th);
		} else {
			SDL_WaitThread(th, NULL);
		}
	}
Exemplo n.º 17
0
int
main(int argc, char *argv[])
{
    SDL_Thread *thread;

	/* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    /* Load the SDL library */
    if (SDL_Init(0) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
        return (1);
    }

    tls = SDL_TLSCreate();
    SDL_assert(tls);
    SDL_TLSSet(tls, "main thread", NULL);
    SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));

    alive = 1;
    thread = SDL_CreateThread(ThreadFunc, "One", "#1");
    if (thread == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
        quit(1);
    }
    SDL_Delay(5 * 1000);
    SDL_Log("Waiting for thread #1\n");
    alive = 0;
    SDL_WaitThread(thread, NULL);

    SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));

    alive = 1;
    signal(SIGTERM, killed);
    thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
    if (thread == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
        quit(1);
    }
    raise(SIGTERM);

    SDL_Quit();                 /* Never reached */
    return (0);                 /* Never reached */
}
Exemplo n.º 18
0
	~WorkQueue()
	{
		{
			LockMutex m(queueMutex);

			queueAlive = false;
			SDL_CondBroadcast(queueCond);
		}

		for (int i = 0; i < 8; ++i)
		{
			int status;
			if (threads[i])
				SDL_WaitThread(threads[i], &status);
		}

		SDL_DestroyMutex(queueMutex);
		SDL_DestroyCond(queueCond);
	}
Exemplo n.º 19
0
void Async_Free()
{
	int i;
	// Stop all threads
	G_is_running = 0;
	// Notify all threads
	SDL_CondBroadcast(G_queue_cond);
	// Wait for threads
	for (i = 0; i < G_thread_count; i++)
	{
		if (G_threads[i])
		{
			SDL_WaitThread(G_threads[i], NULL);
		}
	}
	free(G_threads);
	SDL_DestroyCond(G_queue_cond);
	SDL_DestroyMutex(G_queue_guard);
}
Exemplo n.º 20
0
Sound::~Sound()
{
    //SDL_KillThread( loaderThread );
    SDL_WaitThread( loaderThread, NULL );
    if(currentMusic)
        Mix_FreeMusic(currentMusic);

    if( soundPtr == this )
    {
        soundPtr = 0;
    }
    for (chunks_t::iterator i = waves.begin(); i != waves.end(); i++) {
        Mix_FreeChunk( i->second );
    }
    if ( audioOpen ) {
        Mix_CloseAudio();
        audioOpen = false;
    }
}
Exemplo n.º 21
0
int destroyDisplay( SAC_ND_PARAM_in_nodesc( disp_nt, Display))
{
  SDL_Event event;

  if (SDLsac_isasync) {
    /* stop the timer */
    if (SDLsac_timer != NULL) {
      SDL_RemoveTimer( SDLsac_timer);
    }

    /* tell the event handler to quit */
    event.type = SDL_USEREVENT_QUIT;
    event.user.code = 0;
    event.user.data1 = NULL;
    event.user.data2 = NULL;
    SDL_PushEvent(&event);

    /* wait for event handler to finish */
    if (SDLsac_eventhandler != NULL) {
      SDL_WaitThread( SDLsac_eventhandler, NULL);
    }

#ifdef UPDATE_VIA_SEMAPHORE
    /* kill the updater */
    SDL_KillThread( SDLsac_updater);

    /* destroy the semaphore */
    SDL_DestroySemaphore( SDLsac_updatesem);
#endif
  }

  /* destroy the semaphore */
  SDL_DestroySemaphore( SDLsac_selectsem);

  /* finally, we can release this */
  if (SDLsac_mutex != NULL) {
    SDL_DestroyMutex( SDLsac_mutex);
  }

  SDL_Quit();
  return(0);
}
Exemplo n.º 22
0
void Network::disconnect()
{
    mState = IDLE;

    if (mWorkerThread && SDL_GetThreadID(mWorkerThread))
    {
        SDL_WaitThread(mWorkerThread, nullptr);
        mWorkerThread = nullptr;
    }

    if (mSocket)
    {
        // need call SDLNet_TCP_DelSocket?
        SDLNet_TCP_Close(mSocket);
        mSocket = nullptr;
        int sleep = config.getIntValue("networksleep");
        if (sleep > 0)
            SDL_Delay(sleep);
    }
}
Exemplo n.º 23
0
void NetworkConnectionMenu::ThreadRefreshList()
{
  SDL_SemWait(net_info.lock);

  if (net_info.thread_refresh != NULL) {
    // Check if the thread finished
    if (net_info.finished) {
      int status;
      SDL_WaitThread(net_info.thread_refresh, &status);
    } else {
      MSG_DEBUG("network.refresh_games_list", "A thread is already running");
      SDL_SemPost(net_info.lock);
      return;
    }
  }
  SDL_SemPost(net_info.lock);

  net_info.finished = false;
  net_info.thread_refresh = SDL_CreateThread(RefreshNetInfo, NULL);
}
Exemplo n.º 24
0
void audio_device::sound_stop()
{
    if(playing)
    {
        playing = false;

        SDL_mutexP(audio_mutex);
        done = true;
        SDL_PauseAudio(true);

        mp3->stop();
        audio_wd_num = audio_rd_num = audio_wd = audio_rd = 0;
        audio_total_done = audio_total_decoded = 0;

        SDL_mutexV(audio_mutex);


        if(audiothread) SDL_WaitThread(audiothread, NULL);
    }
}
Exemplo n.º 25
0
/** Check to see if any game instances are done and remove them 
 \todo support more than one instance 
 render thread */
bool sdl_master::check_users(bool last)
{
	if (clients[0] != 0)
	{
		if (clients[0]->done)
		{
			printf("Stop sdl_user\n");
			int bla;
			delete clients[0];
			clients[0] = 0;
			SDL_WaitThread(game_client[0], &bla);
			SDL_FreeSurface(cdisplay[0]);
			cdisplay[0] = 0;
			clients[0] = 0;
			game_client[0] = (SDL_Thread*)0;
			last = true;
		}
	}
	return last;
}
void TCP_NetServer::haltRecvThreads()
{
	SDL_LockMutex(remoteMutex);
	for (int i = 0; i < NETSP_PLAYERS_COUNT; ++i) {
		if (remote[i].socket == NULL) {
			continue;
		}
		SDLNet_TCP_Close(remote[i].socket);
		remote[i].socket = NULL;
		remote[i].playerId = 0;
	}
	SDL_UnlockMutex(remoteMutex);

	for (int i = 0; i < NETSP_PLAYERS_COUNT; ++i) {
		if (remote[i].recvThread != NULL) {
			SDL_WaitThread(remote[i].recvThread, NULL);
			remote[i].recvThread = NULL;
		}
	}
}
Exemplo n.º 27
0
void Update::StartUpdateCheck()
{
  if (m_status == CheckingForUpdate) {
    return;
  }
  if (m_thread) {
    int status;
    SDL_WaitThread(m_thread, &status);
    m_thread = 0;
  }

  m_status = CheckingForUpdate;
  m_new_date_version.clear();
  m_new_display_version.clear();

  m_thread = SDL_CreateThread(update_thread, this);
  if (!m_thread) {
    m_status = UpdateCheckFailed;
  }
}
Exemplo n.º 28
0
static void RunThreads (void)
{
	SDL_Thread *threads[MAX_THREADS];
	int i;

	if (threadstate.numthreads == 1) {
		ThreadWork(NULL);
		return;
	}

	ThreadInit();

	for (i = 0; i < threadstate.numthreads; i++)
		threads[i] = SDL_CreateThread(ThreadWork, NULL);

	for (i = 0; i < threadstate.numthreads; i++)
		SDL_WaitThread(threads[i], NULL);

	ThreadRelease();
}
Exemplo n.º 29
0
		void SDLUtilityTool::DestroyInputHandler()
		{
			int returnValue = 0;

			// wait on the thread
			g_assert(m_inputHandler.IsActive());
			m_inputHandler.Deactivate();
			g_assert(m_inputThread != nullptr);
			SDL_WaitThread(m_inputThread, &returnValue);
			LogSDLError();
			

			// cleanup the game controller
			g_assert(m_inputController != nullptr);
			SDL_GameControllerClose(m_inputController);
			LogSDLError();
			m_inputController = nullptr;
			m_inputHandler.m_gameController = nullptr;
			
		}
Exemplo n.º 30
0
void sosg_image_destroy(sosg_image_p images)
{
    int i;
    if (images) {
        images->running = 0;
        if (images->load_thread) SDL_WaitThread(images->load_thread, NULL);
    
        if (images->images) {
            for (i = 0; i < images->num_images; i++) {
                if (images->images[i]) {
                    if (images->images[i]->buffer) SDL_FreeSurface(images->images[i]->buffer);
                    if (images->images[i]->path) free(images->images[i]->path);
                    free(images->images[i]);
                }
            }
            free(images->images);
        }
        free(images);
    }
}