mailing list of musl libc
 help / color / mirror / code / Atom feed
23c62a3833ce0af9929887b6355d07457f1d1dd9 blob 1672 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 
#include "pthread_impl.h"
#include <threads.h>

static inline __cnd_t* __cnd_init(__cnd_t *c, __mtx_t *m) {
	if (c) {
		*c = (__cnd_t) {
			.rfs = 2,
			 .mtx = m,
			.wts = 1,
			.seq = 0,
		};
	}
	if (m) __mtx_addref(m);
	return c;
}

static inline void __cnd_delete(__cnd_t *c) __attribute__((nonnull(1)));

static inline void __cnd_delete(__cnd_t *c) {
	__mtx_unref(c->mtx);
	c->mtx = 0;
	free(c);
}

void __cnd_unref(__cnd_t *c) {
	if (a_fetch_add(&c->rfs, -1) == 1) {
		__cnd_delete(c);
	}
}

static inline __cnd_t* __cnd_getref_def(cnd_t *cond, __mtx_t* m, __cnd_t* def, int * seq)  __attribute__((nonnull(1,2)));

static inline __cnd_t* __cnd_getref_def(cnd_t *cond, __mtx_t* m, __cnd_t* def, int * seq) {
	__cnd_t * ret;
	/* Critical section protected by lock. */
	__lock(&cond->_cx_lock);
	ret = cond->_cx_cnd;
	if (ret) {
		if (m) {
			/* Has the cnd just been initialized? */
			if (!ret->mtx) {
				__mtx_addref(m);
				ret->mtx = m;
			/* If not, is it consistent with previous usage? */
			} else if (ret->mtx != m) {
				ret = 0;
				goto UNLOCK;
			}
		}
		++ret->wts;
		__cnd_addref(ret);
		*seq = ret->seq;
	} else if (def) {
		ret = def;
		cond->_cx_cnd = def;
	}
 UNLOCK:
	__unlock(&cond->_cx_lock);
	return ret;
}

__cnd_t* __cnd_getref(cnd_t *cond, __mtx_t * m, int * seq) {
	__cnd_t * ret = __cnd_getref_def(cond, m, 0, seq);
	if (!ret) {
		__cnd_t * new = __cnd_init(malloc(sizeof *ret), m);
		if (new) {
			ret = __cnd_getref_def(cond, m, new, seq);
			/* somebody sneaked in between the first and second call */
			if (ret != new) __cnd_delete(new);
		}
	}
	return ret;
}
debug log:

solving 749eaae ...
found 749eaae in https://inbox.vuxu.org/musl/1408049748.4951.134.camel@eris.loria.fr/

applying [1/1] https://inbox.vuxu.org/musl/1408049748.4951.134.camel@eris.loria.fr/
diff --git a/src/thread/__cnd_getref.c b/src/thread/__cnd_getref.c\r
new file mode 100644\r
index 0000000..749eaae\r

1:7: trailing whitespace.
#include "pthread_impl.h"\r
1:8: trailing whitespace.
#include <threads.h>\r
1:9: trailing whitespace.
\r
1:10: trailing whitespace.
static inline __cnd_t* __cnd_init(__cnd_t *c, __mtx_t *m) {\r
1:11: trailing whitespace.
	if (c) {\r
Checking patch src/thread/__cnd_getref.c...
Applied patch src/thread/__cnd_getref.c cleanly.
warning: squelched 68 whitespace errors
warning: 73 lines add whitespace errors.

index at:
100644 23c62a3833ce0af9929887b6355d07457f1d1dd9	src/thread/__cnd_getref.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).