[vlc-commits] Clean up CPU flags one-time initialization
Rémi Denis-Courmont
git at videolan.org
Fri Aug 19 23:00:14 CEST 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Aug 19 23:19:01 2011 +0300| [e8b8ef7753e7d43d99118c79fa91ade9901f32d2] | committer: Rémi Denis-Courmont
Clean up CPU flags one-time initialization
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e8b8ef7753e7d43d99118c79fa91ade9901f32d2
---
src/libvlc.c | 2 --
src/libvlc.h | 7 +------
src/misc/cpu.c | 29 ++++++++++++++++-------------
src/win32/thread.c | 1 +
4 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/src/libvlc.c b/src/libvlc.c
index 0c931c1..759a495 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -191,8 +191,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
vlc_mutex_lock( &global_lock );
if( i_instances == 0 )
{
- /* Guess what CPU we have */
- cpu_flags = CPUCapabilities();
/* The module bank will be initialized later */
}
diff --git a/src/libvlc.h b/src/libvlc.h
index a4ef280..e562e17 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -41,6 +41,7 @@ void system_Init ( void );
void system_Configure ( libvlc_int_t *, int, const char *const [] );
void system_End ( void );
+void vlc_CPU_init(void);
void vlc_CPU_dump(vlc_object_t *);
/*
@@ -66,12 +67,6 @@ void vlc_assert_locked (vlc_mutex_t *);
#endif
/*
- * CPU capabilities
- */
-extern uint32_t cpu_flags;
-uint32_t CPUCapabilities( void );
-
-/*
* LibVLC exit event handling
*/
typedef struct vlc_exit
diff --git a/src/misc/cpu.c b/src/misc/cpu.c
index 7e4b073..24da34b 100644
--- a/src/misc/cpu.c
+++ b/src/misc/cpu.c
@@ -49,6 +49,8 @@
#include "libvlc.h"
+static uint32_t cpu_flags;
+
#if defined( __i386__ ) || defined( __x86_64__ ) || defined( __powerpc__ ) \
|| defined( __ppc__ ) || defined( __ppc64__ ) || defined( __powerpc64__ )
# ifndef WIN32
@@ -90,12 +92,11 @@ static bool check_OS_capability( const char *psz_capability, pid_t pid )
# endif
#endif
-/*****************************************************************************
- * CPUCapabilities: get the CPU capabilities
- *****************************************************************************
- * This function is called to list extensions the CPU may have.
- *****************************************************************************/
-uint32_t CPUCapabilities( void )
+/**
+ * Determines the CPU capabilities and stores them in cpu_flags.
+ * The result can be retrieved with vlc_CPU().
+ */
+void vlc_CPU_init (void)
{
uint32_t i_capabilities = 0;
@@ -322,17 +323,19 @@ out:
# endif
#endif
- return i_capabilities;
-}
-
-uint32_t cpu_flags = 0;
+ cpu_flags = i_capabilities;
+}
-/*****************************************************************************
- * vlc_CPU: get pre-computed CPU capability flags
- ****************************************************************************/
+/**
+ * Retrieves pre-computed CPU capability flags
+ */
unsigned vlc_CPU (void)
{
+#ifndef WIN32 /* On Windows, initialized from DllMain() instead */
+ static pthread_once_t once = PTHREAD_ONCE_INIT;
+ pthread_once (&once, vlc_CPU_init);
+#endif
return cpu_flags;
}
diff --git a/src/win32/thread.c b/src/win32/thread.c
index a70b15c..5b5753c 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -82,6 +82,7 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
vlc_threadvar_create (&thread_key, NULL);
vlc_rwlock_init (&config_lock);
vlc_rwlock_init (&msg_lock);
+ vlc_CPU_init ();
break;
case DLL_PROCESS_DETACH:
More information about the vlc-commits
mailing list