<commit_before>#ifndef __CONCURRENCY_WATCHABLE_HPP__
#define __CONCURRENCY_WATCHABLE_HPP__

#include "concurrency/mutex_assertion.hpp"
#include "concurrency/pubsub.hpp"

template <class value_t>
class watchable_t {
public:
    class freeze_t {
    public:
        explicit freeze_t(const clone_ptr_t<watchable_t> &watchable) 
            : rwi_lock_acquisition(watchable->get_rwi_lock_assertion())
        { }

        void assert_is_holding(const clone_ptr_t<watchable_t> &watchable) {
            rwi_lock_acquisition.assert_is_holding(watchable->get_rwi_lock_assertion());
        }

    private:
        rwi_lock_assertion_t::read_acq_t rwi_lock_acquisition;
    };

    class subscription_t {
    public:
        explicit subscription_t(boost::function<void()> f)
            : subscription(f)
        { }

        subscription_t(boost::function<void()> f, const clone_ptr_t<watchable_t> &watchable, freeze_t *freeze) 
            : subscription(f, watchable->get_publisher(freeze))
        { }

        void reset() {
            subscription.reset();
        }

        void reset(const clone_ptr_t<watchable_t> &watchable, freeze_t *freeze) {
            subscription.reset(watchable->get_publisher(freeze));
        }

    private:
        typename publisher_t<boost::function<void()> >::subscription_t subscription;
    };

    virtual ~watchable_t() { }
    virtual watchable_t *clone() = 0;
    virtual value_t get() = 0;
    virtual publisher_t<boost::function<void()> > *get_publisher(freeze_t *) = 0;
    virtual rwi_lock_assertion_t *get_rwi_lock_assertion() = 0;

protected:
    watchable_t() { }

private:
    DISABLE_COPYING(watchable_t);
};

template <class value_t>
class watchable_variable_t {
public:
    explicit watchable_variable_t(const value_t &_value)
        : value(_value), watchable(this)
    { }

    clone_ptr_t<watchable_t<value_t> > get_watchable() {
        return clone_ptr_t<watchable_t<value_t> >(watchable.clone());
    }

    void set_value(const value_t &_value) {
        rwi_lock_assertion_t::write_acq_t acquisition(&rwi_lock_assertion);
        value = _value;
        publisher_controller.publish(&watchable_variable_t<value_t>::call);
    }

private:
    class w_t : public watchable_t<value_t> {
    public:
        w_t(watchable_variable_t<value_t> *p) : parent(p) { }
        w_t *clone() {<commit_msg>Made w_t constructor explicit.<commit_after>#ifndef __CONCURRENCY_WATCHABLE_HPP__
#define __CONCURRENCY_WATCHABLE_HPP__

#include "concurrency/mutex_assertion.hpp"
#include "concurrency/pubsub.hpp"

template <class value_t>
class watchable_t {
public:
    class freeze_t {
    public:
        explicit freeze_t(const clone_ptr_t<watchable_t> &watchable) 
            : rwi_lock_acquisition(watchable->get_rwi_lock_assertion())
        { }

        void assert_is_holding(const clone_ptr_t<watchable_t> &watchable) {
            rwi_lock_acquisition.assert_is_holding(watchable->get_rwi_lock_assertion());
        }

    private:
        rwi_lock_assertion_t::read_acq_t rwi_lock_acquisition;
    };

    class subscription_t {
    public:
        explicit subscription_t(boost::function<void()> f)
            : subscription(f)
        { }

        subscription_t(boost::function<void()> f, const clone_ptr_t<watchable_t> &watchable, freeze_t *freeze) 
            : subscription(f, watchable->get_publisher(freeze))
        { }

        void reset() {
            subscription.reset();
        }

        void reset(const clone_ptr_t<watchable_t> &watchable, freeze_t *freeze) {
            subscription.reset(watchable->get_publisher(freeze));
        }

    private:
        typename publisher_t<boost::function<void()> >::subscription_t subscription;
    };

    virtual ~watchable_t() { }
    virtual watchable_t *clone() = 0;
    virtual value_t get() = 0;
    virtual publisher_t<boost::function<void()> > *get_publisher(freeze_t *) = 0;
    virtual rwi_lock_assertion_t *get_rwi_lock_assertion() = 0;

protected:
    watchable_t() { }

private:
    DISABLE_COPYING(watchable_t);
};

template <class value_t>
class watchable_variable_t {
public:
    explicit watchable_variable_t(const value_t &_value)
        : value(_value), watchable(this)
    { }

    clone_ptr_t<watchable_t<value_t> > get_watchable() {
        return clone_ptr_t<watchable_t<value_t> >(watchable.clone());
    }

    void set_value(const value_t &_value) {
        rwi_lock_assertion_t::write_acq_t acquisition(&rwi_lock_assertion);
        value = _value;
        publisher_controller.publish(&watchable_variable_t<value_t>::call);
    }

private:
    class w_t : public watchable_t<value_t> {
    public:
        explicit w_t(watchable_variable_t<value_t> *p) : parent(p) { }
        w_t *clone() {
{'fraction_non_alphanumeric': 0.10705236486486487, 'fraction_numerical': 0.0016891891891891893, 'mean_word_length': 3.452067669172932, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1980831', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1609, 'n_words': 244}