[vlc-devel] [PATCH] Remove the deprecated vlc_atomic_t type.

Felix Abecassis felix.abecassis at gmail.com
Thu Jan 2 11:43:02 CET 2014


---
 include/vlc_atomic.h                 | 62 ++++--------------------------------
 modules/access/decklink.cpp          |  8 ++---
 modules/gui/qt4/dialogs/messages.cpp |  4 +--
 modules/gui/qt4/dialogs/messages.hpp |  2 +-
 modules/hw/vdpau/adjust.c            | 32 +++----------------
 modules/video_filter/atmo/atmo.cpp   | 12 +++----
 src/android/thread.c                 |  8 ++---
 src/audio_output/volume.c            |  4 +--
 src/misc/update.c                    | 10 +++---
 src/misc/update.h                    |  2 +-
 10 files changed, 36 insertions(+), 108 deletions(-)

diff --git a/include/vlc_atomic.h b/include/vlc_atomic.h
index 49cc1ae..8420a7e 100644
--- a/include/vlc_atomic.h
+++ b/include/vlc_atomic.h
@@ -387,65 +387,17 @@ typedef         uintmax_t atomic_uintmax_t;
 # endif
 # endif
 
-/**
- * Memory storage space for an atom. Never access it directly.
- */
-typedef union
-{
-    atomic_uintptr_t u;
-} vlc_atomic_t;
-
-/** Static initializer for \ref vlc_atomic_t */
-# define VLC_ATOMIC_INIT(val) { (val) }
-
-/* All functions return the atom value _after_ the operation. */
-static inline uintptr_t vlc_atomic_get(vlc_atomic_t *atom)
-{
-    return atomic_load(&atom->u);
-}
-
-static inline uintptr_t vlc_atomic_set(vlc_atomic_t *atom, uintptr_t v)
-{
-    atomic_store(&atom->u, v);
-    return v;
-}
-
-static inline uintptr_t vlc_atomic_add(vlc_atomic_t *atom, uintptr_t v)
-{
-    return atomic_fetch_add(&atom->u, v) + v;
-}
-
-static inline uintptr_t vlc_atomic_sub (vlc_atomic_t *atom, uintptr_t v)
-{
-    return atomic_fetch_sub (&atom->u, v) - v;
-}
-
-static inline uintptr_t vlc_atomic_inc (vlc_atomic_t *atom)
-{
-    return vlc_atomic_add (atom, 1);
-}
-
-static inline uintptr_t vlc_atomic_dec (vlc_atomic_t *atom)
-{
-    return vlc_atomic_sub (atom, 1);
-}
-
-static inline uintptr_t vlc_atomic_swap(vlc_atomic_t *atom, uintptr_t v)
-{
-    return atomic_exchange(&atom->u, v);
-}
+typedef atomic_uint_least32_t vlc_atomic_float;
 
-static inline uintptr_t vlc_atomic_compare_swap(vlc_atomic_t *atom,
-                                                uintptr_t u, uintptr_t v)
+static inline void vlc_atomic_init_float(vlc_atomic_float *var, float f)
 {
-    atomic_compare_exchange_strong(&atom->u, &u, v);
-    return u;
+    union { float f; uint32_t i; } u;
+    u.f = f;
+    atomic_init(var, u.i);
 }
 
-typedef atomic_uint_least32_t vlc_atomic_float;
-
 /** Helper to retrieve a single precision from an atom. */
-static inline float vlc_atomic_loadf(vlc_atomic_float *atom)
+static inline float vlc_atomic_load_float(vlc_atomic_float *atom)
 {
     union { float f; uint32_t i; } u;
     u.i = atomic_load(atom);
@@ -453,7 +405,7 @@ static inline float vlc_atomic_loadf(vlc_atomic_float *atom)
 }
 
 /** Helper to store a single precision into an atom. */
