[PATCH xserver 4/8] Create a threaded mechanism for input [v3]
Keith Packard
keithp at keithp.com
Sat Dec 12 15:20:47 PST 2015
Mark Kettenis <mark.kettenis at xs4all.nl> writes:
> It isn't odd, because PTHREAD_RECURSIVE_MUTEX_INITIALIZE isn't in the
> standard. You'll have to explicitly initialize the mutex with
> pthread_mutex_init() to get a recursive mutex.
Sigh. That's a pain in this case; the first use of the mutex occurs
before the DDX initializes the input thread. I'll use
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP where it exists, and fallback to
a test inside input_lock() that initializes the mutex on first
use. That's "safe" because the first use will always happen before the
input thread is started.
> You can always prove a point with an appropriately constructed
> microbenchmark ;). Seriously though, I do hope that the overhead of
> the recursive mutex isn't noticable in the Xorg input thread.
I was surprised at how bad the Linux recursive mutexes performed
compared with a thread-local counter, if you actually used recursion. In
the (we hope common) case where the mutex gets acquired only once, they
are the same.
Depth Recursive Counter
10 30.3ns 13.2ns
1 100.4ns 100.4ns
> Anyway, the diff below won't fly as
> PTHREAD_RECURSIVE_MUTEX_INITIALIZER isn't in the standard and
> therefore not widely available. On OpenBSD we don't even have
> PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, and supporting such a thing
> would be difficult.
That's unfortunate, but easy enough to work around with a bit of
conditional code.
Here's code which works only with recursive mutexes, initializing it
explicitly when PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is not available.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-Disable-input-thread-code-with-disable-input-thread..patch
Type: text/x-diff
Size: 6549 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20151212/3721ad99/attachment-0001.patch>
-------------- next part --------------
--
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 810 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20151212/3721ad99/attachment-0001.sig>
More information about the xorg-devel
mailing list