Skip to content
Snippets Groups Projects
Commit c6d72dff authored by Steve Lhomme's avatar Steve Lhomme Committed by Jean-Baptiste Kempf
Browse files

access: cache: disable code not used without VLC_ACCESS_CACHE_CAN_REGISTER

parent 225e0c1e
No related branches found
No related tags found
1 merge request!1721access: cache: disable code not used without VLC_ACCESS_CACHE_CAN_REGISTER
Pipeline #208891 passed with stage
in 43 minutes and 19 seconds
......@@ -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;
}
......
......@@ -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) \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment