lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eladmarg <...@git.apache.org>
Subject [GitHub] lucenenet pull request: Removing Apache.NMS dependency.
Date Sat, 23 Apr 2016 22:26:23 GMT
Github user eladmarg commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/168#discussion_r60835981
  
    --- Diff: src/Lucene.Net.Core/Support/AtomicObject.cs ---
    @@ -0,0 +1,39 @@
    +´╗┐using System;
    +using System.Threading;
    +
    +namespace Lucene.Net.Support
    +{
    +    public class AtomicObject<T> where T : class
    +    {
    +        private T _value;
    +        private ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
    +
    +        public AtomicObject() : this(default(T))
    +        { }
    +
    +        public AtomicObject(T initial)
    +        {
    +            _value = initial;
    +        }
    +
    +        public T Value
    +        {
    +            get
    +            {
    +                try
    +                {
    +                    _lock.EnterReadLock();
    +                    return _value;
    +                }
    +                finally
    +                {
    +                    _lock.ExitReadLock();
    +                }
    +            }
    +            set
    +            {
    +                Interlocked.Exchange(ref _value, value);
    --- End diff --
    
    Great job :+1: 
    just for safety, I would add 
    `
                try
                {
                    _lock.EnterWriteLock();
                    Interlocked.Exchange(ref _value, value);
                }
                finally
                {
                    _lock.ExitWriteLock();
                }`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message