title: Lockless using InterlockedCompareExchange
body: <p>I am trying to make following snip of code lockless using interlocked operations, Any idea how to translate this?</p>
  
  <pre><code>if (m_Ref == 0xFFFF)
      m_Ref = 1;
  else
  {
      if (++m_Ref == 1)
          CallSomething(); //
  
  }
  </code></pre>
  
  <p>I was thinking something like</p>
  
  <pre><code>if (InterlockedCompareExchange(&amp;m_Ref, 1, 0xFFFF) != 0xFFFF))
  {
      if (InterlockedIncrement(&amp;m_Ref) == 1)
           CallSomething();
  }
  </code></pre>
  
  <p>Is there any issues/race in this?</p>