void ResponseCurve::setType(ResponseCurveType type) { typedef void (*ResponseCurveCalculator)(ResponseContainer&); typedef map<ResponseCurveType, ResponseCurveCalculator> ResponseCurveFunc; static ResponseCurveFunc funcs = map_list_of (RESPONSE_LOG10, &fillResponseLog10) (RESPONSE_LINEAR, &fillResponseLinear) (RESPONSE_GAMMA, &fillResponseGamma) (RESPONSE_SRGB, &fillResponseSRGB) ; ResponseCurveType type_ = RESPONSE_LINEAR; ResponseCurveCalculator func_ = &fillResponseLinear; ResponseCurveFunc::const_iterator it = funcs.find(type); if (it != funcs.end()) { type_ = it->first; func_ = it->second; } m_type = type_; func_(m_responses[RESPONSE_CHANNEL_RED]); func_(m_responses[RESPONSE_CHANNEL_GREEN]); func_(m_responses[RESPONSE_CHANNEL_BLUE]); }
void DispatchableFunction::run() { if(func_) { func_(); } }
inline void at_tick(int tick_, FUNC&& func_) { { // limit the scope of the lock to not include // the notify_all() call below; otherwise the // notified threads would still be blocked by // the locked mutex and go for a nap again // wait until the scheduled tick std::unique_lock<std::mutex> lock(m_mutex); m_wakeup.wait(lock, [&]() { return (m_tick >= tick_); }); // verify that the tick value is correct (e.g., no // two actions have been registered for the same tick) CUTE_ASSERT(m_tick == tick_, CUTE_CAPTURE("at_tick(): several actions registered for the same tick")); // update the current tick ++m_tick; // perform the action func_(); } // wakeup other waiting threads again to let them check // if they are due based on their scheduled tick m_wakeup.notify_all(); }
void zmq::trie_t::apply_helper ( unsigned char **buff_, size_t buffsize_, size_t maxbuffsize_, void (*func_) (unsigned char *data_, size_t size_, void *arg_), void *arg_) { // If this node is a subscription, apply the function. if (refcnt) func_ (*buff_, buffsize_, arg_); // Adjust the buffer. if (buffsize_ >= maxbuffsize_) { maxbuffsize_ = buffsize_ + 256; *buff_ = (unsigned char*) realloc (*buff_, maxbuffsize_); zmq_assert (*buff_); } // If there are no subnodes in the trie, return. if (count == 0) return; // If there's one subnode (optimisation). if (count == 1) { (*buff_) [buffsize_] = min; buffsize_++; next.node->apply_helper (buff_, buffsize_, maxbuffsize_, func_, arg_); return; } // If there are multiple subnodes. for (unsigned short c = 0; c != count; c++) { (*buff_) [buffsize_] = min + c; if (next.table [c]) next.table [c]->apply_helper (buff_, buffsize_ + 1, maxbuffsize_, func_, arg_); } }
void FunctionTestCase::__run() { //start... LOG("[ RUN ] %s.%s", name(), method()); //run test... StopWatch stopwatch; stopwatch.start(); TestContext &ctx = TestContext::getInstance(); ctx.setTest(name(), method()); func_(); stopwatch.stop(); int ms = stopwatch.getTimeMillisecond(); //end... if(ctx.isTestSuccess()) { LOG("[ OK ] %s.%s (%d ms)", name(), method(), ms); passCount_ = 1; failCount_ = 0; } else { LOG("[ FAILED ] %s.%s (%d ms)", name(), method(), ms); passCount_ = 0; failCount_ = 1; } }
inline void blocks_until_tick(int tick_, FUNC&& func_) { // perform the action and check afterwards that // the action didn't return too early func_(); CUTE_ASSERT(m_tick >= tick_, CUTE_CAPTURE("blocks_until_tick(): function returned too early")); }
/// /// 実行 void invoke() override{ const T* cp = reinterpret_cast<const T*>(target()); T3_NULL_ASSERT(cp); T* p = const_cast<T*>(cp); Arg1* arg = reinterpret_cast<Arg1*>(arg1()); func_(*p, *arg); }
bool GenericTrigger::Get() { if (func_) return func_(); return false; }
/** * Fullfill the "promise-like" callback wrapper. * Will either call func_ or set a flag, that * then calls the function immediately. */ void fullfill() { fullfilled_.store(true); if (func_) func_(); }
typename Element::TYPE FUNC3_<T>::eval(const Element& element, const int (&iterator)[iterLength]) const { typename Element::TYPE ** map = element.getMappingValues(iterator[iterLength-1]); return func_( map[dirX][fn], map[dirY][fn], map[dirZ][fn]); }
/// /// 実行 void invoke() override{ // 何かわからないインスタンスのポインタを強制的に指定の型とみなす const T* cp = reinterpret_cast<const T*>(target()); T3_NULL_ASSERT(cp); T* p = const_cast<T*>(cp); // 実行! func_(*p); }
Rect ShinonomeFont::GetSize(std::u32string const& txt) const { size_t units = 0; for (char32_t c : txt) { ShinonomeGlyph const* const glyph = func_(c); assert(glyph); units += glyph->is_full? 2 : 1; } return Rect(0, 0, units * HALF_WIDTH, HEIGHT); }
T& value() { if (!resolved_) { value_ = func_(); resolved_ = true; } return value_; }
static void* call (MessageCallbackFunction* func_, void* parameter_) { if (MessageManager::getInstance()->isThisTheMessageThread()) return func_ (parameter_); AsyncFunctionCaller caller (func_, parameter_); caller.triggerAsyncUpdate(); caller.finished.wait(); return caller.result; }
void UdpSearcher::timeoutHandle(const boost::system::error_code& err) { if(!err){ socket_.close(); if(func_) { IpAndNameStruct ipname; ipname.status = IpAndNameStruct::Timeout; func_(ipname); } } }
NATIVEMETHOD(jlong, NativeLongFuncL0, nativeApply)( JNIEnv* env, jobject thisJ, jlong st ) { auto f = to_NativeFunc(env, thisJ); assert(f); auto status = reinterpret_cast<NativeStatus*>(st); return f->func_(status); }
int ring_mem_buffer::consume_all_data() { int ret = 0; try{ unsigned int r_pos = r_pos_.load(memory_order_acquire); unsigned int w_pos = w_pos_.load( memory_order_acquire); if (r_pos < w_pos) { ret = func_(buff_+r_pos, w_pos-r_pos); }else if (r_pos > w_pos) { ret = func_(buff_+r_pos, size_ - r_pos); if (ret == 0 && w_pos != 0) { ret = func_(buff_, w_pos); } } r_pos_.store(w_pos, memory_order_release); }catch(...){ } return ret; }
void Coroutine::start() throw() { // This function runs the coroutine from the given entry point. try { func_(); exit(); // Fell off the end of the coroutine function } catch(ExitException const&) { exit(); // Coroutine was deallocated before exiting } catch(...) { assert(!"error: coroutine killed by exception"); } assert(!"error: unreachable"); }
Rect ShinonomeFont::GetSize(std::string const& txt) const { typedef boost::u8_to_u32_iterator<std::string::const_iterator> iterator; size_t units = 0; iterator i(txt.begin(), txt.begin(), txt.end()); iterator const end(txt.end(), txt.begin(), txt.end()); for(; i != end; ++i) { ShinonomeGlyph const* const glyph = func_(*i); assert(glyph); units += glyph->is_full? 2 : 1; } return Rect(0, 0, units * HALF_WIDTH, HEIGHT); }
void operator()()const { boost::asynchronous::continuation_result<Return> task_res = this->this_task_result(); try { task_res.set_value(std::move(func_())); } catch(std::exception& e) { task_res.set_exception(boost::copy_exception(e)); } }
void ShinonomeFont::Render(Bitmap& bmp, int x, int y, Color const& color, unsigned code) { ShinonomeGlyph const* const glyph = func_(code); assert(glyph); size_t const width = glyph->is_full? FULL_WIDTH : HALF_WIDTH; for(size_t y_ = 0; y_ < HEIGHT; ++y_) { for(size_t x_ = 0; x_ < width; ++x_) { if(glyph->data[y] & (0x1 << x_)) { bmp.SetPixel(x + x_, y + y_, color); } } } }
void operator()() { boost::asynchronous::continuation_result<bool> task_res = this_task_result(); try { // advance up to cutoff Iterator it = boost::asynchronous::detail::find_cutoff(beg_,cutoff_,end_); if (it == end_) { task_res.set_value(std::is_sorted(beg_,end_,func_)); } else { // optimize for not sorted range auto it2 = it; std::advance(it2,-1); // TODO safe_advance must handle negative distance if (func_(*it,*it2)) { task_res.set_value(false); return; } boost::asynchronous::create_callback_continuation_job<Job>( // called when subtasks are done, set our result [task_res](std::tuple<boost::asynchronous::expected<bool>,boost::asynchronous::expected<bool> > res) mutable { try { // get to check that no exception bool res1 = std::get<0>(res).get(); bool res2 = std::get<1>(res).get(); task_res.set_value(res1 && res2); } catch(...) { task_res.set_exception(std::current_exception()); } }, // recursive tasks parallel_is_sorted_helper<Iterator,Func,Job> (beg_,it,func_,cutoff_,this->get_name(),prio_), parallel_is_sorted_helper<Iterator,Func,Job> (it,end_,func_,cutoff_,this->get_name(),prio_) ); } } catch(...) { task_res.set_exception(std::current_exception()); } }
BitmapRef ShinonomeFont::Glyph(char32_t code) { ShinonomeGlyph const* const glyph = func_(code); assert(glyph); size_t const width = glyph->is_full? FULL_WIDTH : HALF_WIDTH; BitmapRef bm = Bitmap::Create(nullptr, width, HEIGHT, 0, DynamicFormat(8,8,0,8,0,8,0,8,0,PF::Alpha)); uint8_t* data = reinterpret_cast<uint8_t*>(bm->pixels()); int pitch = bm->pitch(); for(size_t y_ = 0; y_ < HEIGHT; ++y_) for(size_t x_ = 0; x_ < width; ++x_) data[y_*pitch+x_] = (glyph->data[y_] & (0x1 << x_)) ? 255 : 0; return bm; }
void Tag::Read() { if (attrs_ == nullptr) attrs_ = new ods::Attrs(); func_(ns_, this); auto &xml = ns_.xml(); attrs_->Load(xml); auto token = QXmlStreamReader::NoToken; ods::Tag *append_tag; QVector<ods::Tag*> subtags; foreach (auto *func, subfuncs_) subtags.append(func(ns_, nullptr)); while (token != QXmlStreamReader::EndElement || !ns_.At(attr_)) { token = xml.readNext(); if (token == QXmlStreamReader::Characters) { const QString text = xml.text().toString(); SubnodeAdd(new ods::Node(text)); continue; } if (token != QXmlStreamReader::StartElement) continue; foreach (auto *tag, subtags) { if (!ns_.At(tag)) continue; if (tag->used()) { append_tag = tag->New(); } else { append_tag = tag; tag->used_set(true); } SubnodeAdd(new ods::Node(append_tag)); append_tag->Read(); break; } } foreach (auto *tag, subtags) { if (!tag->used()) delete tag; } }
std::vector<double> SOElement::getc(std::size_t ielem) const { auto const xl = coords_[lnods_[ielem][1]] - coords_[lnods_[ielem][0]]; std::vector<double> c(ntnoel_); c[0] = gl_.qgauss( myfunctional::make_functional( [this, ielem](double r) { return - N1_(r) * func_(N1_(r) * coords_[lnods_[ielem][0]] + N2_(r) * coords_[lnods_[ielem][1]] + N3_(r) * coords_[lnods_[ielem][2]]); }), -1.0, 1.0) * xl * 0.5; c[1] = gl_.qgauss( myfunctional::make_functional([this, ielem](double r) { return - N2_(r) * func_(N1_(r) * coords_[lnods_[ielem][0]] + N2_(r) * coords_[lnods_[ielem][1]] + N3_(r) * coords_[lnods_[ielem][2]]); }), -1.0, 1.0) * xl * 0.5; c[2] = gl_.qgauss( myfunctional::make_functional([this, ielem](double r) { return - N3_(r) * func_(N1_(r) * coords_[lnods_[ielem][0]] + N2_(r) * coords_[lnods_[ielem][1]] + N3_(r) * coords_[lnods_[ielem][2]]); }), -1.0, 1.0) * xl * 0.5; return c; }
NATIVEMETHOD(jlong, NativeLongFuncL5, nativeApply)( JNIEnv* env, jobject thisJ, jlong st, jlong a0, jlong a1, jlong a2, jlong a3, jlong a4 ) { auto f = to_NativeFunc(env, thisJ); assert(f); auto status = reinterpret_cast<NativeStatus*>(st); return f->func_(status, a0, a1, a2, a3, a4); }
void Thread::startFunc() { assert(!func_.empty()); tid_ = gettid(); try { func_(); } catch (...) { /*FIXME:log */ ::abort(); //.... } }
OOP Method::run(State& S, Arguments& args) { if(arity_ > 0 && args.count() != arity_) { return OOP::make_unwind( Exception::create(S, "ArgumentError", "Expected %d, got %d", arity_, args.count())); } if(func_) { HandleScope scope(S); return *func_(S, args.self(), args); } else if(code_) { return S.vm().run(S, this, args); } return OOP::nil(); }
void Fiber::fiberFunc() { #ifdef FOLLY_SANITIZE_ADDRESS fiberManager_.registerFinishSwitchStackWithAsan( nullptr, &asanMainStackBase_, &asanMainStackSize_); #endif while (true) { DCHECK_EQ(state_, NOT_STARTED); threadId_ = localThreadId(); state_ = RUNNING; try { if (resultFunc_) { DCHECK(finallyFunc_); DCHECK(!func_); resultFunc_(); } else { DCHECK(func_); func_(); } } catch (...) { fiberManager_.exceptionCallback_( std::current_exception(), "running Fiber func_/resultFunc_"); } if (UNLIKELY(recordStackUsed_)) { fiberManager_.stackHighWatermark_ = std::max( fiberManager_.stackHighWatermark_, nonMagicInBytes(fcontext_)); VLOG(3) << "Max stack usage: " << fiberManager_.stackHighWatermark_; CHECK( fiberManager_.stackHighWatermark_ < fiberManager_.options_.stackSize - 64) << "Fiber stack overflow"; } state_ = INVALID; auto context = fiberManager_.deactivateFiber(this); DCHECK_EQ(reinterpret_cast<Fiber*>(context), this); } }
void zmq::mtrie_t::match (unsigned char *data_, size_t size_, void (*func_) (pipe_t *pipe_, void *arg_), void *arg_) { mtrie_t *current = this; while (true) { // Signal the pipes attached to this node. if (current->pipes) { for (pipes_t::iterator it = current->pipes->begin (); it != current->pipes->end (); ++it) func_ (*it, arg_); } // If we are at the end of the message, there's nothing more to match. if (!size_) break; // If there are no subnodes in the trie, return. if (current->count == 0) break; // If there's one subnode (optimisation). if (current->count == 1) { if (data_[0] != current->min) break; current = current->next.node; data_++; size_--; continue; } // If there are multiple subnodes. if (data_[0] < current->min || data_[0] >= current->min + current->count) break; if (!current->next.table[data_[0] - current->min]) break; current = current->next.table[data_[0] - current->min]; data_++; size_--; } }