Class ThreadLocalStorage

Synopsis

#include <src/uvw/thread.h>

class ThreadLocalStorage final: public UnderlyingType<ThreadLocalStorage, uv_key_t>

Description

The ThreadLocalStorage wrapper.

A storage area that can only be accessed by one thread. The variable can be seen as a global variable that is only visible to a particular thread and not the whole program.

Inheritance

Ancestors: UnderlyingType

Methods

ThreadLocalStorage
~ThreadLocalStorage
getGets the value of a given variable.
setSets the value of a given variable.

Source

Lines 117-142 in src/uvw/thread.h.

class ThreadLocalStorage final: public UnderlyingType<ThreadLocalStorage, uv_key_t> {
public:
    explicit ThreadLocalStorage(ConstructorAccess ca, std::shared_ptr<Loop> ref) noexcept;

    ~ThreadLocalStorage() noexcept;

    /**
     * @brief Gets the value of a given variable.
     * @tparam T Type to which to cast the opaque storage area.
     * @return A pointer to the given variable.
     */
    template<typename T>
    T* get() noexcept {
        return static_cast<T*>(uv_key_get(UnderlyingType::get()));
    }

    /**
     * @brief Sets the value of a given variable.
     * @tparam T Type of the variable to store aside.
     * @param value A valid pointer to the variable to store
     */
    template<typename T>
    void set(T *value) noexcept {
        return uv_key_set(UnderlyingType::get(), value);
    }
};





Add Discussion as Guest

Log in