Fix issue 311

This commit is contained in:
bossiel 2013-08-18 21:19:41 +00:00
parent 2b7fb7540f
commit b0ff29b39e
3 changed files with 20 additions and 4 deletions

View File

@ -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])

View File

@ -26,6 +26,10 @@
#include "tsk_debug.h"
#include "tsk_common.h"
#if TSK_UNDER_WINDOWS
# include <windows.h>
#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;
}

View File

@ -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.