]> git.sesse.net Git - vlc/commitdiff
Make AddRef() and Release() atomic.
authorSteinar H. Gunderson <steinar+vlc@gunderson.no>
Mon, 27 Sep 2010 22:07:02 +0000 (00:07 +0200)
committerSteinar H. Gunderson <steinar+vlc@gunderson.no>
Mon, 27 Sep 2010 22:07:02 +0000 (00:07 +0200)
modules/access/sdi.cpp

index ec93c27cf677276bd8b8e5bd1676f38fa7bfa734..9c6946e950a319b2d88e5a5fed55160d168bf6d9 100644 (file)
@@ -16,6 +16,7 @@
 #include <vlc_picture.h>
 #include <vlc_charset.h>
 #include <vlc_fs.h>
+#include <vlc_atomic.h>
 
 #include <arpa/inet.h>
 
@@ -126,32 +127,31 @@ struct demux_sys_t
 class DeckLinkCaptureDelegate : public IDeckLinkInputCallback
 {
 public:
-    DeckLinkCaptureDelegate( demux_t *p_demux ) : m_ref_(1), p_demux_(p_demux) {}
+    DeckLinkCaptureDelegate( demux_t *p_demux ) : p_demux_(p_demux)
+    {
+        vlc_atomic_set( &m_ref_, 1 );
+    }
 
     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) { return E_NOINTERFACE; }
 
-    /* Note: AddRef() and Release() here are not thread safe. */
-
     virtual ULONG STDMETHODCALLTYPE AddRef(void)
     {
-        return ++m_ref_;
+        return vlc_atomic_inc( &m_ref_ );
     }
 
     virtual ULONG STDMETHODCALLTYPE Release(void)
     {
-        if ( --m_ref_ == 0 )
-        {
+        uintptr_t new_ref = vlc_atomic_dec( &m_ref_ );
+        if ( new_ref == 0 )
             delete this;
-            return 0;
-        }
-        return m_ref_;
+        return new_ref;
     }
 
     virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
     virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);
 
 private:
-    int m_ref_;
+    vlc_atomic_t m_ref_;
     demux_t *p_demux_;
 };