mailing list of musl libc
 help / color / mirror / code / Atom feed
* Return value of kuser helper cas function
@ 2014-11-18  2:35 Rich Felker
  0 siblings, 0 replies; only message in thread
From: Rich Felker @ 2014-11-18  2:35 UTC (permalink / raw)
  To: Russell King - ARM Linux; +Cc: musl

As far as I can tell, the kuser helper compare-and-swap function
always returns testval-oldval. Is this a behavior that is or could be
made into a guarantee of the API? In musl we want a cas that returns
the old value, and the failure of kuser helper to provide this
currently has us using a second loop around the call to kuser, of the
form:

	for (;;) {
		if (!kuser_cas(testval, setval, ptr))
			return testval;
		if ((oldval = *ptr) != testval)
			return oldval;
	}

It's not safe to just read and return *ptr when the cas fails, because
another thread could race to change *ptr and thereby make it equal to
testval (so that the caller would wrongly infer the cas succeeded).

It would be much nicer if we could just do:

	return testval - kuser_cas(testval, setval, ptr);

and this appears to work, but it's not documented as working at
present.

Rich


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-18  2:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-18  2:35 Return value of kuser helper cas function Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).