-static inline void vlc_atomic_storef(vlc_atomic_float *atom, float f)
+static inline void vlc_atomic_store_float(vlc_atomic_float *atom, float f)
 {
     union { float f; uint32_t i; } u;
     u.f = f;
diff --git a/modules/access/decklink.cpp b/modules/access/decklink.cpp
index 35121b1..fd0852b 100644
--- a/modules/access/decklink.cpp
+++ b/modules/access/decklink.cpp
@@ -154,19 +154,19 @@ class DeckLinkCaptureDelegate : public IDeckLinkInputCallback
 public:
     DeckLinkCaptureDelegate(demux_t *demux) : demux_(demux)
     {
-        vlc_atomic_set(&m_ref_, 1);
+        atomic_store(&m_ref, 1);
     }
 
     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, LPVOID *) { return E_NOINTERFACE; }
 
     virtual ULONG STDMETHODCALLTYPE AddRef(void)
     {
-        return vlc_atomic_inc(&m_ref_);
+        return atomic_fetch_add(&m_ref, 1);
     }
 
     virtual ULONG STDMETHODCALLTYPE Release(void)
     {
-        uintptr_t new_ref = vlc_atomic_dec(&m_ref_);
+        uintptr_t new_ref = atomic_fetch_sub(&m_ref_, 1);
         if (new_ref == 0)
             delete this;
         return new_ref;
@@ -181,7 +181,7 @@ public:
     virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);
 
 private:
-    vlc_atomic_t m_ref_;
+    atomic_uint m_ref_;
     demux_t *demux_;
 };
 
diff --git a/modules/gui/qt4/dialogs/messages.cpp b/modules/gui/qt4/dialogs/messages.cpp
index 223c479..30793a2 100644
--- a/modules/gui/qt4/dialogs/messages.cpp
+++ b/modules/gui/qt4/dialogs/messages.cpp
@@ -143,7 +143,7 @@ MessagesDialog::~MessagesDialog()
 
 void MessagesDialog::changeVerbosity( int i_verbosity )
 {
-    vlc_atomic_set( &this->verbosity, i_verbosity );
+    atomic_store( &this->verbosity, i_verbosity );
 }
 
 void MessagesDialog::updateConfig()
