boolean debug_event(int event, Object *exception, const Thread *thread, const MethodRecord *method, byte *pc, int frame) { // Inform the debug thread (if any) that there has been a debug event. // return false if no debug thread is waiting. switch(debugEventOptions[event]) { case DBG_EVENT_DISABLE: return false; case DBG_EVENT_IGNORE: return true; default: break; } // Check that we have a debugger attached and that it is ready to go... if (!debug || get_monitor_count((&(debug->_super.sync))) != 0 || debugThread->state != CONDVAR_WAITING || (Debug *)debugThread->waitingOn != debug) return false; // Setup the state debug->typ = event; debug->exception = ptr2ref(exception); debug->thread = ptr2ref(thread); debug->pc = (pc ? pc - get_binary_base() : 0); debug->method = (method ? method - get_method_table(get_class_record(0)) : 0); debug->frame = frame; // Suspend all threads (except current) suspend_thread(null); // Make sure current thread is also suspended suspend_thread(currentThread); // Allow the debug thread to run resume_thread(debugThread); monitor_notify_unchecked(&debug->_super, 1); return true; }
void suspend_vsh_thread(void) { sceDisplayWaitVblankStart(); suspend_thread("SCE_VSH_GRAPHICS"); suspend_thread("movie_player"); suspend_thread("audio_buffer"); suspend_thread("music_player"); }
void MainWindow::DoSuspend(void) { BRow* selected = NULL; while ((selected = teamView->CurrentSelection(selected))) { // is a team or thread? if (selected->HasLatch()) for (int i = 0; i < teamView->CountRows(selected); i++) suspend_thread(((ThreadItem *)teamView->RowAt(i, selected))->thread); else suspend_thread(((ThreadItem *)selected)->thread); } }
void Events::wait_for_coming() { acquire_sem(wait_); waiting_thread_ = find_thread(NULL); suspend_thread(waiting_thread_); waiting_thread_ = -1; release_sem(wait_); }
// Synchronous version, not in use at the moment bool nsToolkit::CallMethod(MethodInfo *info) { #ifdef DEBUG printf("TK-CM\n"); #endif ThreadInterfaceData id; GetInterface(); id.data = info; id.waitingThread = find_thread(NULL); // Check message count to not exceed the port's capacity. // There seems to be a BeOS bug that allows more // messages on a port than its capacity. port_info portinfo; if (get_port_info(eventport, &portinfo) != B_OK) { return false; } if (port_count(eventport) < portinfo.capacity - 20) { // If we cannot write inside 5 seconds, something is really wrong. if(write_port_etc(eventport, WM_CALLMETHOD, &id, sizeof(id), B_TIMEOUT, 5000000) == B_OK) { // semantics for CallMethod are that it should be synchronous suspend_thread(id.waitingThread); return true; } } return false; }
extern void unmake_timer_thread(void) { CONTEXT timer_thread_context; BOOL result; DIAGNOSTIC(2,"unmaking timer thread",0,0); suspend_thread(timer_thread); DIAGNOSTIC(3,"timer thread suspended",0,0); timer_thread_context.ContextFlags = CONTEXT_CONTROL; result = GetThreadContext((HANDLE)timer_thread, &timer_thread_context); if (result == FALSE) error("GetThreadContext(timer) failed; GetLastError() returns %d", GetLastError()); DIAGNOSTIC(3,"timer thread context obtained",0,0); timer_thread_context.Eip = (DWORD)timer_thread_end; result = SetThreadContext((HANDLE)timer_thread, &timer_thread_context); if (result == FALSE) error("SetThreadContext(timer) failed; GetLastError() returns %d", GetLastError()); DIAGNOSTIC(3,"timer thread context set",0,0); set_event(timer_event); DIAGNOSTIC(3,"timer event set",0,0); resume_thread(timer_thread); DIAGNOSTIC(3,"timer thread resumed",0,0); wait_for_event(timer_thread); DIAGNOSTIC(3,"timer thread signalled",0,0); close_handle(timer_thread); close_handle(timer_event); DIAGNOSTIC(2,"timer thread unmade and forgotten",0,0); }
QueueActions::~QueueActions(){ if(Lock()){ suspend_thread(fID); exit_thread(fID); delete_sem(fLock); } }
// suspend all available threads in a given pid int suspend_all_threads(pid_t target_pid) { #if DEBUG printf("[DEBUG] Suspending all threads...\n"); #endif task_t targetTask; mach_port_t me = mach_task_self(); thread_act_port_array_t thread_list; mach_msg_type_number_t thread_count,i; if(task_for_pid(me, target_pid, &targetTask)) { fprintf(stderr, "[ERROR] task for pid failed while trying to suspend threads!\n"); fprintf(stderr, "Verify if python has the right procmod permissions!\n"); exit(1); } if (task_threads(targetTask, &thread_list, &thread_count)) { fprintf(stderr, "[ERROR] task_threads failed at %s\n", __FUNCTION__); exit(1); } if (thread_count > 0) { i = thread_count; while (i--) { suspend_thread(thread_list[i]); } } return(0); }
// destructor NetFSServer::~NetFSServer() { fTerminating = true; // stop the connection listener if (fConnectionListener) fConnectionListener->StopListening(); if (fConnectionListenerThread >= 0) { int32 result; wait_for_thread(fConnectionListenerThread, &result); } delete fConnectionListener; // delete the broadcaster semaphore if (fBroadcasterSemaphore >= 0) delete_sem(fBroadcasterSemaphore); // terminate the broadcaster if (fBroadcaster >= 0) { safe_closesocket(fBroadcastingSocket); // interrupt the thread in case it is currently snoozing suspend_thread(fBroadcaster); int32 result; wait_for_thread(fBroadcaster, &result); } // terminate the server info connection listener _ExitServerInfoConnectionListener(); // terminate the connection deleter if (fClosedConnectionsSemaphore >= 0) delete_sem(fClosedConnectionsSemaphore); if (fConnectionDeleter >= 0) { int32 result; wait_for_thread(fConnectionDeleter, &result); } // blow away all remaining connections AutoLocker<Locker> _(fLock); // open connections for (int32 i = 0; ClientConnection* connection = (ClientConnection*)fClientConnections.ItemAt(i); i++) { connection->Close(); delete connection; } // closed connections for (int32 i = 0; ClientConnection* connection = (ClientConnection*)fClosedConnections.ItemAt(i); i++) { delete connection; } VolumeManager::DeleteDefault(); FDManager::DeleteDefault(); delete fSecurityContext; }
void InfoBox::ExitUpdateThread() { if (suspend_thread(update_Thread)!=B_BAD_THREAD_ID) { //send_data(update_Thread, 'exit', NULL, 0); kill_thread(update_Thread); //acquire_sem(exit_thread_sem); } ut_running=false; }
boolean debug_event(int event, Throwable *exception, const Thread *thread, const int method, const int pc, const int method2, const int pc2) { if (!debug) return false; // Check whether the event occured on a system thread. Events on system threads are disabled. if (is_system(thread)) return false; // Inform the debug thread (if any) that there has been a debug event. // return false if no debug thread is waiting. switch (debugEventOptions[event]) { case DBG_EVENT_DISABLE: return false; case DBG_EVENT_IGNORE: return true; default: break; } // Check that we have a debugger attached and that it is ready to go... if (get_monitor_count((&(debug->_super.sync))) != 0 || debugThread->state != CONDVAR_WAITING || (Debug *) debugThread->waitingOn != debug) return false; // Setup the state debug->typ = event; debug->exception = ptr2ref(exception); debug->thread = ptr2ref(thread); debug->pc = pc; debug->method = method; debug->method2 = method2; debug->pc2 = pc2; // Suspend all threads (except current) suspend_thread(null); // Make sure current thread is also suspended if (!is_system(currentThread)) suspend_thread(currentThread); // Allow the debug thread to run debugThread->flags &= ~THREAD_DAEMON; resume_thread(debugThread); monitor_notify_unchecked(&debug->_super, 1); return true; }
void Controller::_PauseCapture() { SendNotices(kMsgControllerCapturePaused); BAutolock _(this); fPaused = true; suspend_thread(fCaptureThread); }
gboolean sgen_park_current_thread_if_doing_handshake (SgenThreadInfo *p) { if (!p->doing_handshake) return FALSE; suspend_thread (p, NULL); return TRUE; }
int32 QueueActions::ManageTheQueue(void* data) { QueueActions *qa=(QueueActions*)data; printf("Thread started %ld\n",qa->fID); while(true){ Action *last=NULL; if(qa->Lock()) { printf("Thread executing PID %ld Count %ld\n",qa->fID,qa->fList.CountItems()); if(qa->fList.CountItems()>0){ // remove and delete the action. last=qa->fList.ItemAt(0); qa->fList.RemoveItemAt(0); qa->SetCurrentAction(last); } else { last=NULL; qa->SetCurrentAction(last); } qa->Unlock(); } if(last) { // pop the action qa->ActionReadyToPerform(last); // perform the action BMessage err; status_t status = last->Perform(&err); // do post-perform! qa->ActionPerformed(last,status,&err); if(qa->Lock()){ qa->SetCurrentAction(NULL); delete last; qa->Unlock(); } } else { printf("Thread suspend PID %ld Count %ld\n",qa->fID,qa->fList.CountItems()); suspend_thread(qa->fID); } } //while }
/* LOCKING: assumes the GC lock is held (by the stopping thread) */ static void suspend_handler (int sig, siginfo_t *siginfo, void *context) { SgenThreadInfo *info; int old_errno = errno; info = mono_thread_info_current (); suspend_thread (info, context); errno = old_errno; }
void suspend_all (LPDBGPROCESS process) { LPDBGTHREAD this_thread = process->ThreadList; while (this_thread != NULL) { suspend_thread(this_thread); this_thread = this_thread->Next; } }
TextScrollerView::~TextScrollerView() { if (continue_updating) { continue_updating = false; tracking_mouse = false; suspend_thread(updater_thread); snooze(1000); int32 return_value; wait_for_thread(updater_thread,&return_value); } }
void idle_wait(void) { #if 0 /* FIXME: add a semaphore (counter) to avoid a B_BAD_THREAD_STATE return if we call idle_resume() when thread is not suspended? Sorry, I can't test -- gb. */ suspend_thread(emul_thread); #endif }
void suspend_all_except (LPDBGPROCESS process, LPDBGTHREAD thread) { LPDBGTHREAD this_thread = process->ThreadList; while (this_thread != NULL) { if (this_thread != thread) suspend_thread(this_thread); this_thread = this_thread->Next; } }
void AutoMounter::SuspendResume(bool _DEVICE_MAP_ONLY(suspend)) { #if _INCLUDES_CLASS_DEVICE_MAP AutoLock<BLooper> lock(this); fSuspended = suspend; if (fSuspended) suspend_thread(fScanThread); else resume_thread(fScanThread); #endif }
extern word* suspend_current_thread(void) { word *thread = #ifdef NATIVE_THREADS CURRENT_THREAD->c_state.native.thread; #else main_thread; #endif suspend_thread(thread); DIAGNOSTIC(2,"suspended ML threads",0,0); return thread; }
void nsToolkit::CallMethod(MethodInfo *info) { ThreadInterfaceData id; GetInterface(); id.data = info; id.waitingThread = find_thread(NULL); if(write_port(eventport, WM_CALLMETHOD, &id, sizeof(id)) == B_OK) { // semantics for CallMethod are that it should be synchronous suspend_thread(id.waitingThread); } }
extern "C" Display* XOpenDisplay(const char *name) { Display* display = new _XDisplay; memset(display, 0, sizeof(Display)); main_thread = find_thread(NULL); thread_info info; get_thread_info(main_thread, &info); rename_thread(main_thread, "X Server"); server_thread = spawn_thread(xmain, info.name, B_NORMAL_PRIORITY, 0); resume_thread(server_thread); suspend_thread(main_thread); init_font(); set_display(display); return display; }
void hb_cond_wait( hb_cond_t * c, hb_lock_t * lock ) { #if defined( SYS_BEOS ) c->thread = find_thread( NULL ); release_sem( lock->sem ); suspend_thread( c->thread ); acquire_sem( lock->sem ); c->thread = -1; #elif USE_PTHREAD pthread_cond_wait( &c->cond, &lock->mutex ); //#elif defined( SYS_CYGWIN ) // SignalObjectAndWait( lock->mutex, c->event, INFINITE, FALSE ); // WaitForSingleObject( lock->mutex, INFINITE ); #endif }
void StandAloneTaskLoop::AddTask(DelayedTask *delayedTask) { _inherited::AddTask(delayedTask); if (fScanThread < 0) return; // wake up the loop thread if it is asleep thread_info info; get_thread_info(fScanThread, &info); if (info.state == B_THREAD_ASLEEP) { suspend_thread(fScanThread); snooze(1000); // snooze because BeBook sez so resume_thread(fScanThread); } }
asmlinkage int pthread_join_sys (pthread_t thread, void **value_ptr) { int flags, c_state; pthread_t old_thread; if (!thread || thread -> magic_number != PTHREAD_MAGIC_NUMBER) { SET_ERRNO (ESRCH); return -1; } if (GET_THREAD_DETACH_STATE(thread)) { SET_ERRNO (EINVAL); return -1; } hw_save_flags_and_cli (flags); c_state = GET_THREAD_STATE (thread); while (c_state != FINISHED_THREAD) { thread -> joining_thread = current_thread; //printf("suspend_thread current_thread 0x%x thread 0x%x\n", (unsigned long)current_thread, (unsigned long)thread); old_thread = current_thread; suspend_thread (current_thread); //printf("current_thread 0x%x join 0x%x c_state %d flags %d\n", (unsigned long)current_thread, (unsigned long)thread, c_state, flags); scheduling (); //ret_may_switch(current_thread, old_thread); //printf("current_thread 0x%x join 0x%x c_state %d flags %d\n", (unsigned long)current_thread, (unsigned long)thread, c_state, flags); c_state = GET_THREAD_STATE (thread); if (GET_THREAD_DETACH_STATE(thread)) { hw_restore_flags (flags); SET_ERRNO (EINVAL); return -1; } } if (value_ptr) *value_ptr = thread -> exit_value; //printf("thread 0x%x exit_value 0x%x\n", (unsigned long)current_thread, thread->exit_value); delete_pthread_struct (thread); hw_restore_flags (flags); return 0; }
void hb_cond_timedwait( hb_cond_t * c, hb_lock_t * lock, int msec ) { #if defined( SYS_BEOS ) c->thread = find_thread( NULL ); release_sem( lock->sem ); suspend_thread( c->thread ); acquire_sem( lock->sem ); c->thread = -1; #elif USE_PTHREAD struct timespec ts; hb_clock_gettime(&ts); ts.tv_nsec += (msec % 1000) * 1000000; ts.tv_sec += msec / 1000 + (ts.tv_nsec / 1000000000); ts.tv_nsec %= 1000000000; pthread_cond_timedwait( &c->cond, &lock->mutex, &ts ); #endif }
/* LOCKING: assumes the GC lock is held (by the stopping thread) */ static void suspend_handler (int sig, siginfo_t *siginfo, void *context) { SgenThreadInfo *info; int old_errno = errno; info = mono_thread_info_current (); if (info) { suspend_thread (info, context); } else { /* This can happen while a thread is dying */ //g_print ("no thread info in suspend\n"); } errno = old_errno; }
bool MessageWindow::QuitRequested (void) { if (dChat) { dConnected = false; if (dInitiate) close (mySocket); close (acceptSocket); suspend_thread (dataThread); kill_thread (dataThread); } return ClientWindow::QuitRequested(); }
int JabberSocketPlug::StopConnection(){ //Thread Killing! suspend_thread(fReceiverThread); if(fReceiverThread) kill_thread(fReceiverThread); fReceiverThread=0; #ifdef BONE_BUILD close(fSocket); #elif NETSERVER_BUILD closesocket(fSocket); #endif return 0; }