diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2009-10-29 12:51:16 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2009-10-29 12:51:16 +0800 |
commit | c8489d58d16573dd2d9d96c5c01b9194368de14b (patch) | |
tree | 02482a37105f7091f8b886b478ccd79451be4bc4 | |
parent | 735c87fd1993d71f3dea7e964651176bd9c82ab2 (diff) |
milkway: fixup object initialize/finalize
-rw-r--r-- | config.h.in | 163 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | milkway/Makefile.am | 4 | ||||
-rw-r--r-- | milkway/mw-connection-mgr.c | 3 | ||||
-rw-r--r-- | milkway/mw-object.c | 34 | ||||
-rw-r--r-- | milkway/mw-object.h | 36 |
6 files changed, 225 insertions, 21 deletions
diff --git a/config.h.in b/config.h.in index 0b6f186..74e5bbb 100644 --- a/config.h.in +++ b/config.h.in @@ -3,18 +3,114 @@ /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD +/* whether memory barriers are needed around atomic operations */ +#undef ATOMIC_OP_NEEDS_MEMORY_BARRIER + +/* Define to 1 if you have the `alarm' function. */ +#undef HAVE_ALARM + +/* Define to 1 if you have the <byteswap.h> header file. */ +#undef HAVE_BYTESWAP_H + +/* Define to 1 if you have the `clock_gettime' function. */ +#undef HAVE_CLOCK_GETTIME + +/* Define to 1 if you have the `ctime_r' function. */ +#undef HAVE_CTIME_R + /* Define to 1 if you have the <dlfcn.h> header file. */ #undef HAVE_DLFCN_H +/* Define to 1 if you have the `drand48' function. */ +#undef HAVE_DRAND48 + +/* Define to 1 if you have the <fcntl.h> header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the `feclearexcept' function. */ +#undef HAVE_FECLEAREXCEPT + +/* Define to 1 if you have the `fedisableexcept' function. */ +#undef HAVE_FEDISABLEEXCEPT + +/* Define to 1 if you have the `feenableexcept' function. */ +#undef HAVE_FEENABLEEXCEPT + +/* Define to 1 if you have the <fenv.h> header file. */ +#undef HAVE_FENV_H + +/* Define to 1 if you have the `ffs' function. */ +#undef HAVE_FFS + +/* Define to 1 if you have the `flockfile' function. */ +#undef HAVE_FLOCKFILE + /* Define to 1 if you have the `getisax' function. */ #undef HAVE_GETISAX +/* Define to 1 if you have the `gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + +/* Enable if your compiler supports the Intel __sync_* atomic primitives */ +#undef HAVE_INTEL_ATOMIC_PRIMITIVES + /* Define to 1 if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 if you have the <io.h> header file. */ +#undef HAVE_IO_H + +/* Define to 1 if you have the <libgen.h> header file. */ +#undef HAVE_LIBGEN_H + +/* Enable if you have libatomic-ops-dev installed */ +#undef HAVE_LIB_ATOMIC_OPS + +/* Define to 1 if you have the `link' function. */ +#undef HAVE_LINK + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#undef HAVE_MALLOC + +/* Define to 1 if you have the `memmove' function. */ +#undef HAVE_MEMMOVE + /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* Define to non-zero if your system has mkdir, and to 2 if your version of + mkdir requires a mode parameter */ +#undef HAVE_MKDIR + +/* Define to 1 if you have the `mmap' function. */ +#undef HAVE_MMAP + +/* Define if you have POSIX threads libraries and header files. */ +#undef HAVE_PTHREAD + +/* Define to 1 if your system has a GNU libc compatible `realloc' function, + and to 0 otherwise. */ +#undef HAVE_REALLOC + +/* Define to 1 if you have the `sched_getaffinity' function. */ +#undef HAVE_SCHED_GETAFFINITY + +/* Define to 1 if you have the <sched.h> header file. */ +#undef HAVE_SCHED_H + +/* Define to 1 if you have the `select' function. */ +#undef HAVE_SELECT + +/* Define to 1 if you have the <setjmp.h> header file. */ +#undef HAVE_SETJMP_H + +/* Define to 1 if you have the <signal.h> header file. */ +#undef HAVE_SIGNAL_H + /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H @@ -27,15 +123,42 @@ /* Define to 1 if you have the <string.h> header file. */ #undef HAVE_STRING_H +/* Define to 1 if you have the <sys/int_types.h> header file. */ +#undef HAVE_SYS_INT_TYPES_H + +/* Define to 1 if you have the <sys/mman.h> header file. */ +#undef HAVE_SYS_MMAN_H + +/* Define to 1 if you have the <sys/poll.h> header file. */ +#undef HAVE_SYS_POLL_H + +/* Define to 1 if you have the <sys/socket.h> header file. */ +#undef HAVE_SYS_SOCKET_H + /* Define to 1 if you have the <sys/stat.h> header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the <sys/types.h> header file. */ #undef HAVE_SYS_TYPES_H +/* Define to 1 if you have the <sys/un.h> header file. */ +#undef HAVE_SYS_UN_H + +/* Define to 1 if you have the <time.h> header file. */ +#undef HAVE_TIME_H + +/* Define to 1 if the system has the type `uint64_t'. */ +#undef HAVE_UINT64_T + /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have the `vasnprintf' function. */ +#undef HAVE_VASNPRINTF + +/* Define to 1 if you have the <windows.h> header file. */ +#undef HAVE_WINDOWS_H + /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #undef LT_OBJDIR @@ -61,12 +184,35 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +#undef PTHREAD_CREATE_JOINABLE + +/* The size of `int', as computed by sizeof. */ +#undef SIZEOF_INT + +/* The size of `long', as computed by sizeof. */ +#undef SIZEOF_LONG + +/* The size of `long long', as computed by sizeof. */ +#undef SIZEOF_LONG_LONG + +/* The size of `size_t', as computed by sizeof. */ +#undef SIZEOF_SIZE_T + +/* The size of `void *', as computed by sizeof. */ +#undef SIZEOF_VOID_P + /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Version number of package */ #undef VERSION +/* Define to the value your compiler uses to support the warn-unused-result + attribute */ +#undef WARN_UNUSED_RESULT + /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ #if defined AC_APPLE_UNIVERSAL_BUILD @@ -79,8 +225,25 @@ # endif #endif + +/* Deal with multiple architecture compiles on Mac OS X */ +#ifdef __APPLE_CC__ +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN 1 +#else +#undef WORDS_BIGENDIAN +#endif +#endif + + /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ #ifndef __cplusplus #undef inline #endif + +/* Define to rpl_malloc if the replacement function should be used. */ +#undef malloc + +/* Define to rpl_realloc if the replacement function should be used. */ +#undef realloc diff --git a/configure.ac b/configure.ac index 9866161..93cf02e 100644 --- a/configure.ac +++ b/configure.ac @@ -146,8 +146,7 @@ AC_CHECK_LIBM LIBS="$LIBS $LIBM" AC_CHECK_LIB(rt, sched_yield, [RT_LIBS=-lrt], [RT_LIBS=]) -MILKWAYPERF_LIBS=$RT_LIBS -AC_SUBST(MILKWAYPERF_LIBS) +MILKWAY_LIBS="$MILKWAY_LIBS $RT_LIBS" has_shm_open= AC_CHECK_LIB(rt, shm_open, [ @@ -307,6 +306,7 @@ WARN_CFLAGS="$milkway_cv_warn_cflags" MILKWAY_CFLAGS="$MILKWAY_CFLAGS $WARN_CFLAGS" AC_SUBST(WARN_CFLAGS) AC_SUBST(MILKWAY_CFLAGS) +AC_SUBST(MILKWAY_LIBS) # We only wish to enable attribute(warn_unused_result) if we can prevent # gcc from generating thousands of warnings about the misapplication of the @@ -328,6 +328,8 @@ AC_CHECK_HEADERS(dlfcn.h, [have_dlsym=yes], [have_dlsym=no]) AM_CONDITIONAL(MILKWAY_HAS_DL, test "x$have_dl" = "xyes") ACX_PTHREAD +MILKWAY_LIBS="$MILKWAY_LIBS $PTHREAD_LIBS" +MILKWAY_CFLAGS="$MILKWAY_CFLAGS $PTHREAD_CFLAGS" AC_ARG_ENABLE(gtk, [AC_HELP_STRING([--enable-gtk], diff --git a/milkway/Makefile.am b/milkway/Makefile.am index ba15738..7c05a9f 100644 --- a/milkway/Makefile.am +++ b/milkway/Makefile.am @@ -22,8 +22,8 @@ milkway_headers = \ mw-connection-mgr.h libmilkway_la_LDFLAGS = -version-info $(LT_VERSION_INFO) -no-undefined -libmilkway_la_LIBADD = @DEP_LIBS@ -libmilkway_la_CFLAGS = -I$(top_srcdir)/milkway -I$(top_srcdir) $(MILKWAY_CFLAGS) +libmilkway_la_LIBADD = @DEP_LIBS@ $(PTHREAD_LIBS) +libmilkway_la_CFLAGS = -I$(top_srcdir)/milkway -I$(top_srcdir) $(MILKWAY_CFLAGS) $(PTHREAD_CFLAGS) libmilkway_la_SOURCES = \ $(milkway_headers) \ milkwayint.h \ diff --git a/milkway/mw-connection-mgr.c b/milkway/mw-connection-mgr.c index e1aac57..14105c8 100644 --- a/milkway/mw-connection-mgr.c +++ b/milkway/mw-connection-mgr.c @@ -69,7 +69,6 @@ mw_connection_mgr_type_init(mw_connection_mgr_type_t *type, { type->base.finalize = mw_connection_mgr_finalize; } -#if 0 + MW_DEFINE_GET_TYPE(mw_connection_mgr, mw_connection_mgr_type_t, MW_OBJECT_TYPE, "mwconnectionmgr", 0); -#endif diff --git a/milkway/mw-object.c b/milkway/mw-object.c index d6aaeb1..bc092ef 100644 --- a/milkway/mw-object.c +++ b/milkway/mw-object.c @@ -87,8 +87,6 @@ mw_object_unref(void *self) void mw_object_default_dispose(mw_object_t *self) { - if (MW_SUPER_TYPE_CAST(self, mw_object_type_t)) - MW_SUPER_TYPE_CAST(self, mw_object_type_t)->dispose(self); } static void @@ -102,8 +100,38 @@ mw_object_get_type(void) { static mw_object_type_t type = { NULL, "mwobject", sizeof(mw_object_t), sizeof(mw_object_type_t), 0, 0, - mw_object_default_dispose, mw_object_finalize + mw_object_default_dispose, mw_object_finalize, MW_TRUE }; return &type; } + +void +mw_object_init_type(mw_object_type_t *type, + mw_object_type_t *parent, + const char *name, + size_t type_size, + size_t priv_size, + mw_object_type_init_func_t func) +{ + static mw_static_mutex_t mutex = MW_STATIC_MUTEX_INIT; + + mw_thread_init(); + + mw_static_mutex_lock(&mutex); + + if (type->initialized) + goto initalized; + + memcpy (type, parent, parent->type_size); + type->name = name; + type->type_size = type_size; + type->priv_size = priv_size; + type->priv_offset = parent->priv_offset + MW_PRIV_ALIGN(parent->priv_size); + type->parent = parent; + func (type); + type->initialized = MW_TRUE; + + initalized: + mw_static_mutex_unlock(&mutex); +} diff --git a/milkway/mw-object.h b/milkway/mw-object.h index 841dccf..d202eaa 100644 --- a/milkway/mw-object.h +++ b/milkway/mw-object.h @@ -36,6 +36,8 @@ struct mw_object_type { void (*finalize)(mw_object_t *self); + + mw_bool_t initialized; }; #define MW_OBJECT_MAGIC 0x6d776f62 @@ -54,28 +56,30 @@ struct mw_object { #define MW_GET_PRIV(self, type) ((char*)self + NW_TYPE(self)->size + \ (mw_object_type_t*)(type)->priv_offset) +typedef void (*mw_object_type_init_func_t)(mw_object_type_t*); + #define MW_DEFINE_GET_TYPE(objname, type_name, parent_type, dsc_name, priv_size) \ type_name* \ objname ## _get_type(void) \ { \ - static type_name __type; \ + static union { \ + mw_object_type_t base; \ + type_name type; \ + } __type = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; \ static mw_bool_t init = MW_FALSE; \ \ if (!init) { \ - mw_object_type_t *parent = parent_type; \ - mw_object_type_t *__base = (mw_object_type_t*)&__type; \ + mw_object_type_t *__parent = (mw_object_type_t*)parent_type; \ + mw_object_type_t *__base = (mw_object_type_t*)&__type.type; \ \ - memcpy(&__type, parent, parent->type_size); \ - __base->name = dsc_name; \ - __base->type_size = sizeof(type_name); \ - __base->priv_size = priv_size; \ - __base->priv_offset = parent->priv_offset + \ - MW_PRIV_ALIGN(parent->priv_size); \ - __base->parent = parent; \ - objname ## _type_init (&__type, parent); \ + mw_object_init_type(__base, __parent, \ + dsc_name, sizeof(type_name), \ + priv_size, \ + (mw_object_type_init_func_t) \ + objname ## _type_init); \ init = MW_TRUE; \ } \ - return &__type; \ + return &__type.type; \ } mw_public mw_object_type_t* @@ -96,4 +100,12 @@ mw_object_unref(void *self); mw_public void mw_object_default_dispose(mw_object_t *self); +mw_public void +mw_object_init_type(mw_object_type_t *type, + mw_object_type_t *parent, + const char *name, + size_t type_size, + size_t priv_size, + mw_object_type_init_func_t func); + #endif |