int main(int argc, char **argv) { opts=new SGraphOptions(); d=new DemoData(opts); plotter = new SDLPlotter(opts,d); SDL_Thread *controller = SDL_CreateThread (control,NULL); SDL_Thread *plotThread= SDL_CreateThread (plot,NULL); SDL_SetEventFilter(pollforquit); while(!done) { SDL_Delay(50); if(opts->follow) { d->SetEofReached(0); SDL_Delay(1000); plotter->PlotData(d); } if(opts->update) { d->ResetData(); SDL_Delay(1000); plotter->PlotData(d); } } plotter->QuitPlotting(); SDL_KillThread(controller); SDL_KillThread(plotThread); SDL_Quit(); exit(0); }
int main(int argc ,char* argv[]){ // freopen( "CON", "wt", stdout ); // SelfMadeBlocks(0); GameInitial(); Sint32 key; SDL_Event gameEvent; MultThread = SDL_CreateThread(ThreadFunc,NULL); AIThread = SDL_CreateThread(AIMain,NULL); while( gameOver == false ){ //press ESC or click X to quit. while( SDL_PollEvent(&gameEvent) != 0 ){ if ( gameEvent.type == SDL_QUIT ){ gameOver = true; } if ( gameEvent.type == SDL_KEYDOWN ){ if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){ gameOver = true; return 0; } key = gameEvent.key.keysym.sym; if( key==SDLK_BACKSPACE ){ AIMode ^= 1; Operation.ClearQ(); if( AIMode ){ Search(); } } // if( AIMode ){ // continue; // } switch( key ){ case SDLK_DOWN: AIPlayer.Operation.AddQ(MOVEDOWN); break; case SDLK_LEFT: AIPlayer.Operation.AddQ(MOVELEFT); break; case SDLK_RIGHT:AIPlayer.Operation.AddQ(MOVERIGHT); break; case SDLK_UP : AIPlayer.Operation.AddQ(ROTATE); break; case SDLK_TAB : AIPlayer.Operation.AddQ(TURNNEXT); break; } } } // key = SDL_GetKeyState(NULL); //实现长按效果的第一个方法 // if( key[SDLK_DOWN] ) Operation.AddQ(MOVEDOWN); // if( key[SDLK_LEFT] ) Operation.AddQ(MOVELEFT); // if( key[SDLK_RIGHT] ) Operation.AddQ(MOVERIGHT); // if( key[SDLK_UP] ) Operation.AddQ(ROTATE); SDL_Delay(1); //减轻CPU负担 } SDL_KillThread(MultThread); SDL_KillThread(AIThread); pressESCtoQuit(); return 0; }
void ChatState::finalize() { if (_instance != NULL) { if (_sentinelThread != NULL) SDL_KillThread(_sentinelThread); if (_reconnectThread != NULL) SDL_KillThread(_reconnectThread); delete _instance; _instance = NULL; } }
// the principal program sequence void PortVideoSDL::run() { if( !setupCamera() ) { if( !setupWindow() ) return; showError("No camera found!"); teardownWindow(); return; } if( !setupWindow() ) return; allocateBuffers(); initFrameProcessors(); bool success = camera_->startCamera(); if( success ){ SDL_FillRect(window_,0,0); SDL_Flip(window_); // add the help message from all FrameProcessors for (frame = processorList.begin(); frame!=processorList.end(); frame++) { std::vector<std::string> processor_text = (*frame)->getOptions(); if (processor_text.size()>0) help_text.push_back(""); for(std::vector<std::string>::iterator processor_line = processor_text.begin(); processor_line!=processor_text.end(); processor_line++) { help_text.push_back(*processor_line); } } //print the help message for(std::vector<std::string>::iterator help_line = help_text.begin(); help_line!=help_text.end(); help_line++) { std::cout << *help_line << std::endl; } std::cout << std::endl; running_=true; cameraThread = SDL_CreateThread(getFrameFromCamera,this); controlThread= SDL_CreateThread(getControlMessage,this); mainLoop(); SDL_KillThread(cameraThread); SDL_KillThread(controlThread); teardownCamera(); } else { showError("Could not start camera!"); } teardownWindow(); freeBuffers(); }
bool Thread::destroyThread() { if (!_threadRunning) return true; // Signal the thread that it should die _killThread = true; // Wait a whole second for the thread to finish on its own for (int i = 0; _threadRunning && (i < 100); i++) SDL_Delay(10); if (!_threadRunning) { // Wait for everything to settle SDL_WaitThread(_thread, 0); _killThread = false; _threadRunning = false; return true; } // Still running? Just kill the bugger, then SDL_KillThread(_thread); _killThread = false; _threadRunning = false; return false; }
static void CloseStuff(int signum) { printf(_("\nSignal %d has been caught and dealt with...\n"),signum); for(unsigned int x = 0; x < sizeof(SignalDefs) / sizeof(SignalInfo); x++) { if(SignalDefs[x].number == signum) { printf("%s", _(SignalDefs[x].message)); if(SignalDefs[x].SafeTryExit) { SDL_Event evt; memset(&evt, 0, sizeof(SDL_Event)); evt.user.type = SDL_QUIT; SDL_PushEvent(&evt); return; } break; } } if(GameThread && SDL_ThreadID() == MainThreadID) { SDL_KillThread(GameThread); GameThread = NULL; } exit(1); }
NetClient::~NetClient() { Connected = false; // Sleep until the other thread has finished (max 4 sec). Clock wait_for_thread; while( Thread && (wait_for_thread.ElapsedSeconds() < 4.) ) SDL_Delay( 1 ); // If the thread didn't finish, kill it. if( Thread ) { SDL_KillThread( Thread ); Thread = NULL; } // Clean up old data and socket. Cleanup(); if( Lock ) { SDL_DestroyMutex( Lock ); Lock = NULL; } if( Initialized ) SDLNet_Quit(); }
int receiveMessages(void* socka) { int len; char message[1024]; UDPsoc sock = *(UDPsoc*)(socka); while(1) { len=sock.Recv(message, 1024); if(len) { for(int n=0; n<onTheTable_len; n++) printf("\b"); for(int n=0; n<onTheTable_len; n++) printf(" "); printf("\rReceiving: %s\n", message); if(onTheTable_len) { for(int n=0; n<onTheTable_len; n++) printf("%c",onTheTable[n]); onTheTable_len=0; } } else { printf("AIR OR\n"); } if(message[0]=='e' && message[1]=='n' && message[2]=='d' && message[3]==0) { out=1; break; } } printf("\tConnection has been closed from the other side. Press enter to quit.\n"); SDL_KillThread(sendThread); }
int sendMessages(void* socka) { int len, temp, n; char message[1024]; UDPsoc sock = *(UDPsoc*)(socka); while(1) { if(khit()) { printf("Send: "); onTheTable_len=6; for(n=0; (temp=gech())!='\n'; n++) { if(temp == '\b') { n-=2; onTheTable_len--; } else { message[n]=temp; onTheTable[6+n] = temp; onTheTable_len++; } } message[n]=0; onTheTable_len=0; //send message to client if(sock.Send(message,n+1)) printf("\t\tEr ur\n"); if(message[0]=='e' && message[1]=='n' && message[2]=='d' && message[3]==0) break; } SDL_Delay(10); } printf("Connection has been closed (by you). Press enter to quit.\n"); SDL_KillThread(recvThread); }
ClientConnection::~ClientConnection() { // Signal to stop status = -1; SDL_WaitThread(send_thread, NULL); // We don't need to lock because the send_thread is terminated while (data_to_send.size() > 0) { delete data_to_send.front().data; data_to_send.pop_front(); } // make sure we don't trash messages when killing the thread. SDL_LockMutex(messages_mutex); SDL_KillThread(recieve_thread); SDL_UnlockMutex(messages_mutex); SDLNet_TCP_Close(socket); SDL_DestroyMutex(send_mutex); SDL_DestroyMutex(messages_mutex); // Remove this client from the world //entity->world->delete_entity(entity); //entity = 0; }
void BGApp::finalize() { SDL_mutexP(this->_mutex); if (this->_initialized) { if (this->_xmpprunner != NULL && this->_xmpprunner->_connection != NULL) { try { this->_xmpprunner->_connection->sendClose(); } catch (exception& ex) { _LOGDATA("Error sending BGApp::finalize:sendingClose: %s", ex.what()); } } if (this->_xmpprunner != NULL) this->_xmpprunner->killWithConfirmation(); SDL_KillThread(this->_xmppthread); ChatState::finalize(); if (this->_xmpprunner != NULL) delete _xmpprunner; this->_lastXMPPRunnerKill = time(NULL); this->_chatState = NULL; this->_xmpprunner = NULL; this->_initialized = false; } SDL_mutexV(this->_mutex); }
void thread::kill() { if(thread_ != NULL) { SDL_KillThread(thread_); thread_ = NULL; } }
void midi_engine_stop(void) { struct midi_provider *n, *p; struct midi_port *q; if (!_connected) return; if (!midi_mutex) return; SDL_mutexP(midi_mutex); for (n = port_providers; n;) { p = n->next; q = NULL; while (midi_port_foreach(p, &q)) { midi_port_unregister(q->num); } if (n->thread) { SDL_KillThread(n->thread); } free(n->name); free(n); n = p; } _connected = 0; SDL_mutexV(midi_mutex); }
RLogMill::~RLogMill() { abort(); if(thread) SDL_KillThread(thread); if(clog) delete clog; }
/* ================== Sys_ShutdownThreads ================== */ void Sys_ShutdownThreads() { // threads for (int i = 0; i < MAX_THREADS; i++) { if (!thread[i]) continue; Sys_Printf("WARNING: Thread '%s' still running\n", thread[i]->name); SDL_KillThread(thread[i]->threadHandle); thread[i] = NULL; } // events for (int i = 0; i < MAX_TRIGGER_EVENTS; i++) { SDL_DestroyCond(cond[i]); cond[i] = NULL; signaled[i] = false; waiting[i] = false; } // critical sections for (int i = 0; i < MAX_CRITICAL_SECTIONS; i++) { SDL_DestroyMutex(mutex[i]); mutex[i] = NULL; } }
int main(int argc, char** argv){ if(!argv[1]){ puts("No IP input found. Please initiate in the form ' ./Player <Server IP> '"); exit(1); } //fgets from stdin to get clientname (and pass that into run, ezpz) printf("Please enter your name: "); fgets(clientname, 64, stdin); clientname[strlen(clientname) - 1] = '\0'; printf("Hello %s!\n", clientname); strcat(clientname, " : "); namelen = strlen(clientname); /// SDL_Surface* screen = initScreen(); //Initiate the semaphores and chatserver thread msgbuf_sem = SDL_CreateSemaphore(1); textSem = SDL_CreateSemaphore(1); chatserv = SDL_CreateThread(chatserver, screen); //Initiate the server connection int socket_id = server_setup(argv[1]); //Initiate the client's sprite Uint32 colorkey = SDL_MapRGB( screen->format, 255, 255, 255); initiate(socket_id, colorkey); TTF_Init(); run(screen, socket_id); //CEASE AND DESIST SDL_KillThread(chatserv); SDL_FreeSurface(screen); SDL_Quit(); TTF_Quit(); int i; for(i=0; i<numMessages; i++) if(text[i] != NULL) SDL_FreeSurface(text[i]); SDL_DestroySemaphore(msgbuf_sem); SDL_DestroySemaphore(textSem); return 1; }
void chess_exit(struct chess_t *chess) { SDL_KillThread(chess->conn); free(chess->packet); free(chess->cli_list); close(chess->fd); sdl_exit(&chess->sdl); }
void callback_quit() { TTF_Quit(); glDeleteTextures( 1, &buttons_tex ); SDL_KillThread(compute_thread); SDL_Quit(); exit(EXIT_SUCCESS); }
// __________________________________________________________________________________________________ void KikiPlayback::start (const std::string filename) { static std::vector<KikiKeyRecord*> key_records; std::string record_string; record_string = kFileReadStringFromFile (filename); std::vector<std::string> lines = kStringGetComponents (record_string, "\n"); std::vector<std::string>::iterator iter; if (thread) SDL_KillThread (thread); key_records.clear(); iter = lines.begin(); std::string world_name = (*iter).substr ((*iter).find (":") + 2); if (world_name != Controller.world->getName()) { Controller.python->execute (kStringPrintf ("KikiPyWorld().create (\"%s\")", world_name.substr (0,world_name.size()-1).c_str())); // hack alert! } iter++; Controller.world->setCameraMode (atoi ((*iter).substr ((*iter).find (":") + 2).c_str())); iter++; unsigned int open = (*iter).find("[")+1; unsigned int close = (*iter).find("]"); std::vector<std::string> values = kStringGetComponents ((*iter).substr(open, close-open), " "); KikiPos pos (atoi(values[0].c_str()), atoi(values[1].c_str()), atoi(values[2].c_str())); Controller.world->moveObjectToPos (Controller.player, pos); iter++; open = (*iter).find("<")+1; close = (*iter).find(">"); values = kStringGetComponents ((*iter).substr(open, close-open), " "); KQuaternion orientation (atof(values[0].c_str()), atof(values[1].c_str()), atof(values[2].c_str()), atof(values[3].c_str())); Controller.player->setOrientation (orientation); iter++; for (; iter != lines.end(); iter++) { if (iter->empty() == false) { if (iter->find("world:") == 0) { next_world = (*iter).substr ((*iter).find (":") + 2); } else { std::vector<std::string> v = kStringGetComponents ((*iter), " "); key_records.push_back (new KikiKeyRecord (atoi(v[0].c_str()), v[1], atoi(v[2].c_str()))); } } } halt = false; thread = SDL_CreateThread (KikiPlayback::playback, &key_records); }
void remove_thread(unsigned int thread_id) #endif { struct thread_entry *current = cores[CURRENT_CORE].running; struct thread_entry *thread = thread_id_entry(thread_id); SDL_Thread *t; SDL_sem *s; if (thread_id != THREAD_ID_CURRENT && thread->id != thread_id) return; int oldlevel = disable_irq_save(); t = thread->context.t; s = thread->context.s; thread->context.t = NULL; if (thread != current) { switch (thread->state) { case STATE_BLOCKED: case STATE_BLOCKED_W_TMO: /* Remove thread from object it's waiting on */ remove_from_list_l(thread->bqp, thread); #ifdef HAVE_WAKEUP_EXT_CB if (thread->wakeup_ext_cb != NULL) thread->wakeup_ext_cb(thread); #endif break; } SDL_SemPost(s); } THREAD_SDL_DEBUGF("Removing thread: %d (%s)\n", thread - threads, THREAD_SDL_GET_NAME(thread)); new_thread_id(thread->id, thread); thread->state = STATE_KILLED; thread_queue_wake(&thread->queue); SDL_DestroySemaphore(s); if (thread == current) { /* Do a graceful exit - perform the longjmp back into the thread function to return */ restore_irq(oldlevel); longjmp(thread_jmpbufs[current - threads], 1); } SDL_KillThread(t); restore_irq(oldlevel); }
void rj_interface_cleanup() { if (rj_reader_thread) SDL_KillThread(rj_reader_thread); if (rj_sock >= 0) close(rj_sock); }
static void resolverstop(ResolverThread &rt, bool restart) { SDL_LockMutex(resolvermutex); SDL_KillThread(rt.thread); rt.query = NULL; rt.starttime = 0; rt.thread = NULL; if (restart) rt.thread = SDL_CreateThread(resolverloop, &rt); SDL_UnlockMutex(resolvermutex); }
//Stop the speech if it is speaking void T4K_Tts_stop(){ extern SDL_Thread *tts_thread; if (tts_thread) { SDL_KillThread(tts_thread); tts_thread = NULL; espeak_Cancel(); } }
ServerConsole::~ServerConsole() { if(thread && running) { // TODO avoid KillThread here... SDL_KillThread(thread); } else { SDL_WaitThread(thread, 0); } }
/** * Kill the thread in case the game is quit early. */ StartState::~StartState() { if (_thread != 0) { SDL_KillThread(_thread); } delete _font; delete _timer; delete _lang; }
ChatState* ChatState::initialize() { if (_instance != NULL) { if (_sentinelThread != NULL) SDL_KillThread(_sentinelThread); if (_reconnectThread != NULL) SDL_KillThread(_reconnectThread); delete _instance; } ChatState* curState = new ChatState(); curState->setState(ChatState::CHAT_STATE_DISCONNECTED); _instance = curState; if (SEND_PING) { _sentinelThread = SDL_CreateThread(ChatState::sentinelTaskCallBack, (void*) ((Uint32) (MAX_SILENT_INTERVAL * 1000))); if (_sentinelThread == NULL) _LOGDATA("Error adding timer sentinelTask"); } return curState; }
void SDLThread::end() { if (_handle != NULL){ _isRunning = false; // kill the thread SDL_KillThread(_handle); _handle = NULL; } }
Client::~Client() { if (listener_thread != 0) SDL_KillThread(listener_thread); // close the connection on sock SDLNet_TCP_Close(sock); if (mutex != 0) SDL_DestroyMutex(mutex); }
void seqbuf_dump() { if (_seqbufptr) { if (write(seqfd, _seqbuf, _seqbufptr) == -1) { perror ("Error writing sequencer device"); SDL_KillThread(player_thread); } } _seqbufptr = 0; }
/* ** Destroy a model viewing context */ void z64mv_destroy ( Z64MV * handle ) { /* Free pointers */ pfree( (void**)&handle->contents ); pfree( (void**)&handle->filename ); /* End the thread */ SDL_KillThread( handle->proc ); /* Free the context */ free( handle ); }