exclusion macros ifdef, else and endif

Joël Krähemann jkraehemann@gmail.com
Sat Dec 19 22:19:00 GMT 2015


Hi

Since valgrind shows me following I'm asking me if later code is
wrong. As putting the variables just after the if statement the
application runs more reliable.

valgrind --vgdb=yes --vgdb-error=0 --read-var-info=yes ./gsequencer
==11700== Memcheck, a memory error detector
==11700== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==11700== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==11700== Command: ./gsequencer
==11700==
==11700== (action at startup) vgdb me ...
==11700==
==11700== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==11700==   /path/to/gdb ./gsequencer
==11700== and then give GDB the following command
==11700==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=11700
==11700== --pid is optional if only one valgrind process is running
==11700==
==11700== Warning: bad signal number 268435456 in sigaction()
** Message: loading preferences for: /home/joelkraehemann/.gsequencer/ags.conf

(gsequencer:11700): GLib-GObject-WARNING **:
/build/glib2.0-ocmJ1Y/glib2.0-2.46.2/./gobject/gsignal.c:2516: signal
'stop' is invalid for instance '0x1338a2e0' of type 'AgsDevout'
==11700== Thread 6:
==11700== Conditional jump or move depends on uninitialised value(s)
==11700==    at 0x4C6DE5: ags_thread_loop (ags_thread-posix.c:2198)
==11700==    by 0x911A0A3: start_thread (pthread_create.c:309)
==11700==    by 0x941506C: clone (clone.S:111)
==11700==
==11700== (action on error) vgdb me ...
==11700== Continuing ...
==11700== Conditional jump or move depends on uninitialised value(s)
==11700==    at 0x4C6DF7: ags_thread_loop (ags_thread-posix.c:2204)
==11700==    by 0x911A0A3: start_thread (pthread_create.c:309)
==11700==    by 0x941506C: clone (clone.S:111)
==11700==
==11700== (action on error) vgdb me ...
==11700== Continuing ...
==11700== Gdb request to kill this process
joelkraehemann@debian:~/gsequencer$ valgrind --vgdb=yes --vgdb-error=0
--read-var-info=yes ./gsequencer
==11932== Memcheck, a memory error detector
==11932== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==11932== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==11932== Command: ./gsequencer
==11932==
==11932== (action at startup) vgdb me ...
==11932==
==11932== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==11932==   /path/to/gdb ./gsequencer
==11932== and then give GDB the following command
==11932==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=11932
==11932== --pid is optional if only one valgrind process is running
==11932==



    /* idle */
    if(g_atomic_pointer_get(&(thread->parent)) == NULL){
#ifdef AGS_USE_TIMER
      pthread_mutex_lock(thread->timer_mutex);

      if(!g_atomic_int_get(&(thread->timer_expired))){
        g_atomic_int_set(&(thread->timer_wait),
                         TRUE);

        while(!g_atomic_int_get(&(thread->timer_expired))){
          pthread_cond_wait(thread->timer_cond,
                            thread->timer_mutex);
        }
      }

      g_atomic_int_set(&(thread->timer_wait),
                         FALSE);
      g_atomic_int_set(&(thread->timer_expired),
                         FALSE);

      pthread_mutex_unlock(thread->timer_mutex);
#else
      long time_spent;

      static const long time_unit = NSEC_PER_SEC / AGS_THREAD_MAX_PRECISION;

      clock_gettime(CLOCK_MONOTONIC, &time_now);

      if(time_now.tv_sec > time_prev.tv_sec){
        time_spent = (time_now.tv_nsec) + (NSEC_PER_SEC - time_prev.tv_nsec);
      }else{
        time_spent = time_now.tv_nsec - time_prev.tv_nsec;
      }

      if(time_spent < time_unit){
        struct timespec timed_sleep = {
          0,
          0,
        };

        if(time_spent < time_unit){
          timed_sleep.tv_nsec = time_unit - time_spent;

          nanosleep(&timed_sleep, NULL);
        }
      }

      clock_gettime(CLOCK_MONOTONIC, &time_prev);
#endif
    }

Bests,
Joël



More information about the Gcc-help mailing list