int Locator_Repository::link_peers (Server_Info_Ptr base, const CORBA::StringSeq p) { sync_load (); CORBA::ULong len = base->peers.length(); base->peers.length (len + p.length()); for (CORBA::ULong i = 0; i < p.length(); i++) { base->peers[len + i] = p[i]; Server_Info *si; ACE_CString peer(p[i]); ACE_NEW_RETURN (si, Server_Info (base->server_id, peer, base->is_jacorb, base), -1); Server_Info_Ptr sip(si); servers ().bind (si->key_name_, sip); this->persistent_update (sip, true); } this->persistent_update (base, true); return 0; }
void _bitmap_bounds_check(bitmap_t *b, uint32_t page, uint32_t word) { assert(word < _bitmap_num_words); // check if the page has been allocated or not for (;;) { _bitmap_page_t p = sync_load(&b[page].page, SYNC_ACQUIRE); if (!p) { void *newp = NULL; int e = posix_memalign((void**)&newp, HPX_CACHELINE_SIZE, _bitmap_num_words * sizeof(_bitmap_word_t)); if (e) { dbg_error("failed to allocate a page for %u words\n", _bitmap_num_words); } memset(newp, 0, _bitmap_num_words * sizeof(_bitmap_word_t)); if (!sync_cas(&b[page].page, &p, newp, SYNC_RELEASE, SYNC_RELAXED)) { free(newp); // try again.. continue; } else { // move on to the previous page page--; continue; } } break; } }
int Locator_Repository::remove_activator (const ACE_CString& name) { int err = sync_load (); if (err != 0) { return err; } int ret = activators().unbind (lcase(name)); if (ret != 0) { return ret; } Locator_Repository::SIMap::ENTRY* sientry = 0; Locator_Repository::SIMap::ITERATOR siit (servers ()); for (; siit.next (sientry); siit.advance() ) { Server_Info *info = sientry->int_id_->active_info (); if (info->death_notify && info->activator == name) { info->death_notify = false; } } return persistent_remove(name, true); }
Server_Info_Ptr Locator_Repository::get_active_server (const ACE_CString& name, int pid) { sync_load (); ACE_CString key; Server_Info_Ptr si; if (name.length() == 0) { return si; } Server_Info::fqname_to_key (name.c_str(), key); servers ().find (key, si); if (si.null()) { if (this->opts_.debug() > 5) { ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) get_active_server could not find %C\n"), name.c_str())); } si = find_by_poa (key); if (si.null()) { if (name.find ("JACORB:") == ACE_CString::npos) { ACE_CString jo_key ("JACORB:"); ACE_CString::size_type pos = name.find (':'); if (pos == ACE_CString::npos) { jo_key += name; } else { jo_key += name.substring (0, pos); jo_key += '/'; jo_key += name.substring (pos+1); } return this->get_active_server (jo_key, pid); } else { return si; } } } if (pid != 0 && si->pid != 0 && si->pid != pid) { if (this->opts_.debug() > 5) { ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) get_active_server could not") ACE_TEXT (" find %C, %d != %d\n"), name.c_str(), pid, si->pid)); } si.reset (); } return si; }
Activator_Info_Ptr Locator_Repository::get_activator (const ACE_CString& name) { sync_load (); Activator_Info_Ptr activator (0); activators ().find (lcase (name), activator); return activator; }
Server_Info_Ptr Locator_Repository::get_info (const ACE_CString& name) { sync_load (); Server_Info_Ptr si; servers ().find (name, si); return si; }
void cr_bitmap_delete(bitmap_t *b) { // delete all pages for (int i = 0; i < _bitmap_num_pages; ++i) { _bitmap_page_t p = sync_load(&b[i].page, SYNC_ACQUIRE); if (p) { free((void*)p); } } free(b); }
// set a bit at index i and then test if the bit at the 0th // position (page 0 word 0) is set uint64_t cr_bitmap_add_and_test(bitmap_t *b, int64_t i) { if (!i) { return 0; } uint32_t page = (i-1)/_bitmap_num_pages; uint32_t pg_offset = (i-1)%_bitmap_page_size; uint32_t word = pg_offset/_bitmap_word_size; int word_offset = (_bitmap_word_size-1) - (pg_offset%_bitmap_word_size); _bitmap_add_at(b, page, word, word_offset); return (uint64_t)sync_load(&b[0].page[0], SYNC_ACQUIRE); }
static int _test_action_handler(void) { char local; // Everyone joins the barrier once. if (sync_barrier_join(barrier, HPX_THREAD_ID)) { // I win the race. printf("thread %d running action on stack %p\n", HPX_THREAD_ID, &local); // This will push the task onto my queue, then I have to induce myself to // transfer to it---everyone else is blocked, so all I have to do is call // yield, which should do the transfer on the same stack, and make this // thread available to whoever wakes up. // // Note that the _test_task task actually releases the lock here, this // prevents anyone from stealing the parent thread (or getting it from the // yield queue) until I have already transferred to the child. // // We send our continuation along so that the test doesn't terminate early. hpx_addr_t and = hpx_thread_current_cont_target(); int e = hpx_call(HPX_HERE, _test_task, and); assert(e == HPX_SUCCESS); hpx_thread_yield(); printf("action stolen by %d\n", HPX_THREAD_ID); // Now, this thread should have been "stolen" or taken from the yield queue // or whatnot. We expect that we're running concurrent with, and on the same // stack, as the _test_task. Verify that we're on the same stack. ptrdiff_t d = &local - task_sp; if (0 < d && d < 1000) { // We're on the same stack---for this to be safe, the _test_task MUST have // already run, which implies that the value for n must be 1. int v = sync_load(&n, SYNC_ACQUIRE); printf("stack difference is %td, value is %d\n", d, v); assert(v == 1 && "work-first task test failed\n"); } else { printf("test indeterminate, task spawned with new stack, d=%td\n", d); } printf("work-first task test success\n"); } else { // I lost the race, wait for the entire thing to be set up before // returning and becoming a "stealer". sync_barrier_join(barrier, HPX_THREAD_ID); } printf("finishing %d\n", HPX_THREAD_ID); return HPX_SUCCESS; }
int Locator_Repository::remove_server (const ACE_CString& name) { int err = sync_load (); if (err != 0) { return err; } Server_Info_Ptr si; this->servers().find (name, si); int ret = this->servers().unbind (name); if (ret != 0) { return ret; } if (!si->alt_info_.null ()) { // name is a peer to another an must be removed from other list bool found = false; for (CORBA::ULong i = 0; i < si->alt_info_->peers.length(); i++) { if (!found && si->poa_name == si->alt_info_->peers[i]) { found = true; continue; } if (found) { si->alt_info_->peers[i-1] = si->alt_info_->peers[i]; } } si->alt_info_->peers.length (si->alt_info_->peers.length() - 1); } else if (si->peers.length () > 0) { for (CORBA::ULong i = 0; i < si->peers.length(); i++) { ACE_CString key; ACE_CString peer (si->peers[i]); Server_Info::gen_key (si->server_id, peer, key); this->servers ().unbind (key); this->persistent_remove (key, false); } } return persistent_remove (name, false); }
static int _proc_return_credit_handler(_process_t *p, uint64_t *args, size_t size) { // add credit to the credit-accounting bitmap uint64_t debt = cr_bitmap_add_and_test(p->debt, *args); for (;;) { uint64_t credit = sync_load(&p->credit, SYNC_ACQUIRE); if ((credit != 0) && ~(debt | ((UINT64_C(1) << (64-credit)) - 1)) == 0) { // log("detected quiescence...\n"); if (!sync_cas(&p->credit, &credit, -credit, SYNC_RELEASE, SYNC_RELAXED)) { continue; } dbg_assert(_is_tracked(p)); hpx_lco_set(p->termination, 0, NULL, HPX_NULL, HPX_NULL); } break; } return HPX_SUCCESS; }
int Locator_Repository::add_server_i (Server_Info *si) { Server_Info_Ptr info(si); int err = sync_load (); if (err != 0) { return err; } err = servers ().bind (si->key_name_, info); if (err != 0) { return err; } this->persistent_update(info, true); return 0; }
int Locator_Repository::add_activator (const ACE_CString& name, const CORBA::Long token, const ACE_CString& ior, ImplementationRepository::Activator_ptr act) { int err = sync_load (); if (err != 0) { return err; } Activator_Info_Ptr info (new Activator_Info (name, token, ior, act)); err = activators ().bind (lcase (name), info); if (err != 0) { return err; } this->persistent_update(info, true); return 0; }
int scheduler_is_stopped(struct scheduler *sched) { int stopped = sync_load(&sched->stopped, SYNC_ACQUIRE); return (stopped != SCHED_RUN); }