mailing list of musl libc
 help / color / mirror / code / Atom feed
6516e2e19f766d126b20fb6f31876a27dd467fdf blob 1826 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
#include "pthread_impl.h"

#include "__lock.h"

weak_alias(__lock_fast, __lock);
weak_alias(__unlock_fast, __unlock);
weak_alias(__unlock_requeue_fast, __unlock_requeue);

/* __unlock_requeue handles the case where we have a second futex
   queue to which the a waiting thread should be scheduled if shared
   is false. This is e.g the case when l is the futex of a condition
   variable and r is the one of a private mutex: if the mutex is
   private, it is more efficient to just insert the thread in the
   queue of that mutex, instead of waking him up and put it back to
   sleep immediately when trying to lock the mutex. */

void __unlock_requeue_slow(volatile int *l, volatile int *r, int shared)
{
	if (shared) __wake(l, 1, 1);
	else __syscall(SYS_futex, l, FUTEX_REQUEUE|__futex_private, 0, 1, r);
}


void __lock_slow(volatile int *l, int current)
{
	/* A first spin lock acquisition loop, for the case of
	   medium congestion. */
	for (unsigned i = 0; i < 10; ++i) {
		if (current < 0) current -= INT_MIN + 1;
		// assertion: current >= 0
		int val = a_cas(l, current, INT_MIN + (current + 1));
		if (val == current) return;
		current = val;
	}
	// Spinning failed, so mark ourselves as being inside the CS.
	current = a_fetch_add(l, 1) + 1;
	/* The main lock acquisition loop for heavy congestion. The only
	   change to the value performed inside that loop is a successful
	   lock via the CAS that acquires the lock. */
	for (;;) {
		/* We can only go into wait, if we know that somebody holds the
		   lock and will eventually wake us up, again. */
		if (current < 0) {
			__futexwait(l, current, 1);
			current -= INT_MIN + 1;
		}
		/* assertion: current > 0, because the count
		   includes us already. */
		int val = a_cas(l, current, INT_MIN + current);
		if (val == current) return;
		current = val;
	}
}
debug log:

solving 6516e2e1 ...
found 6516e2e1 in https://inbox.vuxu.org/musl/d42e6a32e05b15ffd0279eca8505d495b86e5874.1498228733.git.Jens.Gustedt@inria.fr/
found e612c6f9 in https://inbox.vuxu.org/musl/0ec8d5597db7fcc1090b7b2120e3d441624db68c.1498228733.git.Jens.Gustedt@inria.fr/
found 56092240 in https://inbox.vuxu.org/musl/868874$8aqkr1@mail2-relais-roc.national.inria.fr/ ||
	https://inbox.vuxu.org/musl/b03752f80540ecb4310c53f97e0834268b740ea5.1498228733.git.Jens.Gustedt@inria.fr/
found 0874c04a in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 0874c04a4c0a81a9fa0dc032479ec18cec81d8aa	src/thread/__lock.c

applying [1/4] https://inbox.vuxu.org/musl/868874$8aqkr1@mail2-relais-roc.national.inria.fr/
diff --git a/src/thread/__lock.c b/src/thread/__lock.c
index 0874c04a..56092240 100644

Checking patch src/thread/__lock.c...
Applied patch src/thread/__lock.c cleanly.

skipping https://inbox.vuxu.org/musl/b03752f80540ecb4310c53f97e0834268b740ea5.1498228733.git.Jens.Gustedt@inria.fr/ for 56092240
index at:
100644 5609224031980f025d96387e45de47197e0b184f	src/thread/__lock.c

applying [2/4] https://inbox.vuxu.org/musl/0ec8d5597db7fcc1090b7b2120e3d441624db68c.1498228733.git.Jens.Gustedt@inria.fr/
diff --git a/src/thread/__lock.c b/src/thread/__lock.c
index 56092240..e612c6f9 100644


applying [3/4] https://inbox.vuxu.org/musl/d42e6a32e05b15ffd0279eca8505d495b86e5874.1498228733.git.Jens.Gustedt@inria.fr/
diff --git a/src/thread/__lock.c b/src/thread/__lock.c
index e612c6f9..6516e2e1 100644

Checking patch src/thread/__lock.c...
Applied patch src/thread/__lock.c cleanly.
Checking patch src/thread/__lock.c...
Applied patch src/thread/__lock.c cleanly.

index at:
100644 6516e2e19f766d126b20fb6f31876a27dd467fdf	src/thread/__lock.c

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).