[vlc-commits] cpu: deduplicate one-time initialization
Rémi Denis-Courmont
git at videolan.org
Mon Mar 30 15:51:28 CEST 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar 29 17:27:24 2020 +0300| [31f895d0842dc6824c57a3d629db1507ddbf1f2e] | committer: Rémi Denis-Courmont
cpu: deduplicate one-time initialization
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=31f895d0842dc6824c57a3d629db1507ddbf1f2e
---
include/vlc_cpu.h | 8 ++++++++
src/linux/cpu.c | 22 +---------------------
src/misc/cpu.c | 4 ++--
3 files changed, 11 insertions(+), 23 deletions(-)
diff --git a/include/vlc_cpu.h b/include/vlc_cpu.h
index 6fe098f78a..80dfd9656d 100644
--- a/include/vlc_cpu.h
+++ b/include/vlc_cpu.h
@@ -31,6 +31,14 @@
*/
VLC_API unsigned vlc_CPU(void);
+/**
+ * Computes CPU capability flags.
+ *
+ * Do not call this function directly.
+ * Call vlc_CPU() instead, which caches the correct value.
+ */
+unsigned vlc_CPU_raw(void);
+
# if defined (__i386__) || defined (__x86_64__)
# define HAVE_FPU 1
# define VLC_CPU_MMX 0x00000008
diff --git a/src/linux/cpu.c b/src/linux/cpu.c
index b8a4b4d354..6ba11512ef 100644
--- a/src/linux/cpu.c
+++ b/src/linux/cpu.c
@@ -40,7 +40,7 @@
#endif
#ifdef CPU_FLAGS
-static unsigned vlc_CPU_raw(void)
+unsigned vlc_CPU_raw(void)
{
FILE *info = fopen ("/proc/cpuinfo", "rte");
if (info == NULL)
@@ -120,24 +120,4 @@ static unsigned vlc_CPU_raw(void)
return all_caps;
}
-
-static unsigned cpu_flags = 0;
-
-static void vlc_CPU_init(void)
-{
- cpu_flags = vlc_CPU_raw();
-}
-
-unsigned vlc_CPU (void)
-{
- static pthread_once_t once = PTHREAD_ONCE_INIT;
-
- pthread_once (&once, vlc_CPU_init);
- return cpu_flags;
-}
-#else /* CPU_FLAGS */
-unsigned vlc_CPU (void)
-{
- return 0;
-}
#endif
diff --git a/src/misc/cpu.c b/src/misc/cpu.c
index 9d9c71fd98..c73a513607 100644
--- a/src/misc/cpu.c
+++ b/src/misc/cpu.c
@@ -113,7 +113,7 @@ static void Altivec_test (void)
/**
* Determines the CPU capabilities.
*/
-static unsigned vlc_CPU_raw(void)
+VLC_WEAK unsigned vlc_CPU_raw(void)
{
uint32_t i_capabilities = 0;
@@ -254,7 +254,7 @@ static void vlc_CPU_init(void)
cpu_flags = vlc_CPU_raw();
}
-VLC_WEAK unsigned vlc_CPU(void)
+unsigned vlc_CPU(void)
{
static vlc_once_t once = VLC_STATIC_ONCE;
vlc_once(&once, vlc_CPU_init);
More information about the vlc-commits
mailing list