[vlc-commits] commit: Avoid calling dlsym at every code ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Sat Apr 17 16:56:14 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Apr 17 16:39:46 2010 +0300| [49a14c1606cf8dd3312d7f1a9c14182bfe196c74] | committer: Rémi Denis-Courmont 

Avoid calling dlsym at every code

First I ever need to use the auto keyword...

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=49a14c1606cf8dd3312d7f1a9c14182bfe196c74
---

 bin/override.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/bin/override.c b/bin/override.c
index 02402d5..5996e43 100644
--- a/bin/override.c
+++ b/bin/override.c
@@ -26,7 +26,7 @@
 
 void vlc_enable_override (void);
 
-#if defined (__GNUC__) /* typeof and statement-expression */ \
+#if defined (__GNUC__) \
  && (defined (__ELF__) && !defined (__sun__))
 /* Solaris crashes on printf("%s", NULL); which is legal, but annoying. */
 
@@ -97,8 +97,23 @@ static void *getsym (const char *name)
 }
 
 #define LOG(level, ...) logbug(level, __func__, __VA_ARGS__)
+/* Evil non-standard GNU C macro ;)
+ *  typeof keyword,
+ *  statement-expression,
+ *  nested function...
+ */
 #define CALL(func, ...) \
-    ({ typeof (func) *sym = getsym ( # func); sym (__VA_ARGS__); })
+({ \
+    static typeof (func) *sym = NULL; \
+    static pthread_once_t once = PTHREAD_ONCE_INIT; \
+    auto void getsym_once (void); \
+    void getsym_once (void) \
+    { \
+        sym = getsym ( # func); \
+    } \
+    pthread_once (&once, getsym_once); \
+    sym (__VA_ARGS__); \
+})
 
 
 /*** Environment ***



More information about the vlc-commits mailing list