After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 483790 - Allow for instantiating a Glib::Mutex from a GMutex*
Allow for instantiating a Glib::Mutex from a GMutex*
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: threads
2.14.x
Other All
: Normal enhancement
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2007-10-05 15:57 UTC by Milosz Derezynski
Modified: 2012-07-26 08:08 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Implements the requested feature (786 bytes, patch)
2007-10-05 15:58 UTC, Milosz Derezynski
none Details | Review
patch: Glib::Threads:[Rec]Mutex: Add wrap() functions (2.77 KB, patch)
2012-06-25 18:16 UTC, Kjell Ahlstedt
none Details | Review

Description Milosz Derezynski 2007-10-05 15:57:25 UTC
We need the functionality mentioned in the summary for gstreamermm (http://svn.beep-media-player.org/gstreamermm/trunk), to allow glibmm API to be used with Gst locking stuff. Maybe someone else has use for it too :)
Comment 1 Milosz Derezynski 2007-10-05 15:58:14 UTC
Created attachment 96712 [details] [review]
Implements the requested feature
Comment 2 Murray Cumming 2007-10-05 16:14:41 UTC
I don't think the "typedef GMutex CType" is necessary and I don't think we do that elsewhere. It doesn't really even fit with the rest of the code in this class.

More importantly, I worry that you might need to think about ownership of the wrapped type. This will currently call g_mutex_free() in the destructor, but that's maybe not what you want if you are wrapping the result of something_get_mutex() with the something keeping ownership. You might want a "bool take_ownership" parameter in the constructor, as we do in some other classes. However, I think that would need a new boolean m_has_ownership member, breaking ABI.

If so, and if there is no way to associate a boolean with the underlying GMutex, you might need to derive your own MutexWithoutOwnership (or better named) that you can use in those cases. You'd have to make sure that application coders are never expected to delete it via the Glib::Mutex class, because the Glib::Mutex destructor is not virtual.

 
Comment 3 Murray Cumming 2008-08-06 06:23:20 UTC
Thoughts?
Comment 4 Milosz Derezynski 2008-09-16 03:17:07 UTC
I had the same idea regarding ownership with a MutexWithoutOwnership class, but this would be like you said a bad choice regarding the virtual dtor, which can be changed in a later release of glibmm but then we could as well make the change of a bool arg to Glib::Mutex regarding the ownership, so it all hinges on breaking the ABI.

Adding such a class temporarily would be, needless to say, very bad, since people would incorporate this in their code, and finally when a bool arg to Glib::Mutex(GMutex*) is introduced, well, I'll just stop here as it can be clearly seen that this is just BAD! :)

I'd argue for introducing the boolean parameter at the next ABI break, so far I have no better idea.
Comment 5 Kjell Ahlstedt 2012-06-05 06:54:54 UTC
Glib::Mutex is now deprecated. It has been replaced by Glib::Threads::Mutex.

Glib::Threads::Mutex contains
  GMutex gobject_;
instead of
  GMutex* gobject_;
which makes it impossible, I suppose, to add a constructor
  Mutex(GMutex* object, bool take_ownership);

It would be possible to add

  Glib::Threads::Mutex* Glib::Threads::wrap(GMutex* gobject)
  {
    return reinterpret_cast<Glib::Threads::Mutex*>(gobject);
  }

in analogy with

  Glib::Threads::Thread* Glib::Threads::wrap(GThread* gobject)
  {
    return reinterpret_cast<Glib::Threads::Thread*>(gobject);
  }

Is this a good or a bad idea?

What about "Glib::Threads::RecMutex* Glib::Threads::wrap(GRecMutex* gobject)"?

Is this functionality still needed, or is this bug obsolete?
I don't find the link in comment 0 very informative. Perhaps it does not link
to the same information as it did when the bug was filed?
Comment 6 Kjell Ahlstedt 2012-06-24 08:10:24 UTC
Adding José Alburquerque to the CC list.
This bug is said to be related to gstreamermm.
You are perhaps the right person to tell if it's obsolete or not?
Comment 7 José Alburquerque 2012-06-25 05:28:14 UTC
(In reply to comment #5)
> Is this functionality still needed, or is this bug obsolete?

The one member of the GstObject struct that this functionality would make accessible in C++ (via a getter method of the Gst::Object class) is the "lock" member which the GST_OBJECT_GET_LOCK() macro gets in C:
http://developer.gnome.org/gstreamer/0.10/GstObject.html#GST-CLASS-GET-LOCK:CAPS

I guess getting the lock would probably be useful to C++ programmers so this bug should still be addressed.
Comment 8 José Alburquerque 2012-06-25 05:31:16 UTC
The correct link to the GST_OBJECT_GET_LOCK() macro is:
http://developer.gnome.org/gstreamer/0.10/GstObject.html#GST-OBJECT-GET-LOCK:CAPS
Comment 9 Kjell Ahlstedt 2012-06-25 18:16:06 UTC
Created attachment 217232 [details] [review]
patch: Glib::Threads:[Rec]Mutex: Add wrap() functions

This patch adds wrap() functions for GMutex and GRecMutex, similar to the
wrap() function for GThread.

Only a wrap() function for GMutex is requested in the bug, but it seems
reasonable to treat GRecMutex in the same way as GMutex.
I have not made const versions of wrap(). A constant mutex is not very useful,
is it?
Comment 10 Kjell Ahlstedt 2012-07-03 08:32:23 UTC
Does the patch in comment 8 give gstreamermm what it needs?

Are those wrap() functions acceptable in glibmm?
It's an unusual kind of wrap() function. I think such wrap() functions are
possible only for a C++ class that contains exactly one non-static data member
and no virtual functions.
Comment 11 Kjell Ahlstedt 2012-07-03 08:34:51 UTC
(In reply to comment #10)
> comment 8

Shall be: comment 9.
Comment 12 Murray Cumming 2012-07-20 14:02:24 UTC
José, could you respond please.

However, it does seem worth checking if this is still appropriate in GStreamer 0.11 (git master, which will become GStreamer 1.0).
Comment 13 José Alburquerque 2012-07-23 04:50:23 UTC
Sorry for the delay; A few other things have required my attention.

The patch does provide gstreamermm with a way to address the issue.  Locking functionality is still present in GStreamer 0.11 so it would still be appropriate to address this for the future.
Comment 14 Kjell Ahlstedt 2012-07-26 08:08:46 UTC
I have pushed the patch in comment 9.