@@ -732,18 +732,45 @@ inline void IsolateData::set_options(
732732 options_ = std::move (options);
733733}
734734
735- template <typename Fn>
736- void Environment::CreateImmediate (Fn&& cb, bool ref) {
737- auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>(
738- std::move (cb), ref);
739- NativeImmediateCallback* prev_tail = native_immediate_callbacks_tail_;
735+ std::unique_ptr<Environment::NativeImmediateCallback>
736+ Environment::NativeImmediateQueue::Shift () {
737+ std::unique_ptr<Environment::NativeImmediateCallback> ret = std::move (head_);
738+ if (ret) {
739+ head_ = ret->get_next ();
740+ if (!head_)
741+ tail_ = nullptr ; // The queue is now empty.
742+ }
743+ return ret;
744+ }
745+
746+ void Environment::NativeImmediateQueue::Push (
747+ std::unique_ptr<Environment::NativeImmediateCallback> cb) {
748+ NativeImmediateCallback* prev_tail = tail_;
740749
741- native_immediate_callbacks_tail_ = callback .get ();
750+ tail_ = cb .get ();
742751 if (prev_tail != nullptr )
743- prev_tail->set_next (std::move (callback ));
752+ prev_tail->set_next (std::move (cb ));
744753 else
745- native_immediate_callbacks_head_ = std::move (callback);
754+ head_ = std::move (cb);
755+ }
756+
757+ void Environment::NativeImmediateQueue::ConcatMove (
758+ NativeImmediateQueue&& other) {
759+ size_ += other.size_ ;
760+ if (tail_ != nullptr )
761+ tail_->set_next (std::move (other.head_ ));
762+ else
763+ head_ = std::move (other.head_ );
764+ tail_ = other.tail_ ;
765+ other.tail_ = nullptr ;
766+ other.size_ = 0 ;
767+ }
746768
769+ template <typename Fn>
770+ void Environment::CreateImmediate (Fn&& cb, bool ref) {
771+ auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>(
772+ std::move (cb), ref);
773+ native_immediates_.Push (std::move (callback));
747774 immediate_info ()->count_inc (1 );
748775}
749776
0 commit comments