void EventLoopThread::runInLoop(const Functor& cb) { { std::unique_lock<std::mutex> ul(mutex_); functors_.push_back(cb); } wakeup(); }
void QgsGrassRegion::displayRegion() { QgsPoint ul( mWindow.west, mWindow.north ); QgsPoint lr( mWindow.east, mWindow.south ); //mRegionEdit->setRegion( ul, lr ); mRegionEdit->setSrcRegion( QgsRectangle( ul, lr ) ); }
std::shared_ptr<TransactionCoordinatorService::CatalogAndScheduler> TransactionCoordinatorService::_getCatalogAndScheduler(OperationContext* opCtx) { stdx::unique_lock<stdx::mutex> ul(_mutex); uassert( ErrorCodes::NotMaster, "Transaction coordinator is not a primary", _catalogAndScheduler); return _catalogAndScheduler; }
_Accum mulkS(_Accum x, _Accum y) { #if BYTE_ORDER == BIG_ENDIAN # define LO 0 # define HI 1 #else # define LO 1 # define HI 0 #endif uint16_t xs[2]; uint16_t ys[2]; uint32_t mul; int8_t positive = ((x < 0 && y < 0) || (y > 0 && x > 0)) ? 1 : 0; *((_Accum*)xs) = absk(x); *((_Accum*)ys) = absk(y); mul = ul(xs[HI]) * ul(ys[HI]); if(mul > 32767) return (positive ? ACCUM_MAX : ACCUM_MIN); mul = LSHIFT_static(mul, ACCUM_FBIT) + ul(xs[HI])*ul(ys[LO]) + ul(xs[LO])*ul(ys[HI]) + RSHIFT_static(ul(xs[LO]*ys[LO]), ACCUM_FBIT); if(mul & 0x80000000) return (positive ? ACCUM_MAX : ACCUM_MIN); return (positive ? (int32_t)mul : -(int32_t)mul); #undef HI #undef LO }
static void an_infinitely_waiting_main_function() { std::mutex m; std::unique_lock<std::mutex> ul(m); std::condition_variable cv; cv.wait(ul); }
std::unique_lock<std::mutex> TaskScheduler::WaitForNewTask(std::chrono::system_clock::time_point const & parWaitUntil) { std::unique_lock<std::mutex> ul(this->_taskListMutex); if (parWaitUntil < std::chrono::time_point<std::chrono::system_clock>::max()) this->_newTask.wait_until(ul, parWaitUntil); else this->_newTask.wait(ul); return ul; }
Color Image::extract_Color(const Point2f &coordinate) const { const Point2f scaled(coordinate.x * m_size.x, coordinate.y * m_size.y); Point2i ul(int(scaled.x), int(scaled.y)); if(m_tileable) { if(ul.x < 0) ul.x = m_size.x - ((-ul.x) % m_size.x); if(ul.x >= m_size.x) ul.x = ul.x % m_size.x; if(ul.y < 0) ul.y = m_size.y - ((-ul.y) % m_size.y); if(ul.y >= m_size.y) ul.y = ul.y % m_size.y; } else { if(ul.x < 0) ul.x = 0; else if(ul.x >= m_size.x) ul.x = m_size.x - 1; if(ul.y < 0) ul.y = 0; else if(ul.y >= m_size.y) ul.y = m_size.y - 1; } Point2i lr(ul.x + 1, ul.y + 1); if(m_tileable) { lr.x = lr.x % m_size.x; lr.y = lr.y % m_size.y; } else { if(lr.x == m_size.x) --lr.x; if(lr.y == m_size.y) --lr.y; } const Color ulc = extract_Color(ul); const Color llc = extract_Color(Point2i(ul.x, lr.y)); const Color lrc = extract_Color(lr); const Color urc = extract_Color(Point2i(lr.x, ul.y)); const float x_rhs_part = scaled.x - float(floor(scaled.x)); const float y_rhs_part = scaled.y - float(floor(scaled.y)); const Color uc = ulc.interpolate_to(x_rhs_part, urc); const Color lc = llc.interpolate_to(x_rhs_part, lrc); return uc.interpolate_to(y_rhs_part, lc); }
obj global(obj rt){ if(!env) error("global assign in global env"); assert(type(rt)==tSymbol); obj gv = search_pair(curr_interp->gl_vars, rt); if(!gv) error("no such global"); list *arg_bind = &(ul(car(env))); *arg_bind = cons(retain(gv), *arg_bind); return nil; }
void set_control_bounds(GG::Wnd* control, const place_data_t& place_data) { if (control) { GG::Pt ul(GG::X(left(place_data)), GG::Y(top(place_data))); control->SizeMove(ul, ul + GG::Pt(GG::X(width(place_data)), GG::Y(height(place_data)))); } }
inline void wait() { std::unique_lock<std::mutex> ul(lock); ++num_waiters; while (count == 0) { count_nonzero.wait(ul); } --num_waiters; --count; }
bool QtUdpSocketPlugin::waitForMessages(uint32_t messageCount, int32_t timeOut) { std::unique_lock<std::mutex> ul(_conditionLock); while (_messageCounter < messageCount) { if (_conditionVariable.wait_for(ul, std::chrono::milliseconds(timeOut)) == std::cv_status::timeout) { break; } } return _messageCounter == messageCount; }
void InGameMenu::DoLayout() { //size calculation consts and variables const GG::X MIN_BUTTON_WIDTH(160); const GG::Y MIN_BUTTON_HEIGHT(40); const GG::X H_BUTTON_MARGIN(16); //horizontal empty space const GG::Y V_BUTTON_MARGIN(16); //vertical empty space GG::X button_width(0); //width of the buttons GG::Y button_height(0); //height of the buttons const GG::X H_MAINMENU_MARGIN(40); //horizontal empty space const GG::Y V_MAINMENU_MARGIN(40); //vertical empty space GG::X mainmenu_width(0); //width of the mainmenu GG::Y mainmenu_height(0); //height of the mainmenu //calculate necessary button width boost::shared_ptr<GG::Font> font = ClientUI::GetFont(); button_width = std::max(button_width, font->TextExtent(m_save_btn->Text()).x); button_width = std::max(button_width, font->TextExtent(m_load_btn->Text()).x); button_width = std::max(button_width, font->TextExtent(m_options_btn->Text()).x); button_width = std::max(button_width, font->TextExtent(m_exit_btn->Text()).x); button_width = std::max(button_width, font->TextExtent(m_done_btn->Text()).x); button_width += H_BUTTON_MARGIN; button_width = std::max(MIN_BUTTON_WIDTH, button_width); //calculate necessary button height button_height = std::max(MIN_BUTTON_HEIGHT, font->Height() + V_BUTTON_MARGIN); //culate window width and height mainmenu_width = button_width + H_MAINMENU_MARGIN; mainmenu_height = 5.75 * button_height + V_MAINMENU_MARGIN; // 8 rows + 0.75 before exit button // place buttons GG::Pt button_ul(GG::X(15), GG::Y(12)); GG::Pt button_lr(button_width, ClientUI::GetFont()->Lineskip() + 6); button_lr += button_ul; m_save_btn->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_height); button_lr.y += GG::Y(button_height); m_load_btn->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_height); button_lr.y += GG::Y(button_height); m_options_btn->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_height); button_lr.y += GG::Y(button_height); m_exit_btn->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_height) * 1.75; button_lr.y += GG::Y(button_height) * 1.75; m_done_btn->SizeMove(button_ul, button_lr); // position menu window GG::Pt ul(GG::GUI::GetGUI()->AppWidth() * 0.5 - mainmenu_width/2, GG::GUI::GetGUI()->AppHeight() * 0.5 - mainmenu_height/2); GG::Pt lr(GG::GUI::GetGUI()->AppWidth() * 0.5 + mainmenu_width/2, GG::GUI::GetGUI()->AppHeight() * 0.5 + mainmenu_height/2); this->SizeMove(ul, lr); }
void test_can_lock_upgrade_to_unique_if_currently_locked_upgrade() { typedef hpx::lcos::local::shared_mutex shared_mutex_type; shared_mutex_type mtx; boost::upgrade_lock<shared_mutex_type> l(mtx); boost::upgrade_to_unique_lock<shared_mutex_type> ul(l); HPX_TEST(ul.owns_lock()); }
void MyCEGUIGeometryBuffer::draw() const { u32 qcnt = m_Quads.size(); if (!qcnt) return; if (!m_ClipRect.isValid()) return; if (!m_MatrixValid) _updateMatrix(); core::vector3df ul(0.0f, 0.0f, 0.0f); core::vector3df lr(0.0f, 0.0f, 0.0f); core::rectf clipped_rect_draw; core::rectf clipped_rect_tc; for (u32 i = 0; i < qcnt; i++) { RenderQuad &quad = m_Quads[i]; ul.X = quad.rect_draw.UpperLeftCorner.X; ul.Y = quad.rect_draw.UpperLeftCorner.Y; lr.X = quad.rect_draw.LowerRightCorner.X; lr.Y = quad.rect_draw.LowerRightCorner.Y; m_Matrix.transformVect(ul); m_Matrix.transformVect(lr); clipped_rect_draw.set(ul.X, ul.Y, lr.X, lr.Y); clipped_rect_draw.clipAgainst(m_ClipRect); if (!clipped_rect_draw.isValid()) continue; f32 rd_w = quad.rect_draw.getWidth(); f32 rd_h = quad.rect_draw.getHeight(); f32 rtc_w = quad.rect_tc.getWidth(); f32 rtc_h = quad.rect_tc.getHeight(); f32 clip_ul_x = (clipped_rect_draw.UpperLeftCorner.X - ul.X) / rd_w; f32 clip_ul_y = (clipped_rect_draw.UpperLeftCorner.Y - ul.Y) / rd_h; f32 clip_lr_x = (clipped_rect_draw.LowerRightCorner.X - lr.X) / rd_w; f32 clip_lr_y = (clipped_rect_draw.LowerRightCorner.Y - lr.Y) / rd_h; clipped_rect_tc.set( quad.rect_tc.UpperLeftCorner.X + clip_ul_x * rtc_w, quad.rect_tc.UpperLeftCorner.Y + clip_ul_y * rtc_h, quad.rect_tc.LowerRightCorner.X + clip_lr_x * rtc_w, quad.rect_tc.LowerRightCorner.Y + clip_lr_y * rtc_h); m_Driver.registerGUIImageForRendering( quad.texture, s_NextZ, clipped_rect_draw, clipped_rect_tc, quad.colors[0], quad.colors[1], quad.colors[2], quad.colors[3], quad.useAlphaBlending); } s_NextZ -= 0.000001f; }
static bool bind_vars(obj* vars, obj lt, obj rt){ obj utype; switch(lt->type){ default: break; case tSymbol: if(macromode){ if(obj rr = search_assoc(car(macro_env), lt)){ //macromode = false; if(vars) add_assoc(vars, rr, rt); //macromode = true; return true; } } if(vars) add_assoc(vars, lt, rt); return true; case tRef: let(&(uref(lt)), rt); return true; case INT: return equal(lt, rt); case tOp: utype = search_assoc(curr_interp->types, ult(lt)); if(utype){ if(vrInt(utype) != rt->type) return false; return bind_vars(vars, urt(lt), uref(rt)); } if(rt->type!=tOp) return false; if(! bind_vars(vars, ult(lt), ult(rt))) return false; return bind_vars(vars, urt(lt), urt(rt)); case LIST: if(rt->type!=LIST) return false; list x=ul(lt), a=ul(rt); for(; (x && a); x=rest(x),a=rest(a)){ if(!bind_vars(vars, first(x), first(a))) return false; } if(x||a) return false; return true; } print(lt); assert(0); return nil; }
// cases 4-7 void test_disjoint_corner() { bool all_pass = false; rect_list_type cliprects; rect_type mainrect(40,40,20,20); rect_type ul(35,55,10,10); rect_type ur(55,55,10,10); rect_type ll(35,35,10,10); rect_type lr(55,35,10,10); // upper left cliprects = disjoint_union(mainrect, ul); rect_type ul_1(35, 55, 5, 5); rect_type ul_2(35, 60, 10, 5); all_pass = (cliprects.size() == 3) && rect_list_contains(cliprects, ul_1) && \ rect_list_contains(cliprects, ul_2) && rect_list_contains(cliprects, mainrect); if (!all_pass) { printf("Error in test_disjoint_corner()i: upper left\n"); } // lower left cliprects = disjoint_union(mainrect, ll); rect_type ll_1(35, 35, 10, 5); rect_type ll_2(35, 40, 5, 5); all_pass = (cliprects.size() == 3) && rect_list_contains(cliprects, ll_1) && \ rect_list_contains(cliprects, ll_2) && rect_list_contains(cliprects, mainrect); if (!all_pass) { printf("Error in test_disjoint_corner()i: upper left\n"); } // upper right cliprects = disjoint_union(mainrect, ur); rect_type ur_1(55, 60, 10, 5); rect_type ur_2(60, 55, 5, 5); all_pass = (cliprects.size() == 3) && rect_list_contains(cliprects, ur_1) && \ rect_list_contains(cliprects, ur_2) && rect_list_contains(cliprects, mainrect); if (!all_pass) { printf("Error in test_disjoint_corner()i: upper right\n"); } // lower right cliprects = disjoint_union(mainrect, lr); rect_type lr_1(55, 35, 10, 5); rect_type lr_2(60, 40, 5, 5); all_pass = (cliprects.size() == 3) && rect_list_contains(cliprects, lr_1) && \ rect_list_contains(cliprects, lr_2) && rect_list_contains(cliprects, mainrect); if (!all_pass) { printf("Error in test_disjoint_corner()i: lower right\n"); } }
void output(std::uint32_t locality_id, std::uint64_t count, detail::buffer const& buf_in, F const& write_f, Mutex& mtx) { detail::buffer in(buf_in); std::unique_lock<Mutex> l(mtx); data_type& data = output_data_map_[locality_id]; //-V108 if (count == data.first) { // this is the next expected output line if (!in.empty()) { // output the line as requested util::unlock_guard<std::unique_lock<Mutex> > ul(l); in.write(write_f, mtx); } ++data.first; // print all consecutive pending buffers output_data_type::iterator next = data.second.find(++count); while (next != data.second.end()) { buffer next_in = (*next).second; if (!next_in.empty()) { // output the next line util::unlock_guard<std::unique_lock<Mutex> > ul(l); next_in.write(write_f, mtx); } data.second.erase(next); // find next entry in map ++data.first; next = data.second.find(++count); } } else { HPX_ASSERT(count > data.first); data.second.insert(output_data_type::value_type(count, in)); } }
int ElastomericBearingPlasticity2d::getResponse(int responseID, Information &eleInfo) { double kGeo1, MpDelta1, MpDelta2, MpDelta3; switch (responseID) { case 1: // global forces return eleInfo.setVector(this->getResistingForce()); case 2: // local forces theVector.Zero(); // determine resisting forces in local system theVector.addMatrixTransposeVector(0.0, Tlb, qb, 1.0); // add P-Delta moments kGeo1 = 0.5*qb(0); MpDelta1 = kGeo1*(ul(4)-ul(1)); theVector(2) += MpDelta1; theVector(5) += MpDelta1; MpDelta2 = kGeo1*shearDistI*L*ul(2); theVector(2) += MpDelta2; theVector(5) -= MpDelta2; MpDelta3 = kGeo1*(1.0 - shearDistI)*L*ul(5); theVector(2) -= MpDelta3; theVector(5) += MpDelta3; return eleInfo.setVector(theVector); case 3: // basic forces return eleInfo.setVector(qb); case 4: // local displacements return eleInfo.setVector(ul); case 5: // basic displacements return eleInfo.setVector(ub); case 6: // basic stiffness return eleInfo.setDouble(kb(1,1)); default: return -1; } }
void KinectInterfacePrimesense::convertRGBToDepth(const uint32_t start, const uint32_t end) { if (!sync_ir_stream_) { const uint16_t* d = depth(); OniStreamHandle dhandle = streams_[DEPTH_STREAM]->_getHandle(); OniStreamHandle chandle = streams_[RGB_STREAM]->_getHandle(); int rgb_u; int rgb_v; uint8_t* rgb = (uint8_t*)frames_[RGB_STREAM]->getData(); for (uint32_t i = start; i <= end; i++) { uint32_t u = i % depth_dim_[0]; uint32_t v = i / depth_dim_[0]; // This is the API version (REALLY slow) //openni::Status rc = openni::CoordinateConverter::convertDepthToColor( // *streams_[DEPTH_STREAM], *streams_[RGB_IR_STREAM], u, v, d[i], &rgb_u, &rgb_v); //if (rc == openni::Status::STATUS_OK) { // int src_index = rgb_v * src_width + rgb_u; // registered_rgb_[i * 3] = rgb[src_index * 3]; // registered_rgb_[i * 3 + 1] = rgb[src_index * 3 + 1]; // registered_rgb_[i * 3 + 2] = rgb[src_index * 3 + 2]; //} else { // registered_rgb_[i * 3] = 0; // registered_rgb_[i * 3 + 1] = 0; // registered_rgb_[i * 3 + 2] = 0; //} // // My version: openni_funcs_->TranslateSinglePixel(u, v, d[i], rgb_u, rgb_v, flip_image_); if (d[i] != 0 && rgb_u < src_width && rgb_v < src_height && rgb_u >= 0 && rgb_v >= 0) { int src_index = rgb_v * src_width + rgb_u; registered_rgb_[i * 3] = rgb[src_index * 3]; registered_rgb_[i * 3 + 1] = rgb[src_index * 3 + 1]; registered_rgb_[i * 3 + 2] = rgb[src_index * 3 + 2]; } else { registered_rgb_[i * 3] = 0; registered_rgb_[i * 3 + 1] = 0; registered_rgb_[i * 3 + 2] = 0; } } } else { for (uint32_t i = start; i <= end; i++) { registered_rgb_[i * 3] = 255; registered_rgb_[i * 3 + 1] = 255; registered_rgb_[i * 3 + 2] = 255; } } std::unique_lock<std::mutex> ul(thread_update_lock_); threads_finished_++; not_finished_.notify_all(); // Signify that all threads might have finished ul.unlock(); }
bool pop(spmsg_t &msg_, bool wait_ = false) { std::unique_lock<std::mutex> ul(lock); if (list.empty() && !wait_) return false; while (list.empty()) { empty.wait(ul); } msg_ = list.front(); list.pop_front(); return true; }
void f() { time_point t0 = Clock::now(); time_point t1; { std::unique_lock<std::mutex> ul(m); t1 = Clock::now(); } ns d = t1 - t0 - ms(250); assert(d < ms(50)); // within 50ms }
void IntroScreen::DoLayout() { m_splash->Resize(this->Size()); m_logo->Resize(GG::Pt(this->Width(), this->Height() / 10)); m_version->MoveTo(GG::Pt(this->Width() - m_version->Width(), this->Height() - m_version->Height())); //size calculation consts and variables const GG::X MIN_BUTTON_WIDTH(160); const GG::Y MIN_BUTTON_HEIGHT(40); const GG::X H_BUTTON_MARGIN(16); //horizontal empty space const GG::Y V_BUTTON_MARGIN(16); //vertical empty space GG::X button_width(0); //width of the buttons GG::Y button_height(0); //height of the buttons const GG::X H_MAINMENU_MARGIN(40); //horizontal empty space const GG::Y V_MAINMENU_MARGIN(40); //vertical empty space GG::X mainmenu_width(0); //width of the mainmenu GG::Y mainmenu_height(0); //height of the mainmenu //calculate necessary button width boost::shared_ptr<GG::Font> font = ClientUI::GetFont(); button_width += H_BUTTON_MARGIN; button_width = std::max(MIN_BUTTON_WIDTH, button_width); //calculate necessary button height button_height = std::max(MIN_BUTTON_HEIGHT, font->Height() + V_BUTTON_MARGIN); //culate window width and height mainmenu_width = button_width + H_MAINMENU_MARGIN; mainmenu_height = 8.75 * button_height + V_MAINMENU_MARGIN; // 8 rows + 0.75 before exit button // position menu window GG::Pt ul(Width() * GetOptionsDB().Get<double>("UI.main-menu.x") - mainmenu_width/2, Height() * GetOptionsDB().Get<double>("UI.main-menu.y") - mainmenu_height/2); GG::Pt lr(Width() * GetOptionsDB().Get<double>("UI.main-menu.x") + mainmenu_width/2, Height() * GetOptionsDB().Get<double>("UI.main-menu.y") + mainmenu_height/2); m_menu->SizeMove(ul, lr); //create buttons GG::Y button_y(12); //relativ buttonlocation GG::X button_x(15); m_single_player->MoveTo(GG::Pt(button_x, button_y)); button_y += button_height; m_quick_start->MoveTo(GG::Pt(button_x, button_y)); button_y += button_height; m_multi_player->MoveTo(GG::Pt(button_x, button_y)); button_y += button_height; m_load_game->MoveTo(GG::Pt(button_x, button_y)); button_y += button_height; m_options->MoveTo(GG::Pt(button_x, button_y)); button_y += button_height; m_about->MoveTo(GG::Pt(button_x, button_y)); button_y += button_height; m_credits->MoveTo(GG::Pt(button_x, button_y)); button_y += 1.75 * button_height; m_exit_game->MoveTo(GG::Pt(button_x, button_y)); }
void g() { time_point t0 = Clock::now(); time_point t1; { std::shared_lock<std::shared_timed_mutex> ul(m); t1 = Clock::now(); } ns d = t1 - t0; assert(d < ms(50)); // within 50ms }
void thread2() { // wait until thread1 is ready (readyFlag is true) { std::unique_lock<std::mutex> ul(readyMutex); readyCondVar.wait(ul, []{ return readyFlag; }); } // release lock // do whatever shall happen after thread1 has prepared things std::cout << "done" << std::endl; }
connection_ptr agent_impl::get_connetion(unsigned id) { std::unique_lock<std::mutex> ul(mutex_conn_); connection_ptr conn; auto iter = conn_map_.find(id); if (iter != conn_map_.end()) { conn = iter->second; } return conn; }
obj exec(obj v){ obj rr=nil; if(type(v)!=LIST && type(v)!=tExec) return eval(v); for(list l = ul(v); l; ){ if(rr) release(rr); rr = eval(fpp(l)); if(rr && type(rr)==tSigRet) break; if(rr && type(rr)==tBreak) break; } return rr; }
inline Matrix<_xDim,_uDim> dfdu(Matrix<_xDim> (*f)(const Matrix<_xDim>&, const Matrix<_uDim>&), const Matrix<_xDim>& x, const Matrix<_uDim>& u) { Matrix<_xDim,_uDim> B; Matrix<_uDim> ur(u), ul(u); for (size_t i = 0; i < _uDim; ++i) { ur[i] += step; ul[i] -= step; B.insert(0,i, (f(x, ur) - f(x, ul)) / (2.0*step)); ur[i] = ul[i] = u[i]; } return B; }
~cv_cancellation_guard() { if (!_registered || RETHREAD_LIKELY(try_unregister(_token, _handler))) return; // We need to unlock mutex before unregistering, because canceller thread // can get stuck at mutex in cv_cancellation_handler::cancel(). // When unregister returns, we are sure that canceller has left cancel(), so it is safe to lock mutex back. reverse_lock<typename Handler::lock_type> ul(_handler.get_lock()); unregister(_token, _handler); }
struct event_base* EventLoopThread::startLoop() { { std::unique_lock<std::mutex> ul(mutex_); while (nullptr == base_) { cond_.wait(ul); } } return base_; }
void operator()() { for(int i=0;i<5;i++) { { booster::unique_lock<MutexType> ul(*mutex_); int tmp = variable; booster::ptime::millisleep(20); variable = tmp + 1; } } }