1 /* go-note.c -- implement notesleep, notewakeup and noteclear.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 /* A note is a one-time notification. noteclear clears the note.
8 notesleep waits for a call to notewakeup. notewakeup wakes up
9 every thread waiting on the note. */
11 #include "go-assert.h"
14 /* We use a single global lock and condition variable. It would be
15 better to use a futex on Linux. */
17 static pthread_mutex_t note_lock
= PTHREAD_MUTEX_INITIALIZER
;
18 static pthread_cond_t note_cond
= PTHREAD_COND_INITIALIZER
;
20 /* noteclear is called before any calls to notesleep or
24 runtime_noteclear (Note
* n
)
28 i
= pthread_mutex_lock (¬e_lock
);
33 i
= pthread_mutex_unlock (¬e_lock
);
37 /* Wait until notewakeup is called. */
40 runtime_notesleep (Note
* n
)
44 i
= pthread_mutex_lock (¬e_lock
);
49 i
= pthread_cond_wait (¬e_cond
, ¬e_lock
);
53 i
= pthread_mutex_unlock (¬e_lock
);
57 /* Wake up every thread sleeping on the note. */
60 runtime_notewakeup (Note
*n
)
64 i
= pthread_mutex_lock (¬e_lock
);
69 i
= pthread_cond_broadcast (¬e_cond
);
72 i
= pthread_mutex_unlock (¬e_lock
);