From 8f14143859b7e09f2aee5f63d73f0ce6713d7f30 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Fri, 2 Sep 2022 23:47:58 +0200 Subject: [PATCH] Don't do implicit memsets for struct timespec - always has only a tv_sec and tv_nsec member field which always get set --- gfx/drivers/exynos_gfx.c | 4 ++-- libretro-common/features/features_cpu.c | 6 +++--- libretro-common/include/retro_timers.h | 2 +- libretro-common/rthreads/ctr_pthread.h | 15 ++++++++------- libretro-common/rthreads/rthreads.c | 3 +-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index 8dc001083d..0a29cf1796 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -410,7 +410,7 @@ static void exynos_perf_memcpy(struct exynos_perf *p, bool start) clock_gettime(CLOCK_MONOTONIC, &p->tspec); else { - struct timespec new = { 0 }; + struct timespec new; clock_gettime(CLOCK_MONOTONIC, &new); p->memcpy_time += (new.tv_sec - p->tspec.tv_sec) * 1000000; @@ -425,7 +425,7 @@ static void exynos_perf_g2d(struct exynos_perf *p, bool start) clock_gettime(CLOCK_MONOTONIC, &p->tspec); else { - struct timespec new = { 0 }; + struct timespec new; clock_gettime(CLOCK_MONOTONIC, &new); p->g2d_time += (new.tv_sec - p->tspec.tv_sec) * 1000000; diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index 345e4e99bd..9da1cb9b87 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -126,7 +126,7 @@ static int ra_clock_gettime(int clk_ik, struct timespec *t) { struct timeval now; - int rv = gettimeofday(&now, NULL); + int rv = gettimeofday(&now, NULL); if (rv) return rv; t->tv_sec = now.tv_sec; @@ -184,7 +184,7 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) #elif !defined(__MACH__) && (defined(_XBOX360) || defined(__powerpc__) || defined(__ppc__) || defined(__POWERPC__) || defined(__PSL1GHT__) || defined(__PPC64__) || defined(__powerpc64__)) time_ticks = __mftb(); #elif (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0) || defined(__QNX__) || defined(ANDROID) - struct timespec tv = {0}; + struct timespec tv; if (ra_clock_gettime(CLOCK_MONOTONIC, &tv) == 0) time_ticks = (retro_perf_tick_t)tv.tv_sec * 1000000000 + (retro_perf_tick_t)tv.tv_nsec; @@ -251,7 +251,7 @@ retro_time_t cpu_features_get_time_usec(void) #elif defined(_3DS) return osGetTime() * 1000; #elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__) - struct timespec tv = {0}; + struct timespec tv; if (ra_clock_gettime(CLOCK_MONOTONIC, &tv) < 0) return 0; return tv.tv_sec * INT64_C(1000000) + (tv.tv_nsec + 500) / 1000; diff --git a/libretro-common/include/retro_timers.h b/libretro-common/include/retro_timers.h index 56567e9d09..07d744653f 100644 --- a/libretro-common/include/retro_timers.h +++ b/libretro-common/include/retro_timers.h @@ -102,7 +102,7 @@ static int nanosleepDOS(const struct timespec *rqtp, struct timespec *rmtp) #else #define retro_sleep(msec) \ { \ - struct timespec tv = {0}; \ + struct timespec tv; \ tv.tv_sec = msec / 1000; \ tv.tv_nsec = (msec % 1000) * 1000000; \ nanosleep(&tv, NULL); \ diff --git a/libretro-common/rthreads/ctr_pthread.h b/libretro-common/rthreads/ctr_pthread.h index d535140775..88b359d4e9 100644 --- a/libretro-common/rthreads/ctr_pthread.h +++ b/libretro-common/rthreads/ctr_pthread.h @@ -265,26 +265,27 @@ static INLINE int pthread_cond_wait(pthread_cond_t *cond, static INLINE int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) { - struct timespec now = {0}; /* Missing clock_gettime*/ + struct timespec now; struct timeval tm; int retval = 0; - do { + do + { + s64 timeout; gettimeofday(&tm, NULL); - now.tv_sec = tm.tv_sec; + now.tv_sec = tm.tv_sec; now.tv_nsec = tm.tv_usec * 1000; - s64 timeout = (abstime->tv_sec - now.tv_sec) * 1000000000 + (abstime->tv_nsec - now.tv_nsec); - if (timeout < 0) + if ((timeout = (abstime->tv_sec - now.tv_sec) * 1000000000 + +(abstime->tv_nsec - now.tv_nsec)) < 0) { retval = ETIMEDOUT; break; } - if (!CondVar_WaitTimeout((CondVar *)cond, (LightLock *)mutex, timeout)) { + if (!CondVar_WaitTimeout((CondVar *)cond, (LightLock *)mutex, timeout)) break; - } } while (1); return retval; diff --git a/libretro-common/rthreads/rthreads.c b/libretro-common/rthreads/rthreads.c index 02aa5be65d..b611a3e443 100644 --- a/libretro-common/rthreads/rthreads.c +++ b/libretro-common/rthreads/rthreads.c @@ -826,8 +826,7 @@ bool scond_wait_timeout(scond_t *cond, slock_t *lock, int64_t timeout_us) #else int ret; int64_t seconds, remainder; - struct timespec now = {0}; - + struct timespec now; #ifdef __MACH__ /* OSX doesn't have clock_gettime. */ clock_serv_t cclock;