Don't use volatile to mean atomic
authorSebastian Dröge <sebastian@centricular.com>
Fri, 7 Apr 2023 09:15:43 +0000 (12:15 +0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 7 Apr 2023 11:44:45 +0000 (11:44 +0000)
volatile is not sufficient to provide atomic guarantees and real atomics
should be used instead. GCC 11 has started warning about using volatile
with atomic operations.

In case of orc, the volatile integers were always protected with a
mutex, which makes it completely unnecessary.

Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/91>

orc/orc.c
orc/orcfunctions.c
tools/orcc.c

index 7b4808c..40240ef 100644 (file)
--- a/orc/orc.c
+++ b/orc/orc.c
@@ -36,7 +36,7 @@ void _orc_compiler_init(void);
 void
 orc_init (void)
 {
-  static volatile int inited = FALSE;
+  static int inited = FALSE;
 
   if (!inited) {
     orc_global_mutex_lock ();
index 3ddc501..9aa7f99 100644 (file)
@@ -182,7 +182,7 @@ void
 orc_memcpy (void * ORC_RESTRICT d1, const void * ORC_RESTRICT s1, int n)
 {
   OrcExecutor _ex, *ex = &_ex;
-  static volatile int p_inited = 0;
+  static int p_inited = 0;
   static OrcCode *c = 0;
   void (*func) (OrcExecutor *);
 
@@ -279,7 +279,7 @@ void
 orc_memset (void * ORC_RESTRICT d1, int p1, int n)
 {
   OrcExecutor _ex, *ex = &_ex;
-  static volatile int p_inited = 0;
+  static int p_inited = 0;
   static OrcCode *c = 0;
   void (*func) (OrcExecutor *);
 
index 3585e93..36b0adc 100644 (file)
@@ -862,7 +862,7 @@ output_code_execute (OrcProgram *p, FILE *output, int is_inline)
       fprintf(output, "  OrcProgram *p = _orc_program_%s;\n", p->name);
     }
   } else {
-    fprintf(output, "  static volatile int p_inited = 0;\n");
+    fprintf(output, "  static int p_inited = 0;\n");
     if (use_code) {
       fprintf(output, "  static OrcCode *c = 0;\n");
     } else {