@@ -337,7 +337,7 @@ void MessagesDialog::MsgCallback( void *self, int type, const vlc_log_t *item,
 {
     MessagesDialog *dialog = (MessagesDialog *)self;
     char *str;
-    int verbosity = vlc_atomic_get( &dialog->verbosity );
+    int verbosity = atomic_load( &dialog->verbosity );
 
     if( verbosity < 0 || verbosity < (type - VLC_MSG_ERR)
      || unlikely(vasprintf( &str, format, ap ) == -1) )
diff --git a/modules/gui/qt4/dialogs/messages.hpp b/modules/gui/qt4/dialogs/messages.hpp
index 945db4f..3a9ab31 100644
--- a/modules/gui/qt4/dialogs/messages.hpp
+++ b/modules/gui/qt4/dialogs/messages.hpp
@@ -55,7 +55,7 @@ private:
     void sinkMessage( const MsgEvent * );
     bool matchFilter( const QString& );
 
-    vlc_atomic_t verbosity;
+    atomic_uint verbosity;
     static void MsgCallback( void *, int, const vlc_log_t *, const char *,
                              va_list );
 
diff --git a/modules/hw/vdpau/adjust.c b/modules/hw/vdpau/adjust.c
index 7828579..a402073 100644
--- a/modules/hw/vdpau/adjust.c
+++ b/modules/hw/vdpau/adjust.c
@@ -33,36 +33,12 @@
 
 struct filter_sys_t
 {
-    atomic_uint_fast32_t brightness;
-    atomic_uint_fast32_t contrast;
-    atomic_uint_fast32_t saturation;
-    atomic_uint_fast32_t hue;
+    vlc_atomic_float brightness;
+    vlc_atomic_float contrast;
+    vlc_atomic_float saturation;
+    vlc_atomic_float hue;
 };
 
-static inline void vlc_atomic_init_float(atomic_uint_fast32_t *var, float val)
-{
-    union { uint32_t u; float f; } u;
-
-    u.f = val;
-    atomic_init(var, u.u);
-}
-
-static inline void vlc_atomic_store_float(atomic_uint_fast32_t *var, float val)
-{
-    union { uint32_t u; float f; } u;
-
-    u.f = val;
-    atomic_store(var, u.u);
-}
-
-static inline float vlc_atomic_load_float(atomic_uint_fast32_t *var)
-{
-    union { uint32_t u; float f; } u;
-
-    u.u = atomic_load(var);
-    return u.f;
-}
-
 static float vlc_to_vdp_brightness(float brightness)
 {
     brightness -= 1.f;
diff --git a/modules/video_filter/atmo/atmo.cpp b/modules/video_filter/atmo/atmo.cpp
index cbcbec1..581e0d7 100644
--- a/modules/video_filter/atmo/atmo.cpp
+++ b/modules/video_filter/atmo/atmo.cpp
@@ -703,7 +703,7 @@ typedef struct
 {
     filter_t *p_filter;
     vlc_thread_t thread;
-    vlc_atomic_t abort;
+    atomic_bool abort;
 
     /* tell the thread which color should be the target of fading */
     uint8_t ui_red;
@@ -1120,7 +1120,7 @@ static void Atmo_Shutdown(filter_t *p_filter)
           p_sys->p_fadethread->i_steps  = 1;
         else
           p_sys->p_fadethread->i_steps  = p_sys->i_endfadesteps;
-        vlc_atomic_set(&p_sys->p_fadethread->abort, 0);
+        atomic_store(&p_sys->p_fadethread->abort, false);
 
         if( vlc_clone( &p_sys->p_fadethread->thread,
                        FadeToColorThread,
@@ -2390,7 +2390,7 @@ static void *FadeToColorThread(void *obj)
             /* send the same pixel data again... to unlock the buffer! */
             AtmoSendPixelData( p_fadethread->p_filter );
 
-            while( (!vlc_atomic_get (&p_fadethread->abort)) &&
+            while( (!atomic_load (&p_fadethread->abort)) &&
                 (i_steps_done < p_fadethread->i_steps))
             {
                 p_transfer = AtmoLockTransferBuffer( p_fadethread->p_filter );
@@ -2403,7 +2403,7 @@ static void *FadeToColorThread(void *obj)
                 thread improvements wellcome!
                 */
                 for(i_index = 0;
-                    (i_index < i_size) && (!vlc_atomic_get (&p_fadethread->abort));
+                    (i_index < i_size) && (!atomic_load (&p_fadethread->abort));
                     i_index+=4)
                 {
                     i_src_blue  = p_source[i_index+0];
@@ -2459,7 +2459,7 @@ static void CheckAndStopFadeThread(filter_t *p_filter)
     {
         msg_Dbg(p_filter, "kill still running fadeing thread...");
 
-        vlc_atomic_set(&p_sys->p_fadethread->abort, 1);
+        atomic_store(&p_sys->p_fadethread->abort, true);
 
         vlc_join(p_sys->p_fadethread->thread, NULL);
         free(p_sys->p_fadethread);
@@ -2507,7 +2507,7 @@ static int StateCallback( vlc_object_t *, char const *,
                 p_sys->p_fadethread->ui_green = p_sys->ui_pausecolor_green;
                 p_sys->p_fadethread->ui_blue  = p_sys->ui_pausecolor_blue;
                 p_sys->p_fadethread->i_steps  = p_sys->i_fadesteps;
-                vlc_atomic_set(&p_sys->p_fadethread->abort, 0);
+                atomic_store(&p_sys->p_fadethread->abort, false);
 
                 if( vlc_clone( &p_sys->p_fadethread->thread,
                                FadeToColorThread,
diff --git a/src/android/thread.c b/src/android/thread.c
index 3ef87cf..dfbe920 100644
--- a/src/android/thread.c
+++ b/src/android/thread.c
@@ -170,7 +170,7 @@ struct vlc_thread
     void *(*entry)(void*);
     void *data;
 
-    vlc_atomic_t killed;
+    atomic_bool killed;
     bool killable;
 };
 
@@ -374,7 +374,7 @@ static int vlc_clone_attr (vlc_thread_t *th, void *(*entry) (void *),
 
 
     vlc_sem_init(&thread->finished, 0);
-    vlc_atomic_set(&thread->killed, false);
+    atomic_store(&thread->killed, false);
     thread->killable = true;
     thread->cond = NULL;
     thread->entry = entry;
@@ -434,7 +434,7 @@ void vlc_cancel (vlc_thread_t thread_id)
 {
     pthread_cond_t *cond;
 
-    vlc_atomic_set(&thread_id->killed, true);
+    atomic_store(&thread_id->killed, true);
 
     vlc_mutex_lock(&thread_id->lock);
     cond = thread_id->cond;
@@ -467,7 +467,7 @@ void vlc_testcancel (void)
         return;
     if (!thread->killable)
         return;
-    if (!vlc_atomic_get(&thread->killed))
+    if (!atomic_load(&thread->killed))
         return;
 
     pthread_exit(NULL);
diff --git a/src/audio_output/volume.c b/src/audio_output/volume.c
index 57e8f33..78c1517 100644
--- a/src/audio_output/volume.c
+++ b/src/audio_output/volume.c
@@ -135,7 +135,7 @@ int aout_volume_Amplify(aout_volume_t *vol, block_t *block)
         return -1;
 
     float amp = vol->output_factor
-              * vlc_atomic_loadf (&vol->gain_factor);
+              * vlc_atomic_load_float (&vol->gain_factor);
 
     vol->object.amplify(&vol->object, block, amp);
     return 0;
@@ -197,7 +197,7 @@ static int ReplayGainCallback (vlc_object_t *obj, char const *var,
     aout_volume_t *vol = data;
     float multiplier = aout_ReplayGainSelect(obj, val.psz_string,
                                              &vol->replay_gain);
-    vlc_atomic_storef (&vol->gain_factor, multiplier);
+    vlc_atomic_store_float (&vol->gain_factor, multiplier);
     VLC_UNUSED(var); VLC_UNUSED(oldval);
     return VLC_SUCCESS;
 }
diff --git a/src/misc/update.c b/src/misc/update.c
index 4a1a128..8dc4954 100644
--- a/src/misc/update.c
+++ b/src/misc/update.c
@@ -141,7 +141,7 @@ void update_Delete( update_t *p_update )
 
     if( p_update->p_download )
     {
-        vlc_atomic_set( &p_update->p_download->aborted, 1 );
+        atomic_store( &p_update->p_download->aborted, true );
         vlc_join( p_update->p_download->thread, NULL );
         vlc_object_release( p_update->p_download );
     }
@@ -494,7 +494,7 @@ void update_Download( update_t *p_update, const char *psz_destdir )
     // If the object already exist, destroy it
     if( p_update->p_download )
     {
-        vlc_atomic_set( &p_update->p_download->aborted, 1 );
+        atomic_store( &p_update->p_download->aborted, true );
         vlc_join( p_update->p_download->thread, NULL );
         vlc_object_release( p_update->p_download );
     }
@@ -509,7 +509,7 @@ void update_Download( update_t *p_update, const char *psz_destdir )
     p_update->p_download = p_udt;
     p_udt->psz_destdir = psz_destdir ? strdup( psz_destdir ) : NULL;
 
-    vlc_atomic_set(&p_udt->aborted, 0);
+    atomic_store(&p_udt->aborted, false);
     vlc_clone( &p_udt->thread, update_DownloadReal, p_udt, VLC_THREAD_PRIORITY_LOW );
 }
 
@@ -590,7 +590,7 @@ static void* update_DownloadReal( void *obj )
     if( p_progress == NULL )
         goto end;
 
-    while( !vlc_atomic_get( &p_udt->aborted ) &&
+    while( !atomic_load( &p_udt->aborted ) &&
            ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
            !dialog_ProgressCancelled( p_progress ) )
     {
@@ -618,7 +618,7 @@ static void* update_DownloadReal( void *obj )
     fclose( p_file );
     p_file = NULL;
 
-    if( !vlc_atomic_get( &p_udt->aborted ) &&
+    if( !atomic_load( &p_udt->aborted ) &&
         !dialog_ProgressCancelled( p_progress ) )
     {
         dialog_ProgressDestroy( p_progress );
diff --git a/src/misc/update.h b/src/misc/update.h
index 83d0723..61925e2 100644
--- a/src/misc/update.h
+++ b/src/misc/update.h
@@ -153,7 +153,7 @@ typedef struct
     VLC_COMMON_MEMBERS
 
     vlc_thread_t thread;
-    vlc_atomic_t aborted;
+    atomic_bool aborted;
     update_t *p_update;
     char *psz_destdir;
 } update_download_thread_t;
-- 
1.8.3.2




More information about the vlc-devel mailing list