<commit_before>#if FAT

using System;
using System.Collections.Generic;
using System.Threading;

using Theraot.Core;

namespace Theraot.Threading.Needles
{
    public sealed class TransactionNeedle<T> : ITransactionNeedle<T>
    {
        private readonly IEqualityComparer<T> _comparer;
        private readonly Func<T> _source;
        private readonly Action<T> _target;

        private T _original;
        private int _taken;
        private ThreadLocal<T> _value;
        private TransactionNeedle(Func<T> source, Action<T> target)
        {
            _source = source;
            _target = target;
            if (!ReferenceEquals(_source, null))
            {
                _original = _source.Invoke();
                _value = new ThreadLocal<T>(_source);
            }
        }

        bool IReadOnlyNeedle<T>.IsAlive
        {
            get
            {
                return true;
            }
        }

        public T Value
        {
            get
            {
                return _value.Value;
            }
            set
            {
                _value.Value = value;
            }
        }

        public bool Commit()
        {
            if (Interlocked.CompareExchange(ref _taken, 1, 0) == 0)
            {
                try
                {
                    _target.Invoke(_value.Value);
                    return true;
                }
                finally
                {
                    Interlocked.Decrement(ref _taken);
                }
            }
            else
            {
                return false;
            }
        }

        void INeedle<T>.Release()
        {
            //Empty
        }

        public IDisposable Lock()
        {
            if (ReferenceEquals(_source, null))
            {
                return DisposableAkin.Create();
            }
            else
            {
                Interlocked.Increment(ref _taken);
                if (_comparer.Equals(_original, _value.Value))
                {
                    return DisposableAkin.Create(() => Interlocked.Decrement(ref _taken));
                }
                else
                {
                    Interlocked.Decrement(ref _taken);
                    return null;
                }
            }
        }

        public void Rollback()
        {
            _value.Value = _source.Invoke();
        }

        internal static TransactionNeedle<T> Read(Func<T> source)
        {
            var transaction = Transaction.CurrentTransaction;
            if (transaction == null)
            {
                throw new InvalidOperationException("There is no current transaction.");
            }
            else
            {
                ITransactionResource resource;
                if (transaction.TryGetResource(source, out resource))<commit_msg>Removed EqualityComparer<commit_after>#if FAT

using System;
using System.Collections.Generic;
using System.Threading;

using Theraot.Core;

namespace Theraot.Threading.Needles
{
    public sealed class TransactionNeedle<T> : ITransactionNeedle<T>
    {
        private readonly Func<T> _source;
        private readonly Action<T> _target;

        private T _original;
        private int _taken;
        private ThreadLocal<T> _value;
        private TransactionNeedle(Func<T> source, Action<T> target)
        {
            _source = source;
            _target = target;
            if (!ReferenceEquals(_source, null))
            {
                _original = _source.Invoke();
                _value = new ThreadLocal<T>(_source);
            }
        }

        bool IReadOnlyNeedle<T>.IsAlive
        {
            get
            {
                return true;
            }
        }

        public T Value
        {
            get
            {
                return _value.Value;
            }
            set
            {
                _value.Value = value;
            }
        }

        public bool Commit()
        {
            if (Interlocked.CompareExchange(ref _taken, 1, 0) == 0)
            {
                try
                {
                    _target.Invoke(_value.Value);
                    return true;
                }
                finally
                {
                    Interlocked.Decrement(ref _taken);
                }
            }
            else
            {
                return false;
            }
        }

        void INeedle<T>.Release()
        {
            //Empty
        }

        public IDisposable Lock()
        {
            if (ReferenceEquals(_source, null))
            {
                return DisposableAkin.Create();
            }
            else
            {
                Interlocked.Increment(ref _taken);
                if (EqualityComparer<T>.Default.Equals(_original, _value.Value))
                {
                    return DisposableAkin.Create(() => Interlocked.Decrement(ref _taken));
                }
                else
                {
                    Interlocked.Decrement(ref _taken);
                    return null;
                }
            }
        }

        public void Rollback()
        {
            _value.Value = _source.Invoke();
        }

        internal static TransactionNeedle<T> Read(Func<T> source)
        {
            var transaction = Transaction.CurrentTransaction;
            if (transaction == null)
            {
                throw new InvalidOperationException("There is no current transaction.");
            }
            else
            {
                ITransactionResource resource;
                if (transaction.TryGetResource(source, out resource))
{'fraction_non_alphanumeric': 0.0759180790960452, 'fraction_numerical': 0.001059322033898305, 'mean_word_length': 1.0682730923694779, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, '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': '4258214', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1331, 'n_words': 284}