GMainLoop smart pointer: moved to GLibSupport.h

Better use a shared pointer for GMainLoop. Avoids errors with ref
counting when coping an eptr and boost::intrusive_ptr has the same low
overhead.
This commit is contained in:
Patrick Ohly 2011-12-21 14:10:08 +01:00
parent f88fe5acac
commit 31e61c7200
3 changed files with 12 additions and 7 deletions

View file

@ -251,7 +251,10 @@ class GLibTest : public CppUnit::TestFixture {
list<Event> events;
static const char *name = "GLibTest.out";
unlink(name);
GMainLoopPtr loop(g_main_loop_new(NULL, FALSE), "main loop");
GMainLoopCXX loop(g_main_loop_new(NULL, FALSE), false);
if (!loop) {
SE_THROW("could not allocate main loop");
}
GLibNotify notify(name, boost::bind(notifyCallback, boost::ref(events), _1, _2, _3));
{
events.clear();

View file

@ -106,6 +106,12 @@ SE_END_CXX
SE_GOBJECT_TYPE(GFile)
SE_GOBJECT_TYPE(GFileMonitor)
void inline intrusive_ptr_add_ref(GMainLoop *ptr) { g_main_loop_ref(ptr); }
void inline intrusive_ptr_release(GMainLoop *ptr) { g_main_loop_unref(ptr); }
SE_BEGIN_CXX
typedef boost::intrusive_ptr<GMainLoop> GMainLoopCXX;
SE_END_CXX
SE_BEGIN_CXX
/**

View file

@ -88,10 +88,6 @@ class UnrefGString {
public:
static void unref(gchar *ptr) { g_free(ptr); }
};
class UnrefGMainLoop {
public:
static void unref(GMainLoop *ptr) { g_main_loop_unref(ptr); }
};
#endif // HAVE_GLIB
/**
@ -214,10 +210,10 @@ template <class T> class arrayptr : public eptr<T, T, ArrayUnref<T> > {
};
#ifdef HAVE_GLIB
/** eptr for glib event handle */
/** eptr for glib event handle - not reference counted, owned by at most one instance */
typedef SmartPtr<guint, guint, UnrefGLibEvent> GLibEvent;
typedef SmartPtr<gchar *, gchar *, UnrefGString> GStringPtr;
typedef SmartPtr<GMainLoop *, GMainLoop *, UnrefGMainLoop> GMainLoopPtr;
// for GMainLoop see GLibSupport.h
#endif
SE_END_CXX