<commit_before>﻿using System;

namespace Neon.Entities {
    /// <summary>
    /// Wraps the notification pattern, where something happens multiple times but the listeners
    /// should only be notified once.
    /// </summary>
    /// <typeparam name="ParamType">The type of the parameter.</typeparam>
    public class Notifier<ParamType> {
        /// <summary>
        /// Have we already notified the listeners?
        /// </summary>
        private bool _activated = false;

        /// <summary>
        /// Parameter to notify listeners with.
        /// </summary>
        private ParamType _notificationParam;

        /// <summary>
        /// Initializes a new instance of the <see cref="Notifier{ParamType}"/> class.
        /// </summary>
        /// <param name="param">The parameter to notify listeners with.</param>
        public Notifier(ParamType param) {
            _notificationParam = param;
        }

        /// <summary>
        /// Resets this notifier so that it will notify listeners again.
        /// </summary>
        public void Reset() {
            _activated = false;
        }

        /// <summary>
        /// Notify the listeners if they have no already been notified.
        /// </summary>
        public void Notify() {
            if (_activated == false) {
                _activated = true;
                if (Listener != null) {
                    Listener(_notificationParam);
                }
            }
        }

        /// <summary>
        /// Allows objects to listen for notifications.
        /// </summary>
        public event Action<ParamType> Listener;
    }
}<commit_msg>Make Notifier thread-safe<commit_after>﻿using System;

namespace Neon.Entities {
    /// <summary>
    /// Wraps the notification pattern, where something happens multiple times but the listeners
    /// should only be notified once.
    /// </summary>
    /// <remarks>
    /// The Notifier API is thread-safe.
    /// </remarks>
    /// <typeparam name="ParamType">The type of the parameter.</typeparam>
    public class Notifier<ParamType> {
        private object _lock = new object();

        /// <summary>
        /// Have we already notified the listeners?
        /// </summary>
        private bool _activated = false;

        /// <summary>
        /// Parameter to notify listeners with.
        /// </summary>
        private ParamType _notificationParam;

        /// <summary>
        /// Initializes a new instance of the <see cref="Notifier{ParamType}"/> class.
        /// </summary>
        /// <param name="param">The parameter to notify listeners with.</param>
        public Notifier(ParamType param) {
            _notificationParam = param;
        }

        /// <summary>
        /// Resets this notifier so that it will notify listeners again.
        /// </summary>
        public void Reset() {
            lock (_lock) {
                _activated = false;
            }
        }

        /// <summary>
        /// Notify the listeners if they have not already been notified.
        /// </summary>
        public void Notify() {
            lock (_lock) {
                if (_activated == false) {
                    _activated = true;
                    if (Listener != null) {
                        Listener(_notificationParam);
                    }
                }
            }
        }

        /// <summary>
        /// Allows objects to listen for notifications.
        /// </summary>
        public event Action<ParamType> Listener;
    }
}
{'fraction_non_alphanumeric': 0.11689782054910841, 'fraction_numerical': 0.0, 'mean_word_length': 1.5010615711252655, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '2315996', 'n_tokens_mistral': 874, 'n_tokens_neox': 838, 'n_words': 278}