+ if (!executorLock_.try_lock()) {
+ executorLock_.lock();
+ }
+ x = executor_;
+ priority = priority_;
+ executorLock_.unlock();
+ }
+
+ if (x) {
+ exception_wrapper ew;
+ // We need to reset `callback_` after it was executed (which can happen
+ // through the executor or, if `Executor::add` throws, below). The
+ // executor might discard the function without executing it (now or
+ // later), in which case `callback_` also needs to be reset.
+ // The `Core` has to be kept alive throughout that time, too. Hence we
+ // increment `attached_` and `callbackReferences_` by two, and construct
+ // exactly two `CoreAndCallbackReference` objects, which call
+ // `derefCallback` and `detachOne` in their destructor. One will guard
+ // this scope, the other one will guard the lambda passed to the executor.
+ attached_ += 2;
+ callbackReferences_ += 2;
+ CoreAndCallbackReference guard_local_scope(this);
+ CoreAndCallbackReference guard_lambda(this);