TaskManager::TaskManager() { quitSignal = false; mutex = SDL_CreateMutex(); taskFinished = SDL_CreateCond(); queueThreadWakeup = SDL_CreateCond(); struct QueuedTaskHandler : Action { TaskManager* manager; QueuedTaskHandler(TaskManager* m) : manager(m) {} int handle() { ScopedLock lock(manager->mutex); while(true) { if(manager->queuedTasks.size() > 0) { Action* act = manager->queuedTasks.front(); manager->queuedTasks.pop_front(); SDL_mutexV(manager->mutex); act->handle(); delete act; SDL_mutexP(manager->mutex); continue; } if(manager->quitSignal) { return 0; } SDL_CondWait(manager->queueThreadWakeup, manager->mutex); } } }; queueThread = threadPool->start(new QueuedTaskHandler(this), "queued task handler"); }
void SDL_ANDROID_MultiThreadedVideoLoopInit() { videoThread.mutex = SDL_CreateMutex(); videoThread.cond = SDL_CreateCond(); videoThread.cond2 = SDL_CreateCond(); videoThread.execute = 0; }
/** * Initialize and start up the worker threads. */ void socket_thread_start(void) { if (input_buffer_cond == NULL) { input_buffer_cond = SDL_CreateCond(); input_buffer_mutex = SDL_CreateMutex(); output_buffer_cond = SDL_CreateCond(); output_buffer_mutex = SDL_CreateMutex(); socket_mutex = SDL_CreateMutex(); } abort_thread = 0; input_thread = SDL_CreateThread(reader_thread_loop, NULL); if (input_thread == NULL) { LOG(ERROR, "Unable to start socket thread: %s", SDL_GetError()); exit(1); } output_thread = SDL_CreateThread(writer_thread_loop, NULL); if (output_thread == NULL) { LOG(ERROR, "Unable to start socket thread: %s", SDL_GetError()); exit(1); } }
void ThreadPool::init(int _numThreads) { //setup mutex quequeMutex = SDL_CreateMutex(); workerMutex = SDL_CreateMutex(); condHaveWork = SDL_CreateCond(); mutexBarrier = SDL_CreateMutex(); condBarrier = SDL_CreateCond(); //setup number of threads numThreads = _numThreads; //initialize all threads for(int i = 0; i < numThreads; i++) { char threadName[128]; sprintf(threadName,"Thread %d",i); //Create thread threads[i] = SDL_CreateThread(worker,threadName,&poolThread); if (NULL == threads[i]) { printf ("Falha ao Criar thread \n"); } } }
static bool sim_kernel_init(void) { sim_irq_mtx = SDL_CreateMutex(); if (sim_irq_mtx == NULL) { panicf("Cannot create sim_handler_mtx\n"); return false; } sim_thread_cond = SDL_CreateCond(); if (sim_thread_cond == NULL) { panicf("Cannot create sim_thread_cond\n"); return false; } #ifndef HAVE_SDL_THREADS wfi_cond = SDL_CreateCond(); if (wfi_cond == NULL) { panicf("Cannot create wfi\n"); return false; } wfi_mutex = SDL_CreateMutex(); if (wfi_mutex == NULL) { panicf("Cannot create wfi mutex\n"); return false; } #endif return true; }
/* =============== GLimp_SpawnRenderThread =============== */ qboolean GLimp_SpawnRenderThread( void ( *function )( void ) ) { static qboolean warned = qfalse; if ( !warned ) { Com_Printf( "WARNING: You enable r_smp at your own risk!\n" ); warned = qtrue; } #if !defined( MACOS_X ) && !defined( WIN32 ) && !defined ( SDL_VIDEO_DRIVER_X11 ) && !SDL_VERSION_ATLEAST( 2, 0, 0 ) return qfalse; /* better safe than sorry for now. */ #endif if ( renderThread != NULL ) /* hopefully just a zombie at this point... */ { Com_Printf( "Already a render thread? Trying to clean it up...\n" ); GLimp_ShutdownRenderThread(); } smpMutex = SDL_CreateMutex(); if ( smpMutex == NULL ) { Com_Printf( "smpMutex creation failed: %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return qfalse; } renderCommandsEvent = SDL_CreateCond(); if ( renderCommandsEvent == NULL ) { Com_Printf( "renderCommandsEvent creation failed: %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return qfalse; } renderCompletedEvent = SDL_CreateCond(); if ( renderCompletedEvent == NULL ) { Com_Printf( "renderCompletedEvent creation failed: %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return qfalse; } renderThreadFunction = function; renderThread = SDL_CreateThread( GLimp_RenderThreadWrapper, "render thread", NULL ); if ( renderThread == NULL ) { ri.Printf( PRINT_ALL, "SDL_CreateThread() returned %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return qfalse; } return qtrue; }
/* =============== GLimp_SpawnRenderThread =============== */ qboolean GLimp_SpawnRenderThread(void (*function)(void)) { if (renderThread == (void *)0xdead) { Com_Printf("SMP: Not safe restarting thread.\n"); renderThread = NULL; return qfalse; } if (renderThread != NULL) { Com_Printf("SMP: Render thread still Running.\n"); return qtrue; } smpData = (void *)0xdead; smpMutex = SDL_CreateMutex(); if (!smpMutex) { Com_Printf("SMP: Mutex creation failed: %s\n", SDL_GetError()); GLimp_ShutdownRenderThread(); return qfalse; } renderCommandsEvent = SDL_CreateCond(); if (renderCommandsEvent == NULL) { Com_Printf("SMP: CommandEvent creation failed: %s\n", SDL_GetError()); GLimp_ShutdownRenderThread(); return qfalse; } renderCompletedEvent = SDL_CreateCond(); if (renderCompletedEvent == NULL) { Com_Printf("SMP: CompletedEvent creation failed: %s\n", SDL_GetError()); GLimp_ShutdownRenderThread(); return qfalse; } glimpRenderThread = function; renderThread = SDL_CreateThread(GLimp_RenderThreadWrapper, GLthreadname); if (renderThread == NULL) { ri.Printf(PRINT_ALL, "SDL: CreateThread() returned %s", SDL_GetError()); GLimp_ShutdownRenderThread(); return qfalse; } SDL_LockMutex(smpMutex); while ( smpData ) SDL_CondWait(renderCompletedEvent, smpMutex); SDL_UnlockMutex(smpMutex); return qtrue; }
sdl_amedia_status_t SDL_AMediaCodec_FakeFifo_init(SDL_AMediaCodec_FakeFifo *fifo) { memset(fifo, 0, sizeof(SDL_AMediaCodec_FakeFifo)); fifo->mutex = SDL_CreateMutex(); fifo->wakeup_enqueue_cond = SDL_CreateCond(); fifo->wakeup_dequeue_cond = SDL_CreateCond(); return SDL_AMEDIA_OK; }
void ThreadPool::prepareNewThread() { ThreadPoolItem* t = new ThreadPoolItem(); t->pool = this; t->finishedSignal = SDL_CreateCond(); t->readyForNewWork = SDL_CreateCond(); t->finished = false; t->working = false; availableThreads.insert(t); t->thread = SDL_CreateThread(threadWrapper, t); }
/* =============== GLimp_SpawnRenderThread =============== */ bool GLimp_SpawnRenderThread( void ( *function )() ) { static bool warned = false; if ( !warned ) { Com_Printf( "WARNING: You enable r_smp at your own risk!\n" ); warned = true; } if ( renderThread != nullptr ) /* hopefully just a zombie at this point... */ { Com_Printf( "Already a render thread? Trying to clean it up...\n" ); GLimp_ShutdownRenderThread(); } smpMutex = SDL_CreateMutex(); if ( smpMutex == nullptr ) { Com_Printf( "smpMutex creation failed: %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return false; } renderCommandsEvent = SDL_CreateCond(); if ( renderCommandsEvent == nullptr ) { Com_Printf( "renderCommandsEvent creation failed: %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return false; } renderCompletedEvent = SDL_CreateCond(); if ( renderCompletedEvent == nullptr ) { Com_Printf( "renderCompletedEvent creation failed: %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return false; } renderThreadFunction = function; renderThread = SDL_CreateThread( GLimp_RenderThreadWrapper, "render thread", nullptr ); if ( renderThread == nullptr ) { ri.Printf( PRINT_ALL, "SDL_CreateThread() returned %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return false; } return true; }
ThreadPool::ThreadPool(unsigned int size) { nextAction = NULL; nextIsHeadless = false; nextData = NULL; quitting = false; mutex = SDL_CreateMutex(); awakeThread = SDL_CreateCond(); threadStartedWork = SDL_CreateCond(); threadStatusChanged = SDL_CreateCond(); startMutex = SDL_CreateMutex(); notes << "ThreadPool: creating " << size << " threads ..." << endl; while(availableThreads.size() < size) prepareNewThread(); }
/* ================== Sys_InitThreads ================== */ void Sys_InitThreads() { // critical sections for (int i = 0; i < MAX_CRITICAL_SECTIONS; i++) { mutex[i] = SDL_CreateMutex(); if (!mutex[i]) { Sys_Printf("ERROR: SDL_CreateMutex failed\n"); return; } } // events for (int i = 0; i < MAX_TRIGGER_EVENTS; i++) { cond[i] = SDL_CreateCond(); if (!cond[i]) { Sys_Printf("ERROR: SDL_CreateCond failed\n"); return; } signaled[i] = false; waiting[i] = false; } // threads for (int i = 0; i < MAX_THREADS; i++) thread[i] = NULL; thread_count = 0; }
int midi_engine_start(void) { if (_connected) return 1; midi_mutex = SDL_CreateMutex(); midi_record_mutex = SDL_CreateMutex(); midi_play_mutex = SDL_CreateMutex(); midi_port_mutex = SDL_CreateMutex(); midi_play_cond = SDL_CreateCond(); if (!(midi_mutex && midi_record_mutex && midi_play_mutex && midi_port_mutex && midi_play_cond)) { if (midi_mutex) SDL_DestroyMutex(midi_mutex); if (midi_record_mutex) SDL_DestroyMutex(midi_record_mutex); if (midi_play_mutex) SDL_DestroyMutex(midi_play_mutex); if (midi_port_mutex) SDL_DestroyMutex(midi_port_mutex); if (midi_play_cond) SDL_DestroyCond(midi_play_cond); midi_mutex = midi_record_mutex = midi_play_mutex = midi_port_mutex = NULL; midi_play_cond = NULL; return 0; } _midi_engine_connect(); _connected = 1; return 1; }
void pcm_init() { int i; SDL_AudioSpec as; if (!sound) return; as.freq = samplerate; as.format = AUDIO_S16; as.channels = 1 + stereo; as.samples = 1024; as.callback = audio_callback; as.userdata = 0; if (SDL_OpenAudio(&as, 0) == -1) return; pcm.hz = as.freq; pcm.stereo = as.channels - 1; pcm.len = as.size >> 1; pcm.buf = malloc(pcm.len); pcm.pos = 0; memset(pcm.buf, 0, pcm.len); sound_mutex = SDL_CreateMutex(); sound_cv = SDL_CreateCond(); SDL_PauseAudio(0); }
void OPL_Delay(uint64_t us) { delay_data_t delay_data; if (driver == NULL) { return; } // Create a callback that will signal this thread after the // specified time. delay_data.finished = 0; delay_data.mutex = SDL_CreateMutex(); delay_data.cond = SDL_CreateCond(); OPL_SetCallback(us, DelayCallback, &delay_data); // Wait until the callback is invoked. SDL_LockMutex(delay_data.mutex); while (!delay_data.finished) { SDL_CondWait(delay_data.cond, delay_data.mutex); } SDL_UnlockMutex(delay_data.mutex); // Clean up. SDL_DestroyMutex(delay_data.mutex); SDL_DestroyCond(delay_data.cond); }
int prepareAsync_l(VideoState **ps) { VideoState *is = *ps; if (is != 0) { is->pictq_mutex = SDL_CreateMutex(); is->pictq_cond = SDL_CreateCond(); //is->event_tid = malloc(sizeof(*(is->event_tid))); //pthread_create(is->event_tid, NULL, (void *) &event_thread, is); // uncomment for video schedule_refresh(is, 40); is->av_sync_type = DEFAULT_AV_SYNC_TYPE; is->parse_tid = malloc(sizeof(*(is->parse_tid))); if(!is->parse_tid) { av_free(is); return UNKNOWN_ERROR; } pthread_create(is->parse_tid, NULL, (void *) &decode_thread, is); av_init_packet(&is->flush_pkt); is->flush_pkt.data = (unsigned char *)"FLUSH"; return NO_ERROR; } return INVALID_OPERATION; }
THMoviePicture::THMoviePicture(): m_pBuffer(nullptr), m_pixelFormat(AV_PIX_FMT_RGB24) { m_pMutex = SDL_CreateMutex(); m_pCond = SDL_CreateCond(); }
//------------------------------VFRM FUNCTIONS----------------------------------------------------- int VFRM_init( VFRModule *pVfm, char *name, bool bMulticast ) { bandwidth = (double *) av_mallocz( sizeof(double) ); cpu_usage = (double *) av_mallocz( sizeof(double) ); cpu_time = (long long *) av_mallocz( sizeof(long long)*2 ); proc_time = (long long *) av_mallocz( sizeof(long long)*2 ); *bandwidth = 0.0; *cpu_usage = 0.0; cpu_time[0] = cpu_time[1] = 0; proc_time[0] = proc_time[1] = 0; pVfm->quit_flag = 0; pVfm->video_src_id_str = (char *) av_mallocz( sizeof(char)*256 ); strcpy( pVfm->video_src_id_str, "-1" ); GOPQ_init( &(pVfm->gopq) ); if( !fscInit( &(pVfm->fsc) ) ) return 0; NVSStartup( name, bMulticast ); pVfm->fps_choice = 'f'; pVfm->new_fps_choice = 'f'; time_mus = av_gettime(); mutex = SDL_CreateMutex(); cond = SDL_CreateCond(); return 1; }
HTTPServerAgent::HTTPServerAgent(const std::string &endpoint) : m_endpoint(endpoint) { if (!s_initialised) curl_global_init(CURL_GLOBAL_ALL); m_curl = curl_easy_init(); //curl_easy_setopt(m_curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(m_curl, CURLOPT_POST, 1); curl_easy_setopt(m_curl, CURLOPT_READFUNCTION, HTTPServerAgent::FillRequestBuffer); curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, HTTPServerAgent::FillResponseBuffer); m_curlHeaders = 0; m_curlHeaders = curl_slist_append(m_curlHeaders, ("User-agent: " + UserAgent()).c_str()); m_curlHeaders = curl_slist_append(m_curlHeaders, "Content-type: application/json"); curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, m_curlHeaders); m_requestQueueLock = SDL_CreateMutex(); m_requestQueueCond = SDL_CreateCond(); m_responseQueueLock = SDL_CreateMutex(); m_thread = SDL_CreateThread(&HTTPServerAgent::ThreadEntry, "HTTPServerAgent", this); }
int simtk_init_threads_SDL (void) { if ((root_redraw_mutex = SDL_CreateMutex ()) == NULL) { ERROR ("cannot create redraw SDL mutex\n"); return -1; } if ((root_redraw_condition = SDL_CreateCond ()) == NULL) { ERROR ("cannot create redraw condition variable\n"); SDL_DestroyMutex (root_redraw_mutex); return -1; } simtk_redraw_container (root); if ((redraw_thread = SDL_CreateThread (simtk_redraw_thread_SDL, NULL)) == NULL) { ERROR ("cannot create redraw thread\n"); SDL_DestroyCond (root_redraw_condition); SDL_DestroyMutex (root_redraw_mutex); return -1; } return 0; }
void create_videostates(char* filename,int i) { channels[i] = av_mallocz(sizeof(VideoState)); channels[i]->channel = i; channels[i]->audioChannel = i; channels[i]->color_choice=NONE; av_strlcpy(channels[i]->filename, filename, sizeof(channels[i]->filename)); channels[i]->pictq_mutex = SDL_CreateMutex(); channels[i]->pictq_cond = SDL_CreateCond(); schedule_refresh(channels[i], 40); channels[i]->av_sync_type = DEFAULT_AV_SYNC_TYPE; channels[i]->parse_tid = SDL_CreateThread(decode_thread, channels[i]); if (!channels[i]->parse_tid) { av_free(channels[i]); exit(0); } }
int FE_Init () { if (0 == (SDL_INIT_TIMER & SDL_WasInit (SDL_INIT_TIMER))) SDL_InitSubSystem (SDL_INIT_TIMER); eventLock = SDL_CreateMutex (); if (NULL == eventLock) { setError ("FE: can't create a mutex"); return -1; } eventWait = SDL_CreateCond (); if (NULL == eventWait) { setError ("FE: can't create a condition variable"); return -1; } eventTimer = SDL_AddTimer (10, timerCallback, NULL); if (NULL == eventTimer) { setError ("FE: can't add a timer"); return -1; } return 0; }
Condition::Condition() : _ownMutex(true) { _mutex = new Mutex; _condition = SDL_CreateCond(); assert(_condition); }
static void init_threads(download_files_thread_data_t *data, const Uint32 count, const char* server, const char* path, zipFile dest, progress_fnc update_progress_function, void* user_data) { Uint32 i; data->files = 0; queue_initialise(&(data->files)); data->mutex = SDL_CreateMutex(); data->condition = SDL_CreateCond(); data->server = server; data->path = path; data->dest = dest; data->count = count; data->index = 0; data->running = 1; data->update_progress_function = update_progress_function; data->user_data = user_data; for (i = 0; i < UPDATE_DOWNLOAD_THREAD_COUNT; i++) { data->threads[i] = SDL_CreateThread(download_files_thread, data); } }
void packet_queue_init (PacketQueue *q) { memset (q, 0, sizeof *q); q->stop_request = false; q->mutex = SDL_CreateMutex (); q->cond = SDL_CreateCond (); }
/** ** Initialize sound card. ** ** @return True if failure, false if everything ok. */ int InitSound() { // // Open sound device, 8bit samples, stereo. // if (InitSdlSound(44100, 16)) { SoundInitialized = false; return 1; } SoundInitialized = true; // ARI: The following must be done here to allow sound to work in // pre-start menus! // initialize channels for (int i = 0; i < MaxChannels; ++i) { Channels[i].Point = i + 1; } // Create mutex and cond for FillThread Audio.MixerBuffer = new int[Audio.Format.samples * Audio.Format.channels]; memset(Audio.MixerBuffer, 0, Audio.Format.samples * Audio.Format.channels * sizeof(int)); Audio.Buffer = new Uint8[Audio.Format.size]; memset(Audio.Buffer, 0, Audio.Format.size); Audio.Lock = SDL_CreateMutex(); Audio.Cond = SDL_CreateCond(); Audio.Running = true; // Create thread to fill sdl audio buffer Audio.Thread = SDL_CreateThread(FillThread, NULL); return 0; }
PortVideoSDL::PortVideoSDL(const char* name, bool background, const char* cfg,int port) : error_( false ) , pause_( false ) , calibrate_( false ) , help_( false ) , framenumber_( 0 ) , frames_( 0 ) , recording_( false ) , width_( WIDTH ) , height_( HEIGHT ) , displayMode_( DEST_DISPLAY ) , controlPort_(port) , messageServer_(0) { cameraTime_ = processingTime_ = totalTime_ = 0.0f; calibrated_ = !background; camera_config = cfg; time_t start_time; time(&start_time); lastTime_ = (long)start_time; app_name_ = std::string(name); sourceDepth_ = 8; destDepth_ = 8; window_ = NULL; sourceBuffer_ = NULL; destBuffer_ = NULL; //Control listener is the Camera Port controlSocket_=new UdpListeningReceiveSocket( IpEndpointName( IpEndpointName::ANY_ADDRESS, controlPort_ ), this ); controlCond_=SDL_CreateCond(); controlMutex_=SDL_CreateMutex(); for(int i=0;i<256;i++){ palette_[i].r=i; palette_[i].g=i; palette_[i].b=i; } help_text.push_back("display:"); help_text.push_back(" n - no image"); help_text.push_back(" s - source image"); help_text.push_back(" t - target image"); help_text.push_back(" h - toggle help text"); help_text.push_back(""); help_text.push_back("commands:"); help_text.push_back(" ESC - quit " + app_name_); help_text.push_back(" v - verbose output"); help_text.push_back(" o - camera options"); help_text.push_back(" p - pause processing"); #ifndef NDEBUG help_text.push_back("debug options:"); help_text.push_back(" b - save buffer as PGM"); help_text.push_back(" m - save buffer sequence"); #endif }
def_dll int sdl_condition::create() { destroy(); _condition = SDL_CreateCond(); if(_condition)return 0; return -1; }
FrameExporter::FrameExporter() { //this now assumes the display is setup //before the frame exporter is created //(which seems reasonable) rowstride = display.width * 3; pixels1 = new char[display.height * rowstride]; pixels2 = new char[display.height * rowstride]; pixels_out = new char[display.height * rowstride]; pixels_shared_ptr = 0; dumper_thread_state = FRAME_EXPORTER_WAIT; cond = SDL_CreateCond(); mutex = SDL_CreateMutex(); #if SDL_VERSION_ATLEAST(2,0,0) thread = SDL_CreateThread( dumper_thread, "frame_exporter", this ); #else thread = SDL_CreateThread( dumper_thread, this ); #endif }
bool SoundSDL::init(long sampleRate) { SDL_AudioSpec wantAudioSpec; wantAudioSpec.freq = sampleRate; wantAudioSpec.format = AUDIO_S16SYS; wantAudioSpec.channels = 2; wantAudioSpec.samples = 1024; wantAudioSpec.callback = soundCallback; wantAudioSpec.userdata = this; SLOG("Wanted:: freq=%d, format=%X, channels=%d, samples=%d", wantAudioSpec.freq, wantAudioSpec.format, wantAudioSpec.channels, wantAudioSpec.samples); if(SDL_OpenAudio(&wantAudioSpec, NULL)) { SLOG("Failed to open audio: %s", SDL_GetError()); return false; } _rbuf.reset(_delay * sampleRate * 2); _cond = SDL_CreateCond(); _mutex = SDL_CreateMutex(); _initialized = true; return true; }