[vlc-devel] commit: CacheName: inline and thread-safe ( Rémi Denis-Courmont )
git version control
git at videolan.org
Thu Sep 4 22:38:25 CEST 2008
vlc | branch: 0.9-bugfix | Rémi Denis-Courmont <rdenis at simphalempin.com> | Mon Sep 1 22:09:22 2008 +0300| [000bc0c4a535481a0bb6684b8d602ef59476533c] | committer: Rémi Denis-Courmont
CacheName: inline and thread-safe
(cherry picked from commit 674c2927885bb5b1570e54637764fb75051b1a84)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=000bc0c4a535481a0bb6684b8d602ef59476533c
---
src/modules/cache.c | 30 ++++++++++++------------------
1 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/src/modules/cache.c b/src/modules/cache.c
index c497dea..6cc8fc8 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -81,12 +81,19 @@
#ifdef HAVE_DYNAMIC_PLUGINS
static int CacheLoadConfig ( module_t *, FILE * );
static int CacheSaveConfig ( module_t *, FILE * );
-static char * CacheName ( void );
/* Sub-version number
* (only used to avoid breakage in dev version when cache structure changes) */
#define CACHE_SUBVERSION_NUM 3
+/* Format string for the cache filename */
+#define CACHENAME_FORMAT \
+ "plugins-%.2zx%.2zx%.2"PRIx8".dat"
+/* Magic for the cache filename */
+#define CACHENAME_VALUES \
+ sizeof(int), sizeof(void *), *(uint8_t *)&(uint16_t){ 0xbe1e }
+
+
/*****************************************************************************
* LoadPluginsCache: loads the plugins cache file
*****************************************************************************
@@ -113,8 +120,8 @@ void CacheLoad( vlc_object_t *p_this )
return;
}
- if( asprintf( &psz_filename, "%s"DIR_SEP"%s",
- psz_cachedir, CacheName() ) == -1 )
+ if( asprintf( &psz_filename, "%s"DIR_SEP CACHENAME_FORMAT,
+ psz_cachedir, CACHENAME_VALUES ) == -1 )
{
free( psz_cachedir );
return;
@@ -495,7 +502,8 @@ void CacheSave( vlc_object_t *p_this )
}
snprintf( psz_filename, sizeof( psz_filename ),
- "%s"DIR_SEP"%s", psz_cachedir, CacheName() );
+ "%s"DIR_SEP CACHENAME_FORMAT, psz_cachedir,
+ CACHENAME_VALUES );
free( psz_cachedir );
msg_Dbg( p_this, "writing plugins cache %s", psz_filename );
@@ -680,20 +688,6 @@ error:
}
/*****************************************************************************
- * CacheName: Return the cache file name for this platform.
- *****************************************************************************/
-static char *CacheName( void )
-{
- static char psz_cachename[32];
-
- /* Code int size, pointer size and endianness in the filename */
- int32_t x = 0xbe00001e;
- sprintf( psz_cachename, "plugins-%.2x%.2x%.2x.dat", (int)sizeof(int),
- (int)sizeof(void *), (unsigned int)((unsigned char *)&x)[0] );
- return psz_cachename;
-}
-
-/*****************************************************************************
* CacheMerge: Merge a cache module descriptor with a full module descriptor.
*****************************************************************************/
void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
More information about the vlc-devel
mailing list