mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-13 11:59:33 +08:00
CONDVAR(9): Use FreeBSD implementation
This commit is contained in:
parent
8475e7aa0a
commit
50553bcd8e
2
Makefile
2
Makefile
@ -67,7 +67,6 @@ LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-bus-dma.c
|
||||
LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-bus-dma-mbuf.c
|
||||
LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-cam.c
|
||||
LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-chunk.c
|
||||
LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-condvar.c
|
||||
LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-conf.c
|
||||
LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-delay.c
|
||||
LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-ethernet-addr.c
|
||||
@ -164,6 +163,7 @@ freebsd/lib/libipsec/policy_parse.c: freebsd/lib/libipsec/policy_parse.y
|
||||
rm -f __libipsecyy.tab.c
|
||||
mv __libipsecyy.tab.h freebsd/lib/libipsec/y.tab.h
|
||||
LIB_C_FILES += freebsd/sys/kern/init_main.c
|
||||
LIB_C_FILES += freebsd/sys/kern/kern_condvar.c
|
||||
LIB_C_FILES += freebsd/sys/kern/kern_event.c
|
||||
LIB_C_FILES += freebsd/sys/kern/kern_hhook.c
|
||||
LIB_C_FILES += freebsd/sys/kern/kern_intr.c
|
||||
|
@ -667,7 +667,6 @@ rtems.addRTEMSSourceFiles(
|
||||
'rtems/rtems-bsd-bus-dma-mbuf.c',
|
||||
'rtems/rtems-bsd-cam.c',
|
||||
'rtems/rtems-bsd-chunk.c',
|
||||
'rtems/rtems-bsd-condvar.c',
|
||||
'rtems/rtems-bsd-conf.c',
|
||||
'rtems/rtems-bsd-delay.c',
|
||||
'rtems/rtems-bsd-get-ethernet-addr.c',
|
||||
@ -874,6 +873,7 @@ base.addKernelSpaceHeaderFiles(
|
||||
base.addKernelSpaceSourceFiles(
|
||||
[
|
||||
'sys/kern/init_main.c',
|
||||
'sys/kern/kern_condvar.c',
|
||||
'sys/kern/kern_event.c',
|
||||
'sys/kern/kern_hhook.c',
|
||||
'sys/kern/kern_intr.c',
|
||||
|
463
freebsd/sys/kern/kern_condvar.c
Normal file
463
freebsd/sys/kern/kern_condvar.c
Normal file
@ -0,0 +1,463 @@
|
||||
#include <machine/rtems-bsd-kernel-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 Jake Burkholder <jake@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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <rtems/bsd/local/opt_ktrace.h>
|
||||
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <rtems/bsd/sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/ktr.h>
|
||||
#include <sys/condvar.h>
|
||||
#include <sys/sched.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/sleepqueue.h>
|
||||
#include <sys/resourcevar.h>
|
||||
#ifdef KTRACE
|
||||
#include <sys/uio.h>
|
||||
#include <sys/ktrace.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Common sanity checks for cv_wait* functions.
|
||||
*/
|
||||
#define CV_ASSERT(cvp, lock, td) do { \
|
||||
KASSERT((td) != NULL, ("%s: td NULL", __func__)); \
|
||||
KASSERT(TD_IS_RUNNING(td), ("%s: not TDS_RUNNING", __func__)); \
|
||||
KASSERT((cvp) != NULL, ("%s: cvp NULL", __func__)); \
|
||||
KASSERT((lock) != NULL, ("%s: lock NULL", __func__)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Initialize a condition variable. Must be called before use.
|
||||
*/
|
||||
void
|
||||
cv_init(struct cv *cvp, const char *desc)
|
||||
{
|
||||
|
||||
cvp->cv_description = desc;
|
||||
cvp->cv_waiters = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy a condition variable. The condition variable must be re-initialized
|
||||
* in order to be re-used.
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait on a condition variable. The current thread is placed on the condition
|
||||
* variable's wait queue and suspended. A cv_signal or cv_broadcast on the same
|
||||
* condition variable will resume the thread. The mutex is released before
|
||||
* sleeping and will be held on return. It is recommended that the mutex be
|
||||
* held when cv_signal or cv_broadcast are called.
|
||||
*/
|
||||
void
|
||||
_cv_wait(struct cv *cvp, struct lock_object *lock)
|
||||
{
|
||||
WITNESS_SAVE_DECL(lock_witness);
|
||||
struct lock_class *class;
|
||||
struct thread *td;
|
||||
int lock_state;
|
||||
|
||||
td = curthread;
|
||||
lock_state = 0;
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(1, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
CV_ASSERT(cvp, lock, td);
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock,
|
||||
"Waiting on \"%s\"", cvp->cv_description);
|
||||
class = LOCK_CLASS(lock);
|
||||
|
||||
if (cold || panicstr) {
|
||||
/*
|
||||
* During autoconfiguration, just give interrupts
|
||||
* a chance, then just return. Don't run any other
|
||||
* thread or panic below, in case this is the idle
|
||||
* process and already asleep.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
sleepq_lock(cvp);
|
||||
|
||||
cvp->cv_waiters++;
|
||||
if (lock == &Giant.lock_object)
|
||||
mtx_assert(&Giant, MA_OWNED);
|
||||
DROP_GIANT();
|
||||
|
||||
sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR, 0);
|
||||
if (lock != &Giant.lock_object) {
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_release(cvp);
|
||||
WITNESS_SAVE(lock, lock_witness);
|
||||
lock_state = class->lc_unlock(lock);
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_lock(cvp);
|
||||
}
|
||||
sleepq_wait(cvp, 0);
|
||||
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(0, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
PICKUP_GIANT();
|
||||
if (lock != &Giant.lock_object) {
|
||||
class->lc_lock(lock, lock_state);
|
||||
WITNESS_RESTORE(lock, lock_witness);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait on a condition variable. This function differs from cv_wait by
|
||||
* not aquiring the mutex after condition variable was signaled.
|
||||
*/
|
||||
void
|
||||
_cv_wait_unlock(struct cv *cvp, struct lock_object *lock)
|
||||
{
|
||||
struct lock_class *class;
|
||||
struct thread *td;
|
||||
|
||||
td = curthread;
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(1, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
CV_ASSERT(cvp, lock, td);
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock,
|
||||
"Waiting on \"%s\"", cvp->cv_description);
|
||||
KASSERT(lock != &Giant.lock_object,
|
||||
("cv_wait_unlock cannot be used with Giant"));
|
||||
class = LOCK_CLASS(lock);
|
||||
|
||||
if (cold || panicstr) {
|
||||
/*
|
||||
* During autoconfiguration, just give interrupts
|
||||
* a chance, then just return. Don't run any other
|
||||
* thread or panic below, in case this is the idle
|
||||
* process and already asleep.
|
||||
*/
|
||||
class->lc_unlock(lock);
|
||||
return;
|
||||
}
|
||||
|
||||
sleepq_lock(cvp);
|
||||
|
||||
cvp->cv_waiters++;
|
||||
DROP_GIANT();
|
||||
|
||||
sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR, 0);
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_release(cvp);
|
||||
class->lc_unlock(lock);
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_lock(cvp);
|
||||
sleepq_wait(cvp, 0);
|
||||
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(0, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
PICKUP_GIANT();
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait on a condition variable, allowing interruption by signals. Return 0 if
|
||||
* the thread was resumed with cv_signal or cv_broadcast, EINTR or ERESTART if
|
||||
* a signal was caught. If ERESTART is returned the system call should be
|
||||
* restarted if possible.
|
||||
*/
|
||||
int
|
||||
_cv_wait_sig(struct cv *cvp, struct lock_object *lock)
|
||||
{
|
||||
#ifndef __rtems__
|
||||
WITNESS_SAVE_DECL(lock_witness);
|
||||
struct lock_class *class;
|
||||
struct thread *td;
|
||||
int lock_state, rval;
|
||||
|
||||
td = curthread;
|
||||
lock_state = 0;
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(1, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
CV_ASSERT(cvp, lock, td);
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock,
|
||||
"Waiting on \"%s\"", cvp->cv_description);
|
||||
class = LOCK_CLASS(lock);
|
||||
|
||||
if (cold || panicstr) {
|
||||
/*
|
||||
* After a panic, or during autoconfiguration, just give
|
||||
* interrupts a chance, then just return; don't run any other
|
||||
* procs or panic below, in case this is the idle process and
|
||||
* already asleep.
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
sleepq_lock(cvp);
|
||||
|
||||
cvp->cv_waiters++;
|
||||
if (lock == &Giant.lock_object)
|
||||
mtx_assert(&Giant, MA_OWNED);
|
||||
DROP_GIANT();
|
||||
|
||||
sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR |
|
||||
SLEEPQ_INTERRUPTIBLE, 0);
|
||||
if (lock != &Giant.lock_object) {
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_release(cvp);
|
||||
WITNESS_SAVE(lock, lock_witness);
|
||||
lock_state = class->lc_unlock(lock);
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_lock(cvp);
|
||||
}
|
||||
rval = sleepq_wait_sig(cvp, 0);
|
||||
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(0, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
PICKUP_GIANT();
|
||||
if (lock != &Giant.lock_object) {
|
||||
class->lc_lock(lock, lock_state);
|
||||
WITNESS_RESTORE(lock, lock_witness);
|
||||
}
|
||||
|
||||
return (rval);
|
||||
#else /* __rtems__ */
|
||||
_cv_wait(cvp, lock);
|
||||
|
||||
return (0);
|
||||
#endif /* __rtems__ */
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait on a condition variable for at most timo/hz seconds. Returns 0 if the
|
||||
* process was resumed by cv_signal or cv_broadcast, EWOULDBLOCK if the timeout
|
||||
* expires.
|
||||
*/
|
||||
int
|
||||
_cv_timedwait(struct cv *cvp, struct lock_object *lock, int timo)
|
||||
{
|
||||
WITNESS_SAVE_DECL(lock_witness);
|
||||
struct lock_class *class;
|
||||
struct thread *td;
|
||||
int lock_state, rval;
|
||||
|
||||
td = curthread;
|
||||
lock_state = 0;
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(1, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
CV_ASSERT(cvp, lock, td);
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock,
|
||||
"Waiting on \"%s\"", cvp->cv_description);
|
||||
class = LOCK_CLASS(lock);
|
||||
|
||||
if (cold || panicstr) {
|
||||
/*
|
||||
* After a panic, or during autoconfiguration, just give
|
||||
* interrupts a chance, then just return; don't run any other
|
||||
* thread or panic below, in case this is the idle process and
|
||||
* already asleep.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
sleepq_lock(cvp);
|
||||
|
||||
cvp->cv_waiters++;
|
||||
if (lock == &Giant.lock_object)
|
||||
mtx_assert(&Giant, MA_OWNED);
|
||||
DROP_GIANT();
|
||||
|
||||
sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR, 0);
|
||||
sleepq_set_timeout(cvp, timo);
|
||||
if (lock != &Giant.lock_object) {
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_release(cvp);
|
||||
WITNESS_SAVE(lock, lock_witness);
|
||||
lock_state = class->lc_unlock(lock);
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_lock(cvp);
|
||||
}
|
||||
rval = sleepq_timedwait(cvp, 0);
|
||||
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(0, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
PICKUP_GIANT();
|
||||
if (lock != &Giant.lock_object) {
|
||||
class->lc_lock(lock, lock_state);
|
||||
WITNESS_RESTORE(lock, lock_witness);
|
||||
}
|
||||
|
||||
return (rval);
|
||||
}
|
||||
|
||||
#ifndef __rtems__
|
||||
/*
|
||||
* Wait on a condition variable for at most timo/hz seconds, allowing
|
||||
* interruption by signals. Returns 0 if the thread was resumed by cv_signal
|
||||
* or cv_broadcast, EWOULDBLOCK if the timeout expires, and EINTR or ERESTART if
|
||||
* a signal was caught.
|
||||
*/
|
||||
int
|
||||
_cv_timedwait_sig(struct cv *cvp, struct lock_object *lock, int timo)
|
||||
{
|
||||
WITNESS_SAVE_DECL(lock_witness);
|
||||
struct lock_class *class;
|
||||
struct thread *td;
|
||||
int lock_state, rval;
|
||||
|
||||
td = curthread;
|
||||
lock_state = 0;
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(1, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
CV_ASSERT(cvp, lock, td);
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock,
|
||||
"Waiting on \"%s\"", cvp->cv_description);
|
||||
class = LOCK_CLASS(lock);
|
||||
|
||||
if (cold || panicstr) {
|
||||
/*
|
||||
* After a panic, or during autoconfiguration, just give
|
||||
* interrupts a chance, then just return; don't run any other
|
||||
* thread or panic below, in case this is the idle process and
|
||||
* already asleep.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
sleepq_lock(cvp);
|
||||
|
||||
cvp->cv_waiters++;
|
||||
if (lock == &Giant.lock_object)
|
||||
mtx_assert(&Giant, MA_OWNED);
|
||||
DROP_GIANT();
|
||||
|
||||
sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR |
|
||||
SLEEPQ_INTERRUPTIBLE, 0);
|
||||
sleepq_set_timeout(cvp, timo);
|
||||
if (lock != &Giant.lock_object) {
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_release(cvp);
|
||||
WITNESS_SAVE(lock, lock_witness);
|
||||
lock_state = class->lc_unlock(lock);
|
||||
if (class->lc_flags & LC_SLEEPABLE)
|
||||
sleepq_lock(cvp);
|
||||
}
|
||||
rval = sleepq_timedwait_sig(cvp, 0);
|
||||
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(td, KTR_CSW))
|
||||
ktrcsw(0, 0, cv_wmesg(cvp));
|
||||
#endif
|
||||
PICKUP_GIANT();
|
||||
if (lock != &Giant.lock_object) {
|
||||
class->lc_lock(lock, lock_state);
|
||||
WITNESS_RESTORE(lock, lock_witness);
|
||||
}
|
||||
|
||||
return (rval);
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
/*
|
||||
* Signal a condition variable, wakes up one waiting thread. Will also wakeup
|
||||
* the swapper if the process is not in memory, so that it can bring the
|
||||
* sleeping process in. Note that this may also result in additional threads
|
||||
* being made runnable. Should be called with the same mutex as was passed to
|
||||
* cv_wait held.
|
||||
*/
|
||||
void
|
||||
cv_signal(struct cv *cvp)
|
||||
{
|
||||
int wakeup_swapper;
|
||||
|
||||
wakeup_swapper = 0;
|
||||
sleepq_lock(cvp);
|
||||
if (cvp->cv_waiters > 0) {
|
||||
cvp->cv_waiters--;
|
||||
wakeup_swapper = sleepq_signal(cvp, SLEEPQ_CONDVAR, 0, 0);
|
||||
}
|
||||
sleepq_release(cvp);
|
||||
if (wakeup_swapper)
|
||||
kick_proc0();
|
||||
}
|
||||
|
||||
/*
|
||||
* Broadcast a signal to a condition variable. Wakes up all waiting threads.
|
||||
* Should be called with the same mutex as was passed to cv_wait held.
|
||||
*/
|
||||
void
|
||||
cv_broadcastpri(struct cv *cvp, int pri)
|
||||
{
|
||||
int wakeup_swapper;
|
||||
|
||||
/*
|
||||
* XXX sleepq_broadcast pri argument changed from -1 meaning
|
||||
* no pri to 0 meaning no pri.
|
||||
*/
|
||||
wakeup_swapper = 0;
|
||||
if (pri == -1)
|
||||
pri = 0;
|
||||
sleepq_lock(cvp);
|
||||
if (cvp->cv_waiters > 0) {
|
||||
cvp->cv_waiters = 0;
|
||||
wakeup_swapper = sleepq_broadcast(cvp, SLEEPQ_CONDVAR, pri, 0);
|
||||
}
|
||||
sleepq_release(cvp);
|
||||
if (wakeup_swapper)
|
||||
kick_proc0();
|
||||
}
|
@ -43,16 +43,9 @@ TAILQ_HEAD(cv_waitq, thread);
|
||||
* 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.
|
||||
*/
|
||||
#ifdef __rtems__
|
||||
#include <rtems/score/threadq.h>
|
||||
#endif /* __rtems__ */
|
||||
struct cv {
|
||||
const char *cv_description;
|
||||
#ifndef __rtems__
|
||||
int cv_waiters;
|
||||
#else /* __rtems__ */
|
||||
Thread_queue_Control cv_waiters;
|
||||
#endif /* __rtems__ */
|
||||
};
|
||||
|
||||
#ifdef _KERNEL
|
||||
@ -76,8 +69,13 @@ void cv_broadcastpri(struct cv *cvp, int pri);
|
||||
_cv_wait_sig((cvp), &(lock)->lock_object)
|
||||
#define cv_timedwait(cvp, lock, timo) \
|
||||
_cv_timedwait((cvp), &(lock)->lock_object, (timo))
|
||||
#ifndef __rtems__
|
||||
#define cv_timedwait_sig(cvp, lock, timo) \
|
||||
_cv_timedwait_sig((cvp), &(lock)->lock_object, (timo))
|
||||
#else /* __rtems__ */
|
||||
#define cv_timedwait_sig(cvp, lock, timo) \
|
||||
_cv_timedwait((cvp), &(lock)->lock_object, (timo))
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#define cv_broadcast(cvp) cv_broadcastpri(cvp, 0)
|
||||
|
||||
|
@ -52,7 +52,11 @@ extern int cold; /* nonzero if we are doing a cold boot */
|
||||
#define cold 0
|
||||
#endif /* __rtems__ */
|
||||
extern int rebooting; /* kern_reboot() has been called. */
|
||||
#ifndef __rtems__
|
||||
extern const char *panicstr; /* panic message */
|
||||
#else /* __rtems__ */
|
||||
#define panicstr NULL
|
||||
#endif /* __rtems__ */
|
||||
extern char version[]; /* system version */
|
||||
extern char compiler_version[]; /* compiler version */
|
||||
extern char copyright[]; /* system copyright */
|
||||
|
@ -1,165 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_bsd_rtems
|
||||
*
|
||||
* @brief TODO.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-2014 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* Dornierstr. 4
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <machine/rtems-bsd-kernel-space.h>
|
||||
#include <machine/rtems-bsd-support.h>
|
||||
|
||||
#include <rtems/score/threaddispatch.h>
|
||||
#include <rtems/score/threadimpl.h>
|
||||
#include <rtems/score/threadqimpl.h>
|
||||
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <rtems/bsd/sys/types.h>
|
||||
#include <sys/systm.h>
|
||||
#include <rtems/bsd/sys/lock.h>
|
||||
#include <sys/condvar.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
void
|
||||
cv_init(struct cv *cv, const char *desc)
|
||||
{
|
||||
|
||||
cv->cv_description = desc;
|
||||
_Thread_queue_Initialize(&cv->cv_waiters, THREAD_QUEUE_DISCIPLINE_PRIORITY,
|
||||
STATES_WAITING_FOR_CONDITION_VARIABLE, EWOULDBLOCK);
|
||||
}
|
||||
|
||||
void
|
||||
cv_destroy(struct cv *cv)
|
||||
{
|
||||
|
||||
BSD_ASSERT(_Thread_queue_First(&cv->cv_waiters) == NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
_cv_wait_support(struct cv *cv, struct lock_object *lock, Watchdog_Interval timo, bool relock)
|
||||
{
|
||||
int error;
|
||||
struct lock_class *class;
|
||||
int lock_state;
|
||||
Thread_Control *executing;
|
||||
|
||||
_Thread_Disable_dispatch();
|
||||
|
||||
class = LOCK_CLASS(lock);
|
||||
lock_state = (*class->lc_unlock)(lock);
|
||||
|
||||
_Thread_queue_Enter_critical_section(&cv->cv_waiters);
|
||||
|
||||
executing = _Thread_Executing;
|
||||
executing->Wait.return_code = 0;
|
||||
executing->Wait.queue = &cv->cv_waiters;
|
||||
|
||||
_Thread_queue_Enqueue(&cv->cv_waiters, executing, timo);
|
||||
|
||||
DROP_GIANT();
|
||||
|
||||
_Thread_Enable_dispatch();
|
||||
|
||||
PICKUP_GIANT();
|
||||
|
||||
error = (int)executing->Wait.return_code;
|
||||
|
||||
if (relock) {
|
||||
(*class->lc_lock)(lock, lock_state);
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
void
|
||||
_cv_wait(struct cv *cv, struct lock_object *lock)
|
||||
{
|
||||
|
||||
_cv_wait_support(cv, lock, 0, true);
|
||||
}
|
||||
|
||||
void
|
||||
_cv_wait_unlock(struct cv *cv, struct lock_object *lock)
|
||||
{
|
||||
|
||||
_cv_wait_support(cv, lock, 0, false);
|
||||
}
|
||||
|
||||
int
|
||||
_cv_timedwait(struct cv *cv, struct lock_object *lock, int timo)
|
||||
{
|
||||
if (timo <= 0)
|
||||
timo = 1;
|
||||
|
||||
return (_cv_wait_support(cv, lock, (Watchdog_Interval)timo, true));
|
||||
}
|
||||
|
||||
void
|
||||
cv_signal(struct cv *cv)
|
||||
{
|
||||
|
||||
_Thread_Disable_dispatch();
|
||||
_Thread_queue_Dequeue(&cv->cv_waiters);
|
||||
_Thread_Enable_dispatch();
|
||||
}
|
||||
|
||||
void
|
||||
cv_broadcastpri(struct cv *cv, int pri)
|
||||
{
|
||||
|
||||
_Thread_Disable_dispatch();
|
||||
|
||||
while (_Thread_queue_Dequeue(&cv->cv_waiters) != NULL) {
|
||||
/* Again */
|
||||
}
|
||||
|
||||
_Thread_Enable_dispatch();
|
||||
}
|
||||
|
||||
int
|
||||
_cv_wait_sig(struct cv *cv, struct lock_object *lock)
|
||||
{
|
||||
|
||||
return (_cv_wait_support(cv, lock, 0, true));
|
||||
}
|
||||
|
||||
int
|
||||
_cv_timedwait_sig(struct cv *cv, struct lock_object *lock, int timo)
|
||||
{
|
||||
|
||||
if (timo <= 0)
|
||||
timo = 1;
|
||||
|
||||
return (_cv_wait_support(cv, lock, (Watchdog_Interval)timo, true));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user