diff --git a/branches/2.0/doubango/configure.ac b/branches/2.0/doubango/configure.ac index 50bce914..6a67221d 100755 --- a/branches/2.0/doubango/configure.ac +++ b/branches/2.0/doubango/configure.ac @@ -6,7 +6,7 @@ # AC_PREREQ([2.0]) -AC_INIT(libdoubango, 2.0.988, doubango(at)googlegroups(dot)com) +AC_INIT(libdoubango, 2.0.989, doubango(at)googlegroups(dot)com) AM_INIT_AUTOMAKE AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) diff --git a/branches/2.0/doubango/tinySAK/src/tsk_object.c b/branches/2.0/doubango/tinySAK/src/tsk_object.c index b194bf0f..96f29b95 100644 --- a/branches/2.0/doubango/tinySAK/src/tsk_object.c +++ b/branches/2.0/doubango/tinySAK/src/tsk_object.c @@ -26,6 +26,10 @@ #include "tsk_debug.h" #include "tsk_common.h" +#if TSK_UNDER_WINDOWS +# include +#endif /* TSK_UNDER_WINDOWS */ + /**@defgroup tsk_object_group Base object implementation. * @brief Provides utility functions to ease Object Oriented Programming in C. */ @@ -37,6 +41,17 @@ static int tsk_objects_count = 0; # define TSK_DEBUG_OBJECTS 0 #endif +#ifdef __GNUC__ +# define tsk_atomic_inc(_ptr_) __sync_fetch_and_add((_ptr_), 1) +# define tsk_atomic_dec(_ptr_) __sync_fetch_and_sub((_ptr_), 1) +#elif defined(_MSC_VER) +# define tsk_atomic_inc(_ptr_) InterlockedIncrement((_ptr_)) +# define tsk_atomic_dec(_ptr_) InterlockedDecrement((_ptr_)) +#else +# define tsk_atomic_inc(_ptr_) ++(*(_ptr_)) +# define tsk_atomic_dec(_ptr_) --(*(_ptr_)) +#endif + /**@ingroup tsk_object_group * Creates new object. The object MUST be declared using @ref TSK_DECLARE_OBJECT macro. * @param objdef The object meta-data (definition). For more infomation see @ref tsk_object_def_t. @@ -159,7 +174,7 @@ tsk_object_t* tsk_object_ref(tsk_object_t *self) { tsk_object_header_t* objhdr = TSK_OBJECT_HEADER(self); if(objhdr && objhdr->refCount){ - objhdr->refCount++; + tsk_atomic_inc(&objhdr->refCount); return self; } return tsk_null; @@ -179,7 +194,8 @@ tsk_object_t* tsk_object_unref(tsk_object_t *self) if(self){ tsk_object_header_t* objhdr = TSK_OBJECT_HEADER(self); if(objhdr->refCount){ // If refCount is == 0 then, nothing should happen. - if(!--objhdr->refCount){ + tsk_atomic_dec(&objhdr->refCount); + if(!objhdr->refCount){ tsk_object_delete(self); return tsk_null; } diff --git a/branches/2.0/doubango/tinySAK/src/tsk_object.h b/branches/2.0/doubango/tinySAK/src/tsk_object.h index 9555bfdd..d1beb0f7 100644 --- a/branches/2.0/doubango/tinySAK/src/tsk_object.h +++ b/branches/2.0/doubango/tinySAK/src/tsk_object.h @@ -78,7 +78,7 @@ typedef void tsk_object_t; */ #define TSK_DECLARE_OBJECT \ const void* __def__; /**< Opaque data holding a pointer to the actual meta-data(size, constructor, destructor and comparator) */ \ - tsk_size_t refCount /**< Reference counter. */ + long refCount /**< Reference counter. */ /**@ingroup tsk_object_group * Internal macro to get the definition of the object.