title: Using atomic operations on a normal integer in C++
body: <p>I have a <code>struct</code> that contains an integer (say <code>int m_ref</code>) denoting an internal reference count.</p>
  
  <p>In order to maintain C compatibility I can't change the type to <code>std::atomic&lt;int&gt;</code>: the <code>struct</code> may only contain plain old data.</p>
  
  <p>However, I want to adjust my code to exploit the atomic features now in C++11; namely I need to accomplish:</p>
  
  <pre><code>++m_ref;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>--m_ref;
  </code></pre>
  
  <p>as atomic operations. I'm currently using assembler (Intel bus locks) to do this but that code is hardly portable and I'm keen to remove it now that C++ offers a standard construct.</p>
  
  <p>Somehow I need to get to 'under the hood' and do what <code>atomic&lt;T&gt;</code> does but without the overhead of creating an atomic type: I fear that attaching m_ref to <code>atomic&lt;T&gt;</code> will degrade performance.</p>
  
  <p>I suspect this is quite standard and I'm missing something simple here.</p>