# HG changeset patch # User reimar # Date 1274653570 0 # Node ID 97660f5d9aef2acad58feec567b7efd3eeee63ab # Parent 78d11e186bfc1550816587cc511ea539b34d5f57 Slightly reduce number of #ifs diff -r 78d11e186bfc -r 97660f5d9aef stream/cache2.c --- 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; }