svn commit: r201549 - in user/kmacy/releng_8_rump/lib/libunet: .
include/sys
Kip Macy
kmacy at FreeBSD.org
Tue Jan 5 05:37:50 UTC 2010
Author: kmacy
Date: Tue Jan 5 05:37:49 2010
New Revision: 201549
URL: http://svn.freebsd.org/changeset/base/201549
Log:
implement kernel condvar wrappers for pthread condvars
Added:
user/kmacy/releng_8_rump/lib/libunet/include/sys/
user/kmacy/releng_8_rump/lib/libunet/include/sys/_lock.h (contents, props changed)
user/kmacy/releng_8_rump/lib/libunet/include/sys/condvar.h (contents, props changed)
Modified:
user/kmacy/releng_8_rump/lib/libunet/unet_kern_condvar.c
Added: user/kmacy/releng_8_rump/lib/libunet/include/sys/_lock.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/kmacy/releng_8_rump/lib/libunet/include/sys/_lock.h Tue Jan 5 05:37:49 2010 (r201549)
@@ -0,0 +1,42 @@
+/*-
+ * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Berkeley Software Design Inc's name may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SYS__LOCK_H_
+#define _SYS__LOCK_H_
+
+struct lock_object {
+ const char *lo_name; /* Individual lock name. */
+ u_int lo_flags;
+ u_int lo_data; /* General class specific data. */
+ struct witness *lo_witness; /* Data for witness. */
+ pthread_mutex_t lo_mutex;
+};
+
+#endif /* !_SYS__LOCK_H_ */
Added: user/kmacy/releng_8_rump/lib/libunet/include/sys/condvar.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/kmacy/releng_8_rump/lib/libunet/include/sys/condvar.h Tue Jan 5 05:37:49 2010 (r201549)
@@ -0,0 +1,79 @@
+/*-
+ * Copyright (c) 2000 Jake Burkholder <jake at freebsd.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SYS_CONDVAR_H_
+#define _SYS_CONDVAR_H_
+
+#ifndef LOCORE
+#include <sys/queue.h>
+
+struct lock_object;
+struct thread;
+
+TAILQ_HEAD(cv_waitq, thread);
+
+/*
+ * Condition variable. The waiters count is protected by the mutex that
+ * protects the condition; that is, the mutex that is passed to cv_wait*()
+ * and is held across calls to cv_signal() and cv_broadcast(). It is an
+ * optimization to avoid looking up the sleep queue if there are no waiters.
+ */
+struct cv {
+ const char *cv_description;
+ pthread_cond_t cv_cond;
+};
+
+void cv_init(struct cv *cvp, const char *desc);
+void cv_destroy(struct cv *cvp);
+
+void _cv_wait(struct cv *cvp, struct lock_object *lock);
+void _cv_wait_unlock(struct cv *cvp, struct lock_object *lock);
+int _cv_wait_sig(struct cv *cvp, struct lock_object *lock);
+int _cv_timedwait(struct cv *cvp, struct lock_object *lock, int timo);
+int _cv_timedwait_sig(struct cv *cvp, struct lock_object *lock, int timo);
+
+void cv_signal(struct cv *cvp);
+void cv_broadcastpri(struct cv *cvp, int pri);
+
+#define cv_wait(cvp, lock) \
+ _cv_wait((cvp), &(lock)->lock_object)
+#define cv_wait_unlock(cvp, lock) \
+ _cv_wait_unlock((cvp), &(lock)->lock_object)
+#define cv_wait_sig(cvp, lock) \
+ _cv_wait_sig((cvp), &(lock)->lock_object)
+#define cv_timedwait(cvp, lock, timo) \
+ _cv_timedwait((cvp), &(lock)->lock_object, (timo))
+#define cv_timedwait_sig(cvp, lock, timo) \
+ _cv_timedwait_sig((cvp), &(lock)->lock_object, (timo))
+
+#define cv_broadcast(cvp) cv_broadcastpri(cvp, 0)
+
+#define cv_wmesg(cvp) ((cvp)->cv_description)
+
+#endif /* !LOCORE */
+#endif /* _SYS_CONDVAR_H_ */
Modified: user/kmacy/releng_8_rump/lib/libunet/unet_kern_condvar.c
==============================================================================
--- user/kmacy/releng_8_rump/lib/libunet/unet_kern_condvar.c Tue Jan 5 04:07:30 2010 (r201548)
+++ user/kmacy/releng_8_rump/lib/libunet/unet_kern_condvar.c Tue Jan 5 05:37:49 2010 (r201549)
@@ -16,15 +16,18 @@ __FBSDID("$FreeBSD$");
#include <sys/sleepqueue.h>
#include <sys/resourcevar.h>
+#include <pthread.h>
+
/*
* Initialize a condition variable. Must be called before use.
*/
void
cv_init(struct cv *cvp, const char *desc)
{
-
+ pthread_condattr_t ca;
+
cvp->cv_description = desc;
- cvp->cv_waiters = 0;
+ pthread_cond_init(&cvp->cv_cond, &ca);
}
/*
@@ -34,14 +37,8 @@ cv_init(struct cv *cvp, const char *desc
void
cv_destroy(struct cv *cvp)
{
-#ifdef INVARIANTS
- struct sleepqueue *sq;
- sleepq_lock(cvp);
- sq = sleepq_lookup(cvp);
- sleepq_release(cvp);
- KASSERT(sq == NULL, ("%s: associated sleep queue non-empty", __func__));
-#endif
+ pthread_cond_destroy(&cvp->cv_cond);
}
/*
@@ -54,8 +51,8 @@ cv_destroy(struct cv *cvp)
void
_cv_wait(struct cv *cvp, struct lock_object *lock)
{
- panic("");
-
+
+ pthread_cond_wait(&cvp->cv_cond, &lock->lo_mutex);
}
/*
@@ -67,9 +64,8 @@ _cv_wait(struct cv *cvp, struct lock_obj
int
_cv_wait_sig(struct cv *cvp, struct lock_object *lock)
{
- panic("");
- return (0);
+ return (pthread_cond_wait(&cvp->cv_cond, &lock->lo_mutex));
}
/*
@@ -80,9 +76,19 @@ _cv_wait_sig(struct cv *cvp, struct lock
int
_cv_timedwait(struct cv *cvp, struct lock_object *lock, int timo)
{
- panic("");
-
- return (0);
+ struct timespec abstime;
+ int secs = timo/hz;
+ int nsecs = (timo%hz)*((1000*1000*1000)/hz);
+
+ abstime.tv_sec = secs;
+ abstime.tv_nsec = nsecs;
+
+ /* XXX
+ * how do we handle getting interrupted by a signal?
+ * set the sigmask?
+ */
+ return (pthread_cond_timedwait(&cvp->cv_cond, &lock->lo_mutex,
+ &abstime));
}
/*
@@ -94,9 +100,15 @@ _cv_timedwait(struct cv *cvp, struct loc
int
_cv_timedwait_sig(struct cv *cvp, struct lock_object *lock, int timo)
{
- panic("");
+ struct timespec abstime;
+ int secs = timo/hz;
+ int nsecs = (timo%hz)*((1000*1000*1000)/hz);
- return (0);
+ abstime.tv_sec = secs;
+ abstime.tv_nsec = nsecs;
+
+ return (pthread_cond_timedwait(&cvp->cv_cond, &lock->lo_mutex,
+ &abstime));
}
/*
@@ -106,6 +118,6 @@ _cv_timedwait_sig(struct cv *cvp, struct
void
cv_broadcastpri(struct cv *cvp, int pri)
{
- panic("");
-
+
+ pthread_cond_broadcast(&cvp->cv_cond);
}
More information about the svn-src-user
mailing list