1/*
2 * Copyright 2009 Colin G��nther, coling@gmx.de
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5
6
7#include <compat/sys/systm.h>
8#include <compat/sys/kernel.h>
9#include <compat/sys/mutex.h>
10#include <compat/sys/condvar.h>
11
12#include "Condvar.h"
13
14
15int
16msleep(void* identifier, struct mtx* mutex, int priority,
17	const char* description, int timeout)
18{
19	int status;
20	struct cv sleep;
21
22	conditionPublish(&sleep, identifier, description);
23
24	// FreeBSD's msleep() does not allow the mutex to be NULL, but we
25	// do, as we implement some other functions like tsleep() with it.
26	if (mutex != NULL)
27		mtx_unlock(mutex);
28
29	status = publishedConditionTimedWait(identifier, timeout);
30
31	if (mutex != NULL)
32		mtx_lock(mutex);
33
34	conditionUnpublish(&sleep);
35
36	return status;
37}
38
39
40void
41wakeup(void* identifier)
42{
43	publishedConditionNotifyAll(identifier);
44}
45
46
47void
48wakeup_one(void* identifier)
49{
50	publishedConditionNotifyOne(identifier);
51}
52