Edit

kc3-lang/angle/src/libANGLE/signal_utils.h

Branch :

  • Show log

    Commit

  • Author : Jamie Madill
    Date : 2016-07-28 16:20:21
    Hash : 00d6796a
    Message : Replace std::set with vector for signal receivers. This should make insertion much faster, which will improve the speed of many BindBuffer calls. BUG=angleproject:1458 Change-Id: I3f7ebc02cc481257be8b84773506b9ac9e3be677 Reviewed-on: https://chromium-review.googlesource.com/364221 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>

  • src/libANGLE/signal_utils.h
  • //
    // Copyright 2016 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    // signal_utils:
    //   Helper classes for tracking dependent state changes between objects.
    //   These changes are signaled to the dependent class via channels.
    
    #ifndef LIBANGLE_SIGNAL_UTILS_H_
    #define LIBANGLE_SIGNAL_UTILS_H_
    
    #include <set>
    
    #include "common/angleutils.h"
    
    namespace angle
    {
    
    // Message token passed to the receiver;
    using SignalToken = uint32_t;
    
    // Interface that the depending class inherits from.
    class SignalReceiver
    {
      public:
        virtual ~SignalReceiver() = default;
        virtual void signal(SignalToken token) = 0;
    };
    
    class ChannelBinding;
    
    // The host class owns the channel. It uses the channel to fire signals to the receiver.
    class BroadcastChannel final : NonCopyable
    {
      public:
        BroadcastChannel();
        ~BroadcastChannel();
    
        void signal() const;
        void reset();
    
      private:
        // Only the ChannelBinding class should add or remove receivers.
        friend class ChannelBinding;
        void addReceiver(ChannelBinding *receiver);
        void removeReceiver(ChannelBinding *receiver);
    
        std::vector<ChannelBinding *> mReceivers;
    };
    
    // The dependent class keeps bindings to the host's BroadcastChannel.
    class ChannelBinding final
    {
      public:
        ChannelBinding(SignalReceiver *receiver, SignalToken token);
        ~ChannelBinding();
        ChannelBinding(const ChannelBinding &other) = default;
        ChannelBinding &operator=(const ChannelBinding &other) = default;
    
        void bind(BroadcastChannel *channel);
        void reset();
        void signal() const;
        void onChannelClosed();
    
      private:
        BroadcastChannel *mChannel;
        SignalReceiver *mReceiver;
        SignalToken mToken;
    };
    
    }  // namespace angle
    
    #endif  // LIBANGLE_SIGNAL_UTILS_H_