Skip to content

Commit

Permalink
Revert "SGObject mutex to generic lock transition"
Browse files Browse the repository at this point in the history
This reverts commit ed18465.
  • Loading branch information
lisitsyn committed Aug 22, 2011
1 parent dfba7da commit 0020af8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 34 deletions.
8 changes: 2 additions & 6 deletions src/shogun/base/SGObject.cpp
Expand Up @@ -104,9 +104,7 @@ CSGObject::CSGObject()
{
init();
set_global_objects();
#ifdef HAVE_PTHREAD
PTHREAD_LOCK_INIT(m_ref_lock);
#endif
pthread_mutex_init(&m_ref_mutex, NULL);

SG_GCDEBUG("SGObject created (%p)\n", this);
}
Expand All @@ -122,9 +120,7 @@ CSGObject::~CSGObject()
{
SG_GCDEBUG("SGObject destroyed (%p)\n", this);

#ifdef HAVE_PTHREAD
PTHREAD_LOCK_DESTROY(m_ref_lock);
#endif
pthread_mutex_destroy(&m_ref_mutex);
unset_global_objects();
delete m_parameters;
delete m_model_selection_parameters;
Expand Down
47 changes: 19 additions & 28 deletions src/shogun/base/SGObject.h
Expand Up @@ -18,8 +18,13 @@
#include <shogun/base/Parallel.h>
#include <shogun/base/Version.h>

#ifdef HAVE_PTHREAD
#ifndef WIN32
#include <pthread.h>
#else
#define pthread_mutex_init(x)
#define pthread_mutex_destroy(x)
#define pthread_mutex_lock(x)
#define pthread_mutex_unlock(x)
#endif

/** \namespace shogun
Expand Down Expand Up @@ -91,14 +96,10 @@ class CSGObject
*/
inline int32_t ref()
{
#ifdef HAVE_PTHREAD
PTHREAD_LOCK(m_ref_lock);
#endif
pthread_mutex_lock(&m_ref_mutex);
++m_refcount;
SG_GCDEBUG("ref() refcount %ld obj %s (%p) increased\n", m_refcount, this->get_name(), this);
#ifdef HAVE_PTHREAD
PTHREAD_UNLOCK(m_ref_lock);
#endif
pthread_mutex_unlock(&m_ref_mutex);
return m_refcount;
}

Expand All @@ -108,14 +109,10 @@ class CSGObject
*/
inline int32_t ref_count()
{
#ifdef HAVE_PTHREAD
PTHREAD_LOCK(m_ref_lock);
#endif
pthread_mutex_lock(&m_ref_mutex);
int32_t count=m_refcount;
#ifdef HAVE_PTHREAD
PTHREAD_UNLOCK(m_ref_lock);
#endif
SG_GCDEBUG("ref_count(): refcount %d, obj %s (%p)\n", count, this->get_name(), this);
pthread_mutex_unlock(&m_ref_mutex);
return count;
}

Expand All @@ -126,24 +123,18 @@ class CSGObject
*/
inline int32_t unref()
{
#ifdef HAVE_PTHREAD
PTHREAD_LOCK(m_ref_lock);
#endif
pthread_mutex_lock(&m_ref_mutex);
if (m_refcount==0 || --m_refcount==0)
{
SG_GCDEBUG("unref() refcount %ld, obj %s (%p) destroying\n", m_refcount, this->get_name(), this);
#ifdef HAVE_PTHREAD
PTHREAD_UNLOCK(m_ref_lock);
#endif
pthread_mutex_unlock(&m_ref_mutex);
delete this;
return 0;
}
else
{
SG_GCDEBUG("unref() refcount %ld obj %s (%p) decreased\n", m_refcount, this->get_name(), this);
#ifdef HAVE_PTHREAD
PTHREAD_UNLOCK(m_ref_lock);
#endif
pthread_mutex_unlock(&m_ref_mutex);
return m_refcount;
}
}
Expand Down Expand Up @@ -262,10 +253,10 @@ class CSGObject
index_t get_modsel_param_index(const char* param_name);

#ifdef TRACE_MEMORY_ALLOCS
static void list_memory_allocs()
{
::list_memory_allocs();
}
static void list_memory_allocs()
{
::list_memory_allocs();
}
#endif

protected:
Expand Down Expand Up @@ -351,8 +342,8 @@ class CSGObject

int32_t m_refcount;

#ifdef HAVE_PTHREAD
PTHREAD_LOCK_T m_ref_lock;
#ifndef WIN32
pthread_mutex_t m_ref_mutex;
#endif
};
}
Expand Down

0 comments on commit 0020af8

Please sign in to comment.