Mercurial > mplayer.hg
changeset 31147:97660f5d9aef
Slightly reduce number of #ifs
author | reimar |
---|---|
date | Sun, 23 May 2010 22:26:10 +0000 |
parents | 78d11e186bfc |
children | 6957d78df897 |
files | stream/cache2.c |
diffstat | 1 files changed, 21 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/stream/cache2.c Sun May 23 22:09:40 2010 +0000 +++ b/stream/cache2.c Sun May 23 22:26:10 2010 +0000 @@ -279,13 +279,25 @@ return 1; } +static void *shared_alloc(int size) { +#if FORKED_CACHE + return shmem_alloc(size); +#else + return malloc(size); +#endif +} + +static void shared_free(void *ptr, int size) { +#if FORKED_CACHE + shmem_free(ptr, size); +#else + free(ptr); +#endif +} + static cache_vars_t* cache_init(int size,int sector){ int num; -#if FORKED_CACHE - cache_vars_t* s=shmem_alloc(sizeof(cache_vars_t)); -#else - cache_vars_t* s=malloc(sizeof(cache_vars_t)); -#endif + cache_vars_t* s=shared_alloc(sizeof(cache_vars_t)); if(s==NULL) return NULL; memset(s,0,sizeof(cache_vars_t)); @@ -295,18 +307,10 @@ }//32kb min_size s->buffer_size=num*sector; s->sector_size=sector; -#if FORKED_CACHE - s->buffer=shmem_alloc(s->buffer_size); -#else - s->buffer=malloc(s->buffer_size); -#endif + s->buffer=shared_alloc(s->buffer_size); if(s->buffer == NULL){ -#if FORKED_CACHE - shmem_free(s,sizeof(cache_vars_t)); -#else - free(s); -#endif + shared_free(s, sizeof(cache_vars_t)); return NULL; } @@ -327,16 +331,10 @@ s->cache_pid = 0; } if(!c) return; -#if !FORKED_CACHE - free(c->buffer); + shared_free(c->buffer, c->buffer_size); c->buffer = NULL; c->stream = NULL; - free(s->cache_data); -#else - shmem_free(c->buffer,c->buffer_size); - c->buffer = NULL; - shmem_free(s->cache_data,sizeof(cache_vars_t)); -#endif + shared_free(s->cache_data, sizeof(cache_vars_t)); s->cache_data = NULL; }