@@ -745,18 +745,45 @@ inline void IsolateData::set_options(
745745 options_ = std::move (options);
746746}
747747
748- template <typename Fn>
749- void Environment::CreateImmediate (Fn&& cb, bool ref) {
750- auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>(
751- std::move (cb), ref);
752- NativeImmediateCallback* prev_tail = native_immediate_callbacks_tail_;
748+ std::unique_ptr<Environment::NativeImmediateCallback>
749+ Environment::NativeImmediateQueue::Shift () {
750+ std::unique_ptr<Environment::NativeImmediateCallback> ret = std::move (head_);
751+ if (ret) {
752+ head_ = ret->get_next ();
753+ if (!head_)
754+ tail_ = nullptr ; // The queue is now empty.
755+ }
756+ return ret;
757+ }
758+
759+ void Environment::NativeImmediateQueue::Push (
760+ std::unique_ptr<Environment::NativeImmediateCallback> cb) {
761+ NativeImmediateCallback* prev_tail = tail_;
753762
754- native_immediate_callbacks_tail_ = callback .get ();
763+ tail_ = cb .get ();
755764 if (prev_tail != nullptr )
756- prev_tail->set_next (std::move (callback ));
765+ prev_tail->set_next (std::move (cb ));
757766 else
758- native_immediate_callbacks_head_ = std::move (callback);
767+ head_ = std::move (cb);
768+ }
769+
770+ void Environment::NativeImmediateQueue::ConcatMove (
771+ NativeImmediateQueue&& other) {
772+ size_ += other.size_ ;
773+ if (tail_ != nullptr )
774+ tail_->set_next (std::move (other.head_ ));
775+ else
776+ head_ = std::move (other.head_ );
777+ tail_ = other.tail_ ;
778+ other.tail_ = nullptr ;
779+ other.size_ = 0 ;
780+ }
759781
782+ template <typename Fn>
783+ void Environment::CreateImmediate (Fn&& cb, bool ref) {
784+ auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>(
785+ std::move (cb), ref);
786+ native_immediates_.Push (std::move (callback));
760787 immediate_info ()->count_inc (1 );
761788}
762789
0 commit comments