Changeset 58

Show
Ignore:
Timestamp:
06/26/10 13:10:39 (4 years ago)
Author:
wez
Message:

move umem_startup constructor to the umem .so itself, rather than
the malloc replacement.

Rename ec_atomic to umem_atomic.

Add a posix_memalign function.

-ldl isn't universal; make a configure check for it.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Makefile.am

    r45 r58  
    22noinst_PROGRAMS = umem_test umem_test2 umem_test3 
    33 
    4 libumem_la_LDFLAGS = -lpthread -ldl 
     4libumem_la_LDFLAGS = -lpthread 
    55 
    66umem_test_SOURCES = umem_test.c 
     
    3737 
    3838libumem_malloc_la_SOURCES = malloc.c 
    39 libumem_malloc_la_LDFLAGS = -lpthread -ldl -R$(libdir) -lumem  
     39libumem_malloc_la_LDFLAGS = -lpthread -R$(libdir) -lumem  
    4040 
    4141man3_MANS = umem_alloc.3 umem_cache_create.3 umem_debug.3 
  • trunk/configure.ac

    r54 r58  
    2222)  
    2323 
     24AC_CHECK_LIB(dl,dlopen) 
    2425 
    2526AC_CHECK_HEADERS([sys/mman.h sys/sysmacros.h sys/time.h malloc.h]) 
  • trunk/malloc.c

    r57 r58  
    227227} 
    228228 
     229int 
     230posix_memalign(void **memptr, size_t alignment, size_t size) 
     231{ 
     232        *memptr = memalign(alignment, size); 
     233        if (*memptr) { 
     234                return 0; 
     235        } 
     236        return errno; 
     237} 
     238 
    229239void * 
    230240valloc(size_t size) 
     
    398408                return (malloc(newsize)); 
    399409 
     410        if (newsize == 0) { 
     411                free(buf_arg); 
     412                return (NULL); 
     413        } 
     414 
    400415        /* 
    401416         * get the old data size without freeing the buffer 
     
    418433} 
    419434 
    420 void __attribute__((constructor)) 
    421 __malloc_umem_init (void) 
    422 
    423         umem_startup(NULL, 0, 0, NULL, NULL); 
    424 
    425  
     435 
  • trunk/sol_compat.h

    r52 r58  
    110110 
    111111#ifdef ECELERITY 
    112 # include "ec_atomic.h" 
     112# include "umem_atomic.h" 
    113113#else 
    114114# ifdef _WIN32 
    115 #  define ec_atomic_inc(a)            InterlockedIncrement(a) 
    116 #  define ec_atomic_inc64(a)    InterlockedIncrement64(a) 
     115#  define umem_atomic_inc(a)          InterlockedIncrement(a) 
     116#  define umem_atomic_inc64(a)    InterlockedIncrement64(a) 
    117117# elif defined(__MACH__) 
    118118#  include <libkern/OSAtomic.h> 
    119 #  define ec_atomic_inc(x) OSAtomicIncrement32Barrier((int32_t*)x) 
     119#  define umem_atomic_inc(x) OSAtomicIncrement32Barrier((int32_t*)x) 
    120120#  if !defined(__ppc__) 
    121 #   define ec_atomic_inc64(x) OSAtomicIncrement64Barrier((int64_t*)x) 
     121#   define umem_atomic_inc64(x) OSAtomicIncrement64Barrier((int64_t*)x) 
    122122#  endif 
    123123# elif (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__) 
    124 static INLINE uint_t ec_atomic_cas(uint_t *mem, uint_t with, uint_t cmp) 
     124static INLINE uint_t umem_atomic_cas(uint_t *mem, uint_t with, uint_t cmp) 
    125125{ 
    126126  uint_t prev; 
     
    131131  return prev; 
    132132} 
    133 static INLINE uint64_t ec_atomic_cas64(uint64_t *mem, uint64_t with, 
     133static INLINE uint64_t umem_atomic_cas64(uint64_t *mem, uint64_t with, 
    134134  uint64_t cmp) 
    135135{ 
     
    154154  return prev; 
    155155} 
    156 static INLINE uint64_t ec_atomic_inc64(uint64_t *mem) 
     156static INLINE uint64_t umem_atomic_inc64(uint64_t *mem) 
    157157{ 
    158158  register uint64_t last; 
    159159  do { 
    160160    last = *mem; 
    161   } while (ec_atomic_cas64(mem, last+1, last) != last); 
     161  } while (umem_atomic_cas64(mem, last+1, last) != last); 
    162162  return ++last; 
    163163} 
    164 #  define ec_atomic_inc64 ec_atomic_inc64 
     164#  define umem_atomic_inc64 umem_atomic_inc64 
    165165# else 
    166166#  error no atomic solution for your platform 
    167167# endif 
    168168 
    169 # ifndef ec_atomic_inc 
    170 static INLINE uint_t ec_atomic_inc(uint_t *mem) 
     169# ifndef umem_atomic_inc 
     170static INLINE uint_t umem_atomic_inc(uint_t *mem) 
    171171{ 
    172172  register uint_t last; 
    173173  do { 
    174174    last = *mem; 
    175   } while (ec_atomic_cas(mem, last+1, last) != last); 
     175  } while (umem_atomic_cas(mem, last+1, last) != last); 
    176176  return ++last; 
    177177} 
    178178# endif 
    179 # ifndef ec_atomic_inc64 
     179# ifndef umem_atomic_inc64 
    180180   /* yeah, it's not great.  It's only used to bump failed allocation 
    181181    * counts, so it is not critical right now. */ 
    182182extern pthread_mutex_t umem_ppc_64inc_lock; 
    183 static INLINE uint64_t ec_atomic_inc64(uint64_t *val) 
     183static INLINE uint64_t umem_atomic_inc64(uint64_t *val) 
    184184{ 
    185185  uint64_t rval; 
     
    190190  return rval; 
    191191} 
    192 #  define ec_atomic_inc64 ec_atomic_inc64 
     192#  define umem_atomic_inc64 umem_atomic_inc64 
    193193#  define NEED_64_LOCK 1 
    194194# endif 
     
    208208 
    209209/* beware! umem only uses these atomic adds for incrementing by 1 */ 
    210 #define atomic_add_64(lvalptr, delta) ec_atomic_inc64(lvalptr) 
    211 #define atomic_add_32_nv(a, b)            ec_atomic_inc(a)  
     210#define atomic_add_64(lvalptr, delta) umem_atomic_inc64(lvalptr) 
     211#define atomic_add_32_nv(a, b)            umem_atomic_inc(a)  
    212212 
    213213#ifndef NANOSEC 
  • trunk/umem.c

    r56 r58  
    31943194        return (0); 
    31953195} 
     3196 
     3197void __attribute__((constructor)) 
     3198__umem_init (void) 
     3199{ 
     3200        umem_startup(NULL, 0, 0, NULL, NULL); 
     3201} 
     3202