GNOME Bugzilla – Bug 599954
Native RWLock implementation
Last modified: 2011-09-30 04:45:30 UTC
+++ This bug was initially created as a clone of Bug #585375 +++ I took up Wim's branch which added native RWLock and extended it to replace GStaticRWLock to use it. Patches follow
Created attachment 146453 [details] [review] gthread: add GRWMutex prototypes
Created attachment 146454 [details] [review] symbols: add new symbol too
Created attachment 146455 [details] [review] gthread: avoid locking in _get_mutex_impl When getting the mutex implementation of a static mutex, avoid taking the global lock every time but only take the lock when there was no mutex and we need to create one.
Created attachment 146456 [details] [review] gthread: rename functions to match static variants
Created attachment 146457 [details] [review] uhm, rename again, now it's consistent
Created attachment 146458 [details] [review] use native pthread rwlocks
Created attachment 146459 [details] [review] add some test apps.
Created attachment 146460 [details] [review] Initial implementation of native GStaticRWLock
Created attachment 146461 [details] [review] gthread.h: Fix g_static_rw_lock_* macros
Created attachment 146462 [details] [review] glib/gthread.h: *actually* use the shortcut for rw_lock access.
Created attachment 146463 [details] [review] glib: Re-insert old API functions to remain ABI compatible. Only code compiled against the new gthread.h will use the new native rwlock API. Old code will still be able to use the old symbols.
The commits are also available here : http://cgit.freedesktop.org/~bilboed/glib/log/?h=rwlock
Two small notes: AFAIK pthread_rwlock is a relatively new addition to Linux and I think POSIX too. Unless I am misreading you patch compat for systems where these calls do not exist/return ENOSYS is not kept. I personally don't care about breaking that compat at all, but maybe some legacy loving folks might complain. It might make sense to use pthread_rwlockattr_setkind_np() to make the rwlocks follow the same ordering protocol that was used in the old, fake locks.
I'll rework the patches to make the old fake rwlock to be the default implementation of GRWlock, that should work on all system afaict, including those that don't have pthread_rwlock. As for changing the ordering, it looks like we need the PTHREAD_RWLOCK_PREFER_WRITER_NP ordering. There's actually a initializer for that that we could use : PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP Not certain it's available on all systems though. Thanks for the comments
(In reply to comment #14) > There's actually a initializer for that that we could use : > PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP > > Not certain it's available on all systems though. The "NP" suffix means it is non-portable. So you need to #ifdef that, so that it is used only when it exists, like on Linux.
Edward, did you ever rework your patch series ?
Thanks for reminding me, got led astray by other parts. No, I still haven't reworked it.
Review of attachment 146455 [details] [review]: Committed this one
we have a native rwlock implementation now
> we have a native rwlock implementation now And some other very nice GThread cleanups, I an see. Thanks, for the effort!