void save_old_state(JavaThread* java_thread) { _java_thread = java_thread; _is_alive = is_alive(java_thread); if (is_alive()) { _old_state = java_lang_Thread::get_thread_status(_java_thread->threadObj()); } }
/* Function count_alive_neighbors Given a game board, array, and a row and column (row, col), determines the number of surrounding cells that are alive. If the cell is not on the game board, prints an error message and terminates the program. Input: int rows - the number of rows of the game board int cols - the number of columns of the game board int[][] array - the previous generation of the game board, a 2D array of zeros and ones int row - the row of the cell whose neighbors are being counted int col - the column of the cell whose neighbors are being counted Output: The number of surrounding cells that are alive */ int count_alive_neighbors(int rows, int cols, int array[rows][cols], int row, int col) { /* First, use an assert statement and call is_in_range to confirm the specified cell is on the game board. */ assert(is_in_range(rows, cols, row, col)); /* Then, assuming the assert succeeds: Compute and return the number of live neighbors by adding together the results of is_alive for each of the 8 surrounding cells. Since is_alive checks to see if a cell is on the board, you do not need to do so here. */ int counter = 0; int r, c; for(r=(row-1); r<=(row+1); r++) { for(c=(col-1); c<=(col+1); c++) { if(is_alive(rows, cols, array, r, c)) { counter++; } } } if(is_alive(rows, cols, array, row, col)) { counter = counter-1; } return counter; }
void curr_exe() { if (is_alive(CURR_POKEMON) && is_alive(OTHR_POKEMON)) { if (is_move(CURR_ACTION)) { curr_attack(); } else { curr_switchto(); } } }
/// Releases job control resources and terminates running jobs void job_teardown(void) { // 20 tries will give processes about 1 sec to exit cleanly uint32_t remaining_tries = 20; bool all_dead = true; int i; Job *job; // Politely ask each job to terminate for (i = 0; i < MAX_RUNNING_JOBS; i++) { if ((job = table[i]) != NULL) { all_dead = false; uv_process_kill(&job->proc, SIGTERM); } } if (all_dead) { return; } os_delay(10, 0); // Right now any exited process are zombies waiting for us to acknowledge // their status with `wait` or handling SIGCHLD. libuv does that // automatically (and then calls `exit_cb`) but we have to give it a chance // by running the loop one more time event_poll(0); // Prepare to start shooting for (i = 0; i < MAX_RUNNING_JOBS; i++) { job = table[i]; // Still alive while (job && is_alive(job) && remaining_tries--) { os_delay(50, 0); // Acknowledge child exits event_poll(0); // It's possible that the event_poll call removed the job from the table, // reset 'job' so the next iteration won't run in that case. job = table[i]; } if (job && is_alive(job)) { uv_process_kill(&job->proc, SIGKILL); } } // Last run to ensure all children were removed event_poll(0); }
gboolean gveejay_idle(gpointer data) { if(gveejay_running()) { int sync = 0; if( is_alive(&sync) == FALSE ) { return FALSE; } if( sync ) { if( gveejay_time_to_sync( get_ui_info() ) ) { veejay_update_multitrack( get_ui_info() ); } } else { // gveejay_sleep( get_ui_info() ); } update_gveejay(); } if( gveejay_restart() ) { //@ reinvoke if( execvp( cargv[0], cargv ) == -1 ) veejay_msg(VEEJAY_MSG_ERROR, "Unable to restart"); } return TRUE; }
void observer_list::clear () { __TBB_ASSERT( this != &the_global_observer_list, "Method clear() cannot be used on the list of global observers" ); // Though the method will work fine for the empty list, we require the caller // to check for the list emptiness before invoking it to avoid extra overhead. __TBB_ASSERT( !empty(), NULL ); { scoped_lock lock(mutex(), /*is_writer=*/true); observer_proxy *next = my_head; while ( observer_proxy *p = next ) { __TBB_ASSERT( p->my_version >= 6, NULL ); next = p->my_next; // Both proxy p and observer p->my_observer (if non-null) are guaranteed // to be alive while the list is locked. task_scheduler_observer_v3 *obs = p->my_observer; // Make sure that possible concurrent observer destruction does not // conflict with the proxy list cleanup. if ( !obs || !(p = (observer_proxy*)__TBB_FetchAndStoreW(&obs->my_proxy, 0)) ) continue; __TBB_ASSERT( !next || p == next->my_prev, NULL ); __TBB_ASSERT( is_alive(p->my_ref_count), "Observer's proxy died prematurely" ); __TBB_ASSERT( p->my_ref_count == 1, "Reference for observer is missing" ); __TBB_ASSERT( !obs->my_busy_count, "Local observer in an empty arena cannot be marked as busy" ); store<relaxed>( obs->my_busy_count, interface6::task_scheduler_observer::v6_trait ); #if TBB_USE_ASSERT p->my_observer = NULL; p->my_ref_count = 0; #endif /* TBB_USE_ASSERT */ remove(p); delete p; } } while( my_head ) __TBB_Yield(); }
static Audio_instrument_widget *create_audio_instrument_widget(struct Patch *patch, bool set_as_current){ EditorWidget *editor = static_cast<EditorWidget*>(root->song->tracker_windows->os_visual.widget); Audio_instrument_widget *instrument = new Audio_instrument_widget(editor->main_window,patch); R_ASSERT_RETURN_IF_FALSE2(instrument!=NULL, NULL); instrument->_patch_widget->name_widget->setText(patch->name); //instruments_widget->tabs->insertTab(instrument, QString::fromLatin1(patch->name), instruments_widget->tabs->count()); g_instruments_widget->tabs->insertWidget(g_instruments_widget->tabs->count(),instrument); // (forgot to take copy) if (set_as_current){ IsAlive is_alive(instrument); // Schedule this happen a little bit later since setCurrentWidget triggers an eventEvent, which might not work properly before the instrument is finished initializing. QTimer::singleShot(g_set_current_delay,[is_alive, instrument]{ if (!is_alive) return; g_instruments_widget->tabs->setCurrentWidget(instrument); MW_update_all_chips(); }); } instrument->updateWidgets(); return instrument; }
CPUThread::CPUThread(CPUThreadType type, const std::string& name, std::function<std::string()> thread_name) : m_id(idm::get_last_id()) , m_type(type) , m_name(name) { start(std::move(thread_name), [this] { g_tls_current_cpu_thread = this; Emu.SendDbgCommand(DID_CREATE_THREAD, this); std::unique_lock<std::mutex> lock(mutex); // check thread status while (joinable() && is_alive()) { CHECK_EMU_STATUS; // check stop status if (!is_stopped()) { if (lock) lock.unlock(); try { task(); } catch (CPUThreadReturn) { ; } catch (CPUThreadStop) { m_state |= CPU_STATE_STOPPED; } catch (CPUThreadExit) { m_state |= CPU_STATE_DEAD; break; } catch (...) { dump_info(); throw; } m_state &= ~CPU_STATE_RETURN; continue; } if (!lock) { lock.lock(); continue; } cv.wait(lock); } }); }
void iLiving::apply_status(eStatus which, int how_much) { if(!is_alive()) return; static const std::set<eStatus> allow_negative = { // The obvious ones: eStatus::BLESS_CURSE, eStatus::HASTE_SLOW, // The ones that BoE previously allowed: eStatus::POISONED_WEAPON, eStatus::POISON, eStatus::ASLEEP, // (Note: Negative levels of sleep can be obtained from the Hyperactivity spell. The other two never go negative.) // The additional ones that make sense in the negative: eStatus::MAGIC_RESISTANCE, eStatus::DUMB, }; int lo = 0, hi = 8; if(which == eStatus::MARTYRS_SHIELD) hi = 10; else if(which == eStatus::PARALYZED) hi = 5000; else if(which == eStatus::FORCECAGE) hi = 1000; if(allow_negative.count(which)) lo = -hi; if(which == eStatus::ASLEEP || which == eStatus::DUMB) { // No "wrapping" allowed for these effects. if(status[which] < 0) hi = 0; else if(status[which] > 0) lo = 0; } status[which] = minmax(lo,hi,status[which] + how_much); }
s32 sceKernelWaitThreadEnd(s32 threadId, vm::ptr<s32> pExitStatus, vm::ptr<u32> pTimeout) { sceLibKernel.Warning("sceKernelWaitThreadEnd(threadId=0x%x, pExitStatus=*0x%x, pTimeout=*0x%x)", threadId, pExitStatus, pTimeout); const auto thread = idm::get<ARMv7Thread>(threadId); if (!thread) { return SCE_KERNEL_ERROR_INVALID_UID; } if (pTimeout) { } while (thread->is_alive()) { CHECK_EMU_STATUS; std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack } if (pExitStatus) { *pExitStatus = thread->GPR[0]; } return SCE_OK; }
void toggle_alive(board b, int h, int w) { if(is_alive(b, h, w)) { set_alive(b,h, w, false); } else { set_alive(b,h, w, true); } }
void fiber::priority( int prio) { if ( ! info_) throw fiber_moved(); info_->priority = prio; if ( is_alive() ) info_->st->reschedule( get_id() ); }
bool Actor::fight(Actor & actor) { int damage = base_damage; if (current_weapon != 0) { damage += current_weapon->get_damage(); } int opponent_damage = actor.base_damage; if (actor.current_weapon != 0) { opponent_damage += actor.current_weapon->get_damage(); } std::cout << name() << " initiated a fight with " << actor.name() << " to the death." << std::endl; while (is_alive() || actor.is_alive()) { if (current_weapon != 0) { std::cout << " " << name() << " hits " << actor.name() << " with " << current_weapon->name() << " for " << damage << " health points" << std::endl; } else { std::cout << " " << name() << " hits " << actor.name() << " for " << damage << " health points" << std::endl; } actor.health -= damage; if (!actor.is_alive()) { std::cout << name() << " won this fight, " << actor.name() << " is dead." << std::endl; controller.kill(actor); return true; } if (actor.current_weapon != 0) { std::cout << " " << actor.name() << " hits " << name() << " with " << actor.current_weapon->name() << " for " << opponent_damage << " health points" << std::endl; } else { std::cout << " " << actor.name() << " hits " << name() << " for " << opponent_damage << " health points" << std::endl; } health -= opponent_damage; if (!is_alive()) { std::cout << actor.name() << " won this fight, " << name() << " is dead." << std::endl; controller.kill(*this); return false; } } return false; }
void cCreature::restore_sp(int amt) { if(!is_alive()) return; if(mp >= max_mp) return; mp += amt; if(mp > max_mp) mp = max_mp; if(mp < 0) mp = 0; }
void test_is_alive(void) { init_gol(3,3); // Dead by underpopulation TEST_ASSERT_EQUAL_INT(0, is_alive(1, 1, 1)); // Dead by overcrowding TEST_ASSERT_EQUAL_INT(0, is_alive(1, 1, 4)); // Dead so still dead TEST_ASSERT_EQUAL_INT(0, is_alive(1, 1, 2)); // Alive due born or live TEST_ASSERT_EQUAL_INT(1, is_alive(1, 1, 3)); // Alive so still alive table[1][1] = 1; TEST_ASSERT_EQUAL_INT(1, is_alive(1, 1, 2)); }
static void gc_sweep_phase(pic_state *pic) { struct heap_page *page; int it; khash_t(weak) *h; khash_t(oblist) *s = &pic->oblist; struct symbol *sym; struct object *obj; size_t total = 0, inuse = 0; /* weak maps */ while (pic->heap->weaks != NULL) { h = &pic->heap->weaks->hash; for (it = kh_begin(h); it != kh_end(h); ++it) { if (! kh_exist(h, it)) continue; obj = kh_key(h, it); if (! is_alive(obj)) { kh_del(weak, h, it); } } pic->heap->weaks = pic->heap->weaks->prev; } /* symbol table */ for (it = kh_begin(s); it != kh_end(s); ++it) { if (! kh_exist(s, it)) continue; sym = kh_val(s, it); if (sym && ! is_alive((struct object *)sym)) { kh_del(oblist, s, it); } } page = pic->heap->pages; while (page) { inuse += gc_sweep_page(pic, page); total += PAGE_UNITS; page = page->next; } if (PIC_PAGE_REQUEST_THRESHOLD(total) <= inuse) { heap_morecore(pic); } }
// java_thread is waiting thread being blocked on monitor reenter. // Current thread is the notifying thread which holds the monitor. static bool wait_reenter_begin(JavaThread *java_thread, ObjectMonitor *obj_m) { assert((java_thread != NULL), "Java thread should not be null here"); bool active = false; if (is_alive(java_thread) && ServiceUtil::visible_oop((oop)obj_m->object())) { active = contended_enter_begin(java_thread); } return active; }
void arena::close_arena () { #if !__TBB_STATISTICS_EARLY_DUMP GATHER_STATISTIC( dump_arena_statistics() ); #endif my_market->detach_arena( *this ); __TBB_ASSERT( is_alive(my_guard), NULL ); free_arena(); }
double Bug::DecreaseEnergy(double amount) { amount = GameObject::DecreaseEnergy(amount); if (!is_alive()) StopEating(); return amount; }
void job_teardown() { // 20 tries will give processes about 1 sec to exit cleanly uint32_t remaining_tries = 20; bool all_dead = true; int i; Job *job; // Politely ask each job to terminate for (i = 0; i < MAX_RUNNING_JOBS; i++) { if ((job = table[i]) != NULL) { all_dead = false; uv_process_kill(&job->proc, SIGTERM); } } if (all_dead) { return; } os_delay(10, 0); // Right now any exited process are zombies waiting for us to acknowledge // their status with `wait` or handling SIGCHLD. libuv does that // automatically (and then calls `exit_cb`) but we have to give it a chance // by running the loop one more time uv_run(uv_default_loop(), UV_RUN_NOWAIT); // Prepare to start shooting for (i = 0; i < MAX_RUNNING_JOBS; i++) { if ((job = table[i]) == NULL) { continue; } // Still alive while (is_alive(job) && remaining_tries--) { os_delay(50, 0); // Acknowledge child exits uv_run(uv_default_loop(), UV_RUN_NOWAIT); } if (is_alive(job)) { uv_process_kill(&job->proc, SIGKILL); } } }
void cCreature::heal(int amt) { if(!is_alive()) return; if(health >= m_health) return; health += amt; if(health > m_health) health = m_health; if(health < 0) health = 0; }
thread_base_t::~thread_base_t() { ASSERT(!is_alive()); if (m_private) { delete m_private; m_private = NULL; } }
/*-------------------------------------------------- * Start the thread *-------------------------------------------------*/ PMThread& PMThread::start() { if( !is_alive()) run_id = _beginthread( (void(*_Optlink)(void*))launch, NULL, 64*1024, this ); if( run_id == -1 ) PM_THROW_CLBERROR(); return *this; }
static uint8_t living_neighbors(uint8_t x, uint8_t y) { uint8_t neighbors = 0; if(y > 0) { //above //middle if(is_alive(x,y-1)) { neighbors ++; } //left if(x > 0) { if(is_alive(x-1,y-1)) { neighbors ++; } } //right if(x < SIZE_X-1) { if(is_alive(x+1,y-1)) { neighbors ++; } } } if(y < SIZE_Y-1) { //beneath //middle if(is_alive(x,y+1)) { neighbors ++; } //left if(x > 0) { if(is_alive(x-1,y+1)) { neighbors ++; } } //right if(x < SIZE_X-1) { if(is_alive(x+1,y+1)) { neighbors ++; } } } //left if(x > 0) { if(is_alive(x-1,y)) { neighbors ++; } } //right if(x < SIZE_X-1) { if(is_alive(x+1,y)) { neighbors ++; } } return neighbors; }
bool ThreadImpl::wait_for_thread_end(const ThreadStruct &ts, int32_t time_out) { if(is_alive(ts) == false) { return true; } imp_sleep(time_out); return false; }
bool alive_at(board b, int x, int y) { if(x >= b->width) x = 0; if(x < 0) x = b->width-1; if(y >= b->height) y = 0; if(y < 0) y = b->height-1; return is_alive(b, y, x); }
JavaThreadSleepState(JavaThread *java_thread) : JavaThreadStatusChanger(java_thread, java_lang_Thread::SLEEPING) { if (is_alive()) { _stat = java_thread->get_thread_stat(); _active = ThreadService::is_thread_monitoring_contention(); _stat->thread_sleep(); if (_active) { _stat->thread_sleep_begin(); } } else { _active = false; } }
JavaThreadBlockedOnMonitorEnterState(JavaThread *java_thread, ObjectMonitor *obj_m) : JavaThreadStatusChanger(java_thread) { assert((java_thread != NULL), "Java thread should not be null here"); // Change thread status and collect contended enter stats for monitor contended // enter done for external java world objects and it is contended. All other cases // like for vm internal objects and for external objects which are not contended // thread status is not changed and contended enter stat is not collected. _active = false; if (is_alive() && ServiceUtil::visible_oop((oop)obj_m->object()) && obj_m->contentions() > 0) { _stat = java_thread->get_thread_stat(); _active = contended_enter_begin(java_thread); } }
JavaThreadParkedState(JavaThread *java_thread, bool timed) : JavaThreadStatusChanger(java_thread, timed ? java_lang_Thread::PARKED_TIMED : java_lang_Thread::PARKED) { if (is_alive()) { _stat = java_thread->get_thread_stat(); _active = ThreadService::is_thread_monitoring_contention(); _stat->monitor_wait(); if (_active) { _stat->monitor_wait_begin(); } } else { _active = false; } }
JavaThreadInObjectWaitState(JavaThread *java_thread, bool timed) : JavaThreadStatusChanger(java_thread, timed ? java_lang_Thread::IN_OBJECT_WAIT_TIMED : java_lang_Thread::IN_OBJECT_WAIT) { if (is_alive()) { _stat = java_thread->get_thread_stat(); _active = ThreadService::is_thread_monitoring_contention(); _stat->monitor_wait(); if (_active) { _stat->monitor_wait_begin(); } } else { _active = false; } }