template class EE::Scene::MainThreadLifetime

Gates main-thread callbacks with the lifetime of a non-owning object.

The dispatcher and the guarded object must belong to the main thread. The dispatcher may be the guarded object itself, but it must otherwise outlive it. Worker threads may safely copy a WeakHandle and call run(); callbacks queued before invalidation become no-ops once the object is destroyed.

#include <mainthreadlifetime.hpp>

template <typename T>
class MainThreadLifetime {
public:
    // structs

    struct State;

    // classes

    class WeakHandle;

    // construction

    MainThreadLifetime(T* object, Node* dispatcher);
    MainThreadLifetime(const MainThreadLifetime&);
    ~MainThreadLifetime();

    // methods

    MainThreadLifetime& operator=(const MainThreadLifetime&);
    WeakHandle weakHandle() const;
    void setDispatcher(Node* dispatcher);
    void invalidate();
};