mailing list of musl libc
 help / color / mirror / code / Atom feed
dfdc5d10a0a0cde08211517f41d88daea43ff36d blob 1771 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
74
75
76
77
78
79
80
81
 
#include "pthread_impl.h"
#include <threads.h>

void __pthread_testcancel(void);

struct cm {
	cnd_t *c;
	mtx_t *m;
};

static void unwait(cnd_t *c, mtx_t *m)
{
	__THRD_ABI_MARK;
	/* Removing a waiter is non-trivial if we could be using requeue
	 * based broadcast signals, due to mutex access issues, etc. */

	while (a_swap(&c->_c_lock, 1))
		__wait(&c->_c_lock, &c->_c_lockwait, 1, 1);

	if (c->_c_waiters2) c->_c_waiters2--;
	else a_dec(&m->_m_waiters);

	a_store(&c->_c_lock, 0);
	if (c->_c_lockwait) __wake(&c->_c_lock, 1, 1);

	a_dec(&c->_c_waiters);
	if (c->_c_destroy) __wake(&c->_c_waiters, 1, 1);
}

static void cleanup(void *p)
{
	struct cm *cm = p;
	unwait(cm->c, cm->m);
	mtx_lock(cm->m);
}

int cnd_timedwait(cnd_t *restrict c, mtx_t *restrict m, const struct timespec *restrict ts)
{
	struct cm cm = { .c=c, .m=m };
	int r, e=0, seq;

	if (m->_m_type && (m->_m_lock&INT_MAX) != __pthread_self()->tid)
		return thrd_error;

	if (ts && ts->tv_nsec >= 1000000000UL)
		return thrd_error;

	__pthread_testcancel();

	a_inc(&c->_c_waiters);

	c->_c_mutex = m;
	while (a_swap(&c->_c_lock, 1))
		__wait(&c->_c_lock, &c->_c_lockwait, 1, 1);
	c->_c_waiters2++;
	a_store(&c->_c_lock, 0);
	if (c->_c_lockwait) __wake(&c->_c_lock, 1, 1);

	seq = c->_c_seq;

	mtx_unlock(m);

	do e = __timedwait(&c->_c_seq, seq, CLOCK_REALTIME, ts, cleanup, &cm, 0);
	while (c->_c_seq == seq && (!e || e==EINTR));
	if (e == EINTR) e = 0;

	unwait(c, m);

	if (mtx_lock(m) != thrd_success)
	 return thrd_error;

	switch (e) {
	case 0:
		if (thrd_success == 0) break;
		else return thrd_success;
	case ETIMEDOUT:
		if (thrd_timedout == ETIMEDOUT) break;
		else return thrd_timedout;
	}
        return e;
}
debug log:

solving 18db3ef ...
found 18db3ef in https://inbox.vuxu.org/musl/1407144603.8274.248.camel@eris.loria.fr/

applying [1/1] https://inbox.vuxu.org/musl/1407144603.8274.248.camel@eris.loria.fr/
diff --git a/src/thread/cnd_timedwait.c b/src/thread/cnd_timedwait.c\r
new file mode 100644\r
index 0000000..18db3ef\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.
void __pthread_testcancel(void);\r
1:11: trailing whitespace.
\r
Checking patch src/thread/cnd_timedwait.c...
Applied patch src/thread/cnd_timedwait.c cleanly.
warning: squelched 76 whitespace errors
warning: 81 lines add whitespace errors.

index at:
100644 dfdc5d10a0a0cde08211517f41d88daea43ff36d	src/thread/cnd_timedwait.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).