[vlc-commits] [Git][videolan/vlc][master] access: cache: disable code not used without VLC_ACCESS_CACHE_CAN_REGISTER

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Apr 8 21:03:13 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
c6d72dff by Steve Lhomme at 2022-04-08T13:12:43+00:00
access: cache: disable code not used without VLC_ACCESS_CACHE_CAN_REGISTER

- - - - -


2 changed files:

- modules/access/cache.c
- modules/access/cache.h


Changes:

=====================================
modules/access/cache.c
=====================================
@@ -64,6 +64,7 @@ vlc_access_cache_entry_New(void *context, const char *url, const char *username,
     return entry;
 }
 
+#ifdef VLC_ACCESS_CACHE_CAN_REGISTER
 static void *
 vlc_access_cache_Thread(void *data)
 {
@@ -104,7 +105,6 @@ vlc_access_cache_InitOnce(void *data)
 {
     struct vlc_access_cache *cache = data;
 
-#ifdef VLC_ACCESS_CACHE_CAN_REGISTER
     vlc_mutex_lock(&cache->lock);
 
     cache->running = true;
@@ -114,7 +114,6 @@ vlc_access_cache_InitOnce(void *data)
         cache->running = false;
 
     vlc_mutex_unlock(&cache->lock);
-#endif
 }
 
 void
@@ -138,15 +137,19 @@ vlc_access_cache_Destroy(struct vlc_access_cache *cache)
         vlc_access_cache_entry_Delete(entry);
     }
 }
+#endif
 
 void
 vlc_access_cache_AddEntry(struct vlc_access_cache *cache,
                           struct vlc_access_cache_entry *entry)
 {
+#ifdef VLC_ACCESS_CACHE_CAN_REGISTER
     vlc_once(&cache->once, vlc_access_cache_InitOnce, cache);
+#endif
 
     vlc_mutex_lock(&cache->lock);
 
+#ifdef VLC_ACCESS_CACHE_CAN_REGISTER
     if (!cache->running)
     {
         vlc_mutex_unlock(&cache->lock);
@@ -154,6 +157,7 @@ vlc_access_cache_AddEntry(struct vlc_access_cache *cache,
         vlc_access_cache_entry_Delete(entry);
         return;
     }
+#endif
 
     struct vlc_access_cache_entry *it;
     size_t count = 0;
@@ -171,7 +175,9 @@ vlc_access_cache_AddEntry(struct vlc_access_cache *cache,
     entry->timeout = vlc_tick_now() + VLC_ACCESS_CACHE_TTL;
     vlc_list_append(&entry->node, &cache->entries);
 
+#ifdef VLC_ACCESS_CACHE_CAN_REGISTER
     vlc_cond_signal(&cache->cond);
+#endif
     vlc_mutex_unlock(&cache->lock);
 }
 
@@ -179,7 +185,9 @@ struct vlc_access_cache_entry *
 vlc_access_cache_GetEntry(struct vlc_access_cache *cache,
                           const char *url, const char *username)
 {
+#ifdef VLC_ACCESS_CACHE_CAN_REGISTER
     vlc_once(&cache->once, vlc_access_cache_InitOnce, cache);
+#endif
 
     vlc_mutex_lock(&cache->lock);
 
@@ -193,7 +201,9 @@ vlc_access_cache_GetEntry(struct vlc_access_cache *cache,
          && (username != NULL ? strcmp(username, it->username) == 0 : true))
         {
             vlc_list_remove(&it->node);
+#ifdef VLC_ACCESS_CACHE_CAN_REGISTER
             vlc_cond_signal(&cache->cond);
+#endif
             vlc_mutex_unlock(&cache->lock);
             return it;
         }


=====================================
modules/access/cache.h
=====================================
@@ -38,17 +38,26 @@ struct vlc_access_cache_entry
     struct vlc_list node;
 };
 
+#ifdef __has_attribute
+  #if __has_attribute(destructor)
+    #define VLC_ACCESS_CACHE_CAN_REGISTER
+  #endif
+#endif
+
 struct vlc_access_cache
 {
-    vlc_once_t once;
     vlc_mutex_t lock;
+#ifdef VLC_ACCESS_CACHE_CAN_REGISTER
+    vlc_once_t once;
     vlc_cond_t cond;
     vlc_thread_t thread;
     bool running;
+#endif
 
     struct vlc_list entries;
 };
 
+#ifdef VLC_ACCESS_CACHE_CAN_REGISTER
 #define VLC_ACCESS_CACHE_INITIALIZER(name) { \
     .once = VLC_STATIC_ONCE, \
     .lock = VLC_STATIC_MUTEX, \
@@ -56,6 +65,12 @@ struct vlc_access_cache
     .running = false, \
     .entries = VLC_LIST_INITIALIZER(&name.entries), \
 }
+#else
+#define VLC_ACCESS_CACHE_INITIALIZER(name) { \
+    .lock = VLC_STATIC_MUTEX, \
+    .entries = VLC_LIST_INITIALIZER(&name.entries), \
+}
+#endif
 
 static inline char *
 vlc_access_cache_entry_CreateSmbUrl(const char *server, const char *share)
@@ -89,9 +104,6 @@ vlc_access_cache_entry_NewSmb(void *context, const char *server,
 void
 vlc_access_cache_entry_Delete(struct vlc_access_cache_entry *entry);
 
-void
-vlc_access_cache_Destroy(struct vlc_access_cache *cache);
-
 void
 vlc_access_cache_AddEntry(struct vlc_access_cache *cache,
                           struct vlc_access_cache_entry *entry);
@@ -116,13 +128,10 @@ vlc_access_cache_GetSmbEntry(struct vlc_access_cache *cache,
     return entry;
 }
 
-#ifdef __has_attribute
-  #if __has_attribute(destructor)
-    #define VLC_ACCESS_CACHE_CAN_REGISTER
-  #endif
-#endif
-
 #ifdef VLC_ACCESS_CACHE_CAN_REGISTER
+void
+vlc_access_cache_Destroy(struct vlc_access_cache *cache);
+
 #define VLC_ACCESS_CACHE_REGISTER(name) \
 static struct vlc_access_cache name = VLC_ACCESS_CACHE_INITIALIZER(name); \
 __attribute__((destructor)) static void vlc_access_cache_destructor_##name(void) \



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/c6d72dffefea44d3aaf71b2c66f3ccbc3d66ce06

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/c6d72dffefea44d3aaf71b2c66f3ccbc3d66ce06
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list