make the build experience nicer outside of ecelerity.

Add a simple test app.
Note: we don't compile the malloc replacement component.
This commit is contained in:
Wez Furlong 2006-03-11 18:57:05 +00:00
parent ec9812105b
commit 855e068963
5 changed files with 92 additions and 13 deletions

View file

@ -1,4 +1,9 @@
lib_LTLIBRARIES = libumem.la
noinst_PROGRAMS = umem_test
umem_test_SOURCES = umem_test.c
umem_test_LDADD = -lumem -lpthread -ldl
libumem_la_SOURCES = init_lib.c \
umem_agent_support.c \
umem_fail.c \
@ -6,13 +11,14 @@ libumem_la_SOURCES = init_lib.c \
umem_update_thread.c \
vmem_mmap.c \
vmem_sbrk.c \
envvar.o \
getpcstack.o \
malloc.o \
misc.o \
vmem_base.o \
umem.o \
vmem.o
envvar.c \
getpcstack.c \
misc.c \
vmem_base.c \
umem.c \
vmem.c
# malloc.c \
# XXX: Standalone version?
# See <http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libumem/Makefile.com>

5
misc.c
View file

@ -49,7 +49,10 @@
#include <umem_impl.h>
#include "misc.h"
#ifdef ECELERITY
#include "util.h"
#endif
#define UMEM_ERRFD 2 /* goes to standard error */
#define UMEM_MAX_ERROR_SIZE 4096 /* error messages are truncated to this */
@ -80,7 +83,9 @@ umem_log_enter(const char *error_str, int serious)
char c;
looped = 0;
#ifdef ECELERITY
mem_printf(serious ? DCRITICAL : DINFO, "umem: %s", error_str);
#endif
(void) mutex_lock(&umem_error_lock);

View file

@ -11,9 +11,15 @@
#include <stdint.h>
#include <pthread.h>
#define INLINE inline
#define THR_RETURN void *
#define THR_API
#ifdef _WIN32
# define THR_RETURN DWORD
# define THR_API WINAPI
# define INLINE __inline
#else
# define THR_RETURN void *
# define THR_API
# define INLINE inline
#endif
#if defined(__MACH__) || defined(_WIN32)
#define NO_WEAK_SYMBOLS
@ -98,7 +104,41 @@ static INLINE int thr_create(void *stack_base,
# define RTLD_FIRST 0
#endif
/*#include "ec_atomic.h"*/
#ifdef ECELERITY
# include "ec_atomic.h"
#else
# ifdef _WIN32
# define ec_atomic_inc(a) InterlockedIncrement(a)
# define ec_atomic_inc64(a) InterlockedIncrement64(a)
# elif (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
static INLINE uint_t ec_atomic_cas(uint_t *mem, uint_t with, uint_t cmp)
{
uint_t prev;
asm volatile ("lock; cmpxchgl %1, %2"
: "=a" (prev)
: "r" (with), "m" (*(mem)), "0" (cmp)
: "memory");
return prev;
}
# endif
# ifndef ec_atomic_inc
static INLINE uint_t ec_atomic_inc(uint_t *mem)
{
register uint_t last;
do {
last = *mem;
} while (ec_atomic_cas(mem, last+1, last) != last);
return ++last;
}
# endif
# ifndef ec_atomic_inc64
/* yeah, it's not great. It's only used to bump failed allocation
* counts, so it is not critical right now. */
# define ec_atomic_inc64(a) (*a)++
# endif
#endif
#define P2PHASE(x, align) ((x) & ((align) - 1))
#define P2ALIGN(x, align) ((x) & -(align))
@ -139,4 +179,12 @@ static INLINE int __nthreads(void)
# define _LP64 1
#endif
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
# define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#endif

View file

@ -126,10 +126,11 @@ umem_panic(const char *format, ...)
if (format[strlen(format)-1] != '\n')
umem_error_enter("\n");
#ifdef ECELERITY
va_start(va, format);
/*ec_debug_vprintf(DCRITICAL, DMEM, format, va);*/
fvprintf(stderr, format, va);
ec_debug_vprintf(DCRITICAL, DMEM, format, va);
va_end(va);
#endif
print_stacktrace();

19
umem_test.c Normal file
View file

@ -0,0 +1,19 @@
#include "umem.h"
int main(int argc, char *argv[])
{
char *foo;
umem_startup(NULL, 0, 0, NULL, NULL);
foo = umem_alloc(32, UMEM_DEFAULT);
strcpy(foo, "hello there");
printf("Hello %s\n", foo);
umem_free(foo, 32);
return 0;
}