summaryrefslogtreecommitdiffstats
path: root/rtemsbsd/rtems
diff options
context:
space:
mode:
Diffstat (limited to 'rtemsbsd/rtems')
-rw-r--r--rtemsbsd/rtems/rtems-bsd-condvar.c120
-rw-r--r--rtemsbsd/rtems/rtems-bsd-mutex.c108
-rw-r--r--rtemsbsd/rtems/rtems-bsd-rwlock.c70
-rw-r--r--rtemsbsd/rtems/rtems-bsd-shell.c69
-rw-r--r--rtemsbsd/rtems/rtems-bsd-sx.c102
5 files changed, 91 insertions, 378 deletions
diff --git a/rtemsbsd/rtems/rtems-bsd-condvar.c b/rtemsbsd/rtems/rtems-bsd-condvar.c
index e64b4703..ff2f9c30 100644
--- a/rtemsbsd/rtems/rtems-bsd-condvar.c
+++ b/rtemsbsd/rtems/rtems-bsd-condvar.c
@@ -39,153 +39,127 @@
#include <machine/rtems-bsd-kernel-space.h>
#include <machine/rtems-bsd-support.h>
-#include <rtems/score/objectimpl.h>
#include <rtems/score/threaddispatch.h>
+#include <rtems/score/threadimpl.h>
#include <rtems/score/threadqimpl.h>
-#include <rtems/posix/condimpl.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/mutex.h>
#include <sys/condvar.h>
-
-RTEMS_CHAIN_DEFINE_EMPTY(rtems_bsd_condvar_chain);
+#include <sys/mutex.h>
void
cv_init(struct cv *cv, const char *desc)
{
- int rv = pthread_cond_init(&cv->cv_id, NULL);
-
- BSD_ASSERT_RV(rv);
cv->cv_description = desc;
-
- rtems_chain_append(&rtems_bsd_condvar_chain, &cv->cv_node);
+ _Thread_queue_Initialize(&cv->cv_waiters, THREAD_QUEUE_DISCIPLINE_PRIORITY,
+ STATES_WAITING_FOR_CONDITION_VARIABLE, EWOULDBLOCK);
}
void
cv_destroy(struct cv *cv)
{
- int rv = pthread_cond_destroy(&cv->cv_id);
- BSD_ASSERT_RV(rv);
-
- rtems_chain_extract(&cv->cv_node);
+ BSD_ASSERT(_Thread_queue_First(&cv->cv_waiters) == NULL);
}
-static int _cv_wait_support(struct cv *cv, struct lock_object *lock, int timo, bool relock)
+static int
+_cv_wait_support(struct cv *cv, struct lock_object *lock, Watchdog_Interval timo, bool relock)
{
- int eno = 0;
- Objects_Locations location = OBJECTS_ERROR;
- POSIX_Condition_variables_Control *pcv = _POSIX_Condition_variables_Get(&cv->cv_id, &location);
-
- if (location == OBJECTS_LOCAL) {
- struct lock_class *class = LOCK_CLASS(lock);
- int lock_state;
-
- if (pcv->Mutex != POSIX_CONDITION_VARIABLES_NO_MUTEX && pcv->Mutex != lock->lo_id) {
- _Thread_Enable_dispatch();
-
- BSD_ASSERT(false);
-
- return EINVAL;
- }
+ int error;
+ struct lock_class *class;
+ int lock_state;
+ Thread_Control *executing;
- lock_state = (*class->lc_unlock)(lock);
+ _Thread_Disable_dispatch();
- pcv->Mutex = lock->lo_id;
+ class = LOCK_CLASS(lock);
+ lock_state = (*class->lc_unlock)(lock);
- _Thread_queue_Enter_critical_section(&pcv->Wait_queue);
- _Thread_Executing->Wait.return_code = 0;
- _Thread_Executing->Wait.queue = &pcv->Wait_queue;
- _Thread_Executing->Wait.id = cv->cv_id;
+ _Thread_queue_Enter_critical_section(&cv->cv_waiters);
- /* FIXME: Integer conversion */
- _Thread_queue_Enqueue(&pcv->Wait_queue, _Thread_Executing, (Watchdog_Interval) timo);
+ executing = _Thread_Executing;
+ executing->Wait.return_code = 0;
+ executing->Wait.queue = &cv->cv_waiters;
- DROP_GIANT();
+ _Thread_queue_Enqueue(&cv->cv_waiters, executing, timo);
- _Thread_Enable_dispatch();
+ DROP_GIANT();
- PICKUP_GIANT();
+ _Thread_Enable_dispatch();
- eno = (int) _Thread_Executing->Wait.return_code;
- if (eno != 0) {
- if (eno == ETIMEDOUT) {
- eno = EWOULDBLOCK;
- } else {
- BSD_ASSERT(false);
+ PICKUP_GIANT();
- eno = EINVAL;
- }
- }
+ error = (int)executing->Wait.return_code;
- if (relock) {
- (*class->lc_lock)(lock, lock_state);
- }
-
- return eno;
+ if (relock) {
+ (*class->lc_lock)(lock, lock_state);
}
- BSD_PANIC("unexpected object location");
+ 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) {
+ if (timo <= 0)
timo = 1;
- }
- return _cv_wait_support(cv, lock, timo, true);
+ return (_cv_wait_support(cv, lock, (Watchdog_Interval)timo, true));
}
void
cv_signal(struct cv *cv)
{
- int rv = pthread_cond_signal(&cv->cv_id);
- BSD_ASSERT_RV(rv);
+ _Thread_Disable_dispatch();
+ _Thread_queue_Dequeue(&cv->cv_waiters);
+ _Thread_Enable_dispatch();
}
void
cv_broadcastpri(struct cv *cv, int pri)
{
- int rv = 0;
- /* FIXME: What to do with "pri"? */
+ _Thread_Disable_dispatch();
+
+ while (_Thread_queue_Dequeue(&cv->cv_waiters) != NULL) {
+ /* Again */
+ }
- rv = pthread_cond_broadcast(&cv->cv_id);
- BSD_ASSERT_RV(rv);
+ _Thread_Enable_dispatch();
}
+
int
-_cv_wait_sig(struct cv *cvp, struct lock_object *lock)
+_cv_wait_sig(struct cv *cv, struct lock_object *lock)
{
- /* XXX */
- return _cv_wait_support(cvp, lock, 0, true);
+
+ return (_cv_wait_support(cv, lock, 0, true));
}
int
-_cv_timedwait_sig(struct cv *cvp, struct lock_object *lock, int timo)
+_cv_timedwait_sig(struct cv *cv, struct lock_object *lock, int timo)
{
- /* XXX */
- if (timo <= 0) {
+
+ if (timo <= 0)
timo = 1;
- }
- return _cv_wait_support(cvp, lock, timo, true);
+ return (_cv_wait_support(cv, lock, (Watchdog_Interval)timo, true));
}
diff --git a/rtemsbsd/rtems/rtems-bsd-mutex.c b/rtemsbsd/rtems/rtems-bsd-mutex.c
index b975b977..37cc04ca 100644
--- a/rtemsbsd/rtems/rtems-bsd-mutex.c
+++ b/rtemsbsd/rtems/rtems-bsd-mutex.c
@@ -38,12 +38,7 @@
*/
#include <machine/rtems-bsd-kernel-space.h>
-#include <machine/rtems-bsd-thread.h>
-#include <machine/rtems-bsd-support.h>
-
-#include <rtems/score/objectimpl.h>
-#include <rtems/rtems/attrimpl.h>
-#include <rtems/rtems/semimpl.h>
+#include <machine/rtems-bsd-muteximpl.h>
#include <rtems/bsd/sys/param.h>
#include <rtems/bsd/sys/types.h>
@@ -59,8 +54,6 @@ static int owner_mtx(struct lock_object *lock, struct thread **owner);
#endif
static int unlock_mtx(struct lock_object *lock);
-RTEMS_CHAIN_DEFINE_EMPTY(rtems_bsd_mtx_chain);
-
/*
* Lock classes for sleep and spin mutexes.
*/
@@ -103,19 +96,15 @@ assert_mtx(struct lock_object *lock, int what)
void
lock_mtx(struct lock_object *lock, int how)
{
-
- mtx_lock((struct mtx *)lock);
+ mtx_lock((struct mtx *)lock);
}
int
unlock_mtx(struct lock_object *lock)
{
- struct mtx *m;
+ mtx_unlock((struct mtx *)lock);
- m = (struct mtx *)lock;
- mtx_assert(m, MA_OWNED | MA_NOTRECURSED);
- mtx_unlock(m);
- return (0);
+ return (0);
}
@@ -135,9 +124,6 @@ mtx_init(struct mtx *m, const char *name, const char *type, int opts)
{
struct lock_class *class;
int flags;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
- rtems_id id = RTEMS_ID_NONE;
- rtems_attribute attr = RTEMS_LOCAL | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY;
/* Determine lock class and lock flags. */
if (opts & MTX_SPIN)
@@ -148,55 +134,26 @@ mtx_init(struct mtx *m, const char *name, const char *type, int opts)
if (opts & MTX_RECURSE)
flags |= LO_RECURSABLE;
- lock_init(&m->lock_object, class, name, type, flags);
-
- sc = rtems_semaphore_create(
- rtems_build_name('_', 'M', 'T', 'X'),
- 1,
- attr,
- BSD_TASK_PRIORITY_RESOURCE_OWNER,
- &id
- );
- BSD_ASSERT_SC(sc);
-
- m->lock_object.lo_id = id;
-
- rtems_chain_append(&rtems_bsd_mtx_chain, &m->lock_object.lo_node);
+ rtems_bsd_mutex_init(&m->lock_object, &m->mutex, class, name, type,
+ flags);
}
void
_mtx_lock_flags(struct mtx *m, int opts, const char *file, int line)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
-
- sc = rtems_semaphore_obtain(m->lock_object.lo_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
- BSD_ASSERT_SC(sc);
+ rtems_bsd_mutex_lock(&m->lock_object, &m->mutex);
}
int
_mtx_trylock(struct mtx *m, int opts, const char *file, int line)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
-
- sc = rtems_semaphore_obtain(m->lock_object.lo_id, RTEMS_NO_WAIT, 0);
- if (sc == RTEMS_SUCCESSFUL) {
- return 1;
- } else if (sc == RTEMS_UNSATISFIED) {
- return 0;
- } else {
- BSD_ASSERT_SC(sc);
-
- return 0;
- }
+ return (rtems_bsd_mutex_trylock(&m->lock_object, &m->mutex));
}
void
_mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
-
- sc = rtems_semaphore_release(m->lock_object.lo_id);
- BSD_ASSERT_SC(sc);
+ rtems_bsd_mutex_unlock(&m->mutex);
}
/*
@@ -238,38 +195,12 @@ _mtx_assert(struct mtx *m, int what, const char *file, int line)
int mtx_owned(struct mtx *m)
{
- Objects_Locations location;
- Semaphore_Control *sema = _Semaphore_Get(m->lock_object.lo_id, &location);
-
- if (location == OBJECTS_LOCAL && !_Attributes_Is_counting_semaphore(sema->attribute_set)) {
- int owned = sema->Core_control.mutex.holder == _Thread_Executing;
-
- _Thread_Enable_dispatch();
-
- return owned;
- } else {
- _Thread_Enable_dispatch();
-
- BSD_PANIC("unexpected semaphore location or attributes");
- }
+ return (rtems_bsd_mutex_owned(&m->mutex));
}
int mtx_recursed(struct mtx *m)
{
- Objects_Locations location;
- Semaphore_Control *sema = _Semaphore_Get(m->lock_object.lo_id, &location);
-
- if (location == OBJECTS_LOCAL && !_Attributes_Is_counting_semaphore(sema->attribute_set)) {
- int recursed = sema->Core_control.mutex.nest_count != 0;
-
- _Thread_Enable_dispatch();
-
- return recursed;
- } else {
- _Thread_Enable_dispatch();
-
- BSD_PANIC("unexpected semaphore location or attributes");
- }
+ return (rtems_bsd_mutex_recursed(&m->mutex));
}
void
@@ -283,23 +214,8 @@ mtx_sysinit(void *arg)
void
mtx_destroy(struct mtx *m)
{
- rtems_status_code sc;
-
- do {
- sc = rtems_semaphore_delete(m->lock_object.lo_id);
- if (sc == RTEMS_RESOURCE_IN_USE) {
- BSD_ASSERT(mtx_owned(m));
-
- mtx_unlock(m);
- } else {
- BSD_ASSERT_SC(sc);
- }
- } while (sc != RTEMS_SUCCESSFUL);
-
- rtems_chain_extract(&m->lock_object.lo_node);
- m->lock_object.lo_id = 0;
- m->lock_object.lo_flags &= ~LO_INITIALIZED;
+ rtems_bsd_mutex_destroy(&m->lock_object, &m->mutex);
}
void
diff --git a/rtemsbsd/rtems/rtems-bsd-rwlock.c b/rtemsbsd/rtems/rtems-bsd-rwlock.c
index b85f3742..b6540b54 100644
--- a/rtemsbsd/rtems/rtems-bsd-rwlock.c
+++ b/rtemsbsd/rtems/rtems-bsd-rwlock.c
@@ -46,17 +46,13 @@
*/
#include <machine/rtems-bsd-kernel-space.h>
-#include <machine/rtems-bsd-thread.h>
-#include <machine/rtems-bsd-support.h>
-
-#include <rtems.h>
+#include <machine/rtems-bsd-muteximpl.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/rwlock.h>
-#include <sys/mutex.h>
#ifndef INVARIANTS
#define _rw_assert(rw, what, file, line)
@@ -83,8 +79,6 @@ struct lock_class lock_class_rw = {
#endif
};
-RTEMS_CHAIN_DEFINE_EMPTY(rtems_bsd_rwlock_chain);
-
void
assert_rw(struct lock_object *lock, int what)
{
@@ -94,29 +88,15 @@ assert_rw(struct lock_object *lock, int what)
void
lock_rw(struct lock_object *lock, int how)
{
- struct rwlock *rw;
-
- rw = (struct rwlock *)lock;
- if (how)
- rw_wlock(rw);
- else
- rw_rlock(rw);
+ rw_wlock((struct rwlock *)lock);
}
int
unlock_rw(struct lock_object *lock)
{
- struct rwlock *rw;
-
- rw = (struct rwlock *)lock;
- rw_assert(rw, RA_LOCKED | LA_NOTRECURSED);
- if (rw->rw_lock & RW_LOCK_READ) {
- rw_runlock(rw);
- return (0);
- } else {
- rw_wunlock(rw);
- return (1);
- }
+ rw_unlock((struct rwlock *)lock);
+
+ return (0);
}
#ifdef KDTRACE_HOOKS
@@ -136,34 +116,20 @@ void
rw_init_flags(struct rwlock *rw, const char *name, int opts)
{
int flags;
- rtems_status_code sc;
- rtems_id id;
- rtems_attribute attr = RTEMS_LOCAL | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY;
flags = LO_UPGRADABLE;
if (opts & RW_RECURSE)
flags |= LO_RECURSABLE;
- lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags);
-
- sc = rtems_semaphore_create(
- rtems_build_name('_', '_', 'R', 'W'),
- 1,
- attr,
- BSD_TASK_PRIORITY_RESOURCE_OWNER,
- &id
- );
- BSD_ASSERT_SC(sc);
-
- rw->lock_object.lo_id = id;
-
- rtems_chain_append(&rtems_bsd_rwlock_chain, &rw->lock_object.lo_node);
+ rtems_bsd_mutex_init(&rw->lock_object, &rw->mutex, &lock_class_rw,
+ name, NULL, flags);
}
void
rw_destroy(struct rwlock *rw)
{
- mtx_destroy((struct mtx *) rw);
+
+ rtems_bsd_mutex_destroy(&rw->lock_object, &rw->mutex);
}
void
@@ -185,55 +151,55 @@ rw_sysinit_flags(void *arg)
int
rw_wowned(struct rwlock *rw)
{
- return mtx_owned((struct mtx *) rw);
+ return (rtems_bsd_mutex_owned(&rw->mutex));
}
void
_rw_wlock(struct rwlock *rw, const char *file, int line)
{
- _mtx_lock_flags((struct mtx *) rw, 0, file, line);
+ rtems_bsd_mutex_lock(&rw->lock_object, &rw->mutex);
}
int
_rw_try_wlock(struct rwlock *rw, const char *file, int line)
{
- return _mtx_trylock((struct mtx *) rw, 0, file, line);
+ return (rtems_bsd_mutex_trylock(&rw->lock_object, &rw->mutex));
}
void
_rw_wunlock(struct rwlock *rw, const char *file, int line)
{
- _mtx_unlock_flags((struct mtx *) rw, 0, file, line);
+ rtems_bsd_mutex_unlock(&rw->mutex);
}
void
_rw_rlock(struct rwlock *rw, const char *file, int line)
{
- _mtx_lock_flags((struct mtx *) rw, 0, file, line);
+ rtems_bsd_mutex_lock(&rw->lock_object, &rw->mutex);
}
int
_rw_try_rlock(struct rwlock *rw, const char *file, int line)
{
- return _mtx_trylock((struct mtx *) rw, 0, file, line);
+ return (rtems_bsd_mutex_trylock(&rw->lock_object, &rw->mutex));
}
void
_rw_runlock(struct rwlock *rw, const char *file, int line)
{
- _mtx_unlock_flags((struct mtx *) rw, 0, file, line);
+ rtems_bsd_mutex_unlock(&rw->mutex);
}
int
_rw_try_upgrade(struct rwlock *rw, const char *file, int line)
{
- return 1;
+ return (1);
}
void
_rw_downgrade(struct rwlock *rw, const char *file, int line)
{
- /* Nothing to do */
+ /* Nothing to do */
}
#ifdef INVARIANT_SUPPORT
diff --git a/rtemsbsd/rtems/rtems-bsd-shell.c b/rtemsbsd/rtems/rtems-bsd-shell.c
index 2fa1aaa3..7ccb170c 100644
--- a/rtemsbsd/rtems/rtems-bsd-shell.c
+++ b/rtemsbsd/rtems/rtems-bsd-shell.c
@@ -44,67 +44,12 @@
#include <rtems/bsd/sys/param.h>
#include <rtems/bsd/sys/types.h>
#include <sys/systm.h>
-#include <rtems/bsd/sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/callout.h>
-#include <sys/condvar.h>
#include <sys/proc.h>
#include <rtems/bsd/bsd.h>
#include <rtems/shell.h>
static void
-rtems_bsd_dump_mtx(void)
-{
- rtems_chain_control *chain = &rtems_bsd_mtx_chain;
- rtems_chain_node *node = rtems_chain_first(chain);
-
- printf("mtx dump:\n");
-
- while (!rtems_chain_is_tail(chain, node)) {
- struct lock_object *lo = (struct lock_object *) node;
-
- printf("\t%s: 0x%08x\n", lo->lo_name, lo->lo_id);
-
- node = rtems_chain_next(node);
- }
-}
-
-static void
-rtems_bsd_dump_sx(void)
-{
- rtems_chain_control *chain = &rtems_bsd_sx_chain;
- rtems_chain_node *node = rtems_chain_first(chain);
-
- printf("sx dump:\n");
-
- while (!rtems_chain_is_tail(chain, node)) {
- struct lock_object *lo = (struct lock_object *) node;
-
- printf("\t%s: 0x%08x\n", lo->lo_name, lo->lo_id);
-
- node = rtems_chain_next(node);
- }
-}
-
-static void
-rtems_bsd_dump_condvar(void)
-{
- rtems_chain_control *chain = &rtems_bsd_condvar_chain;
- rtems_chain_node *node = rtems_chain_first(chain);
-
- printf("condvar dump:\n");
-
- while (!rtems_chain_is_tail(chain, node)) {
- struct cv *cv = (struct cv *) node;
-
- printf("\t%s: 0x%08x\n", cv->cv_description, cv->cv_id);
-
- node = rtems_chain_next(node);
- }
-}
-
-static void
rtems_bsd_dump_thread(void)
{
const rtems_chain_control *chain = &rtems_bsd_thread_chain;
@@ -122,7 +67,7 @@ rtems_bsd_dump_thread(void)
}
static const char rtems_bsd_usage [] =
- "bsd {all|mtx|sx|condvar|thread|callout}";
+ "bsd {all|condvar|thread|callout}";
#define CMP(s) all || strcasecmp(argv [1], s) == 0
@@ -138,18 +83,6 @@ rtems_bsd_info(int argc, char **argv)
all = true;
}
- if (CMP("mtx")) {
- rtems_bsd_dump_mtx();
- usage = false;
- }
- if (CMP("sx")) {
- rtems_bsd_dump_sx();
- usage = false;
- }
- if (CMP("condvar")) {
- rtems_bsd_dump_condvar();
- usage = false;
- }
if (CMP("thread")) {
rtems_bsd_dump_thread();
usage = false;
diff --git a/rtemsbsd/rtems/rtems-bsd-sx.c b/rtemsbsd/rtems/rtems-bsd-sx.c
index 3d0e79e0..46ab2d17 100644
--- a/rtemsbsd/rtems/rtems-bsd-sx.c
+++ b/rtemsbsd/rtems/rtems-bsd-sx.c
@@ -38,11 +38,7 @@
*/
#include <machine/rtems-bsd-kernel-space.h>
-#include <machine/rtems-bsd-support.h>
-
-#include <rtems/score/objectimpl.h>
-#include <rtems/rtems/attrimpl.h>
-#include <rtems/rtems/semimpl.h>
+#include <machine/rtems-bsd-muteximpl.h>
#include <rtems/bsd/sys/param.h>
#include <rtems/bsd/sys/types.h>
@@ -75,8 +71,6 @@ struct lock_class lock_class_sx = {
#endif
};
-RTEMS_CHAIN_DEFINE_EMPTY(rtems_bsd_sx_chain);
-
void
assert_sx(struct lock_object *lock, int what)
{
@@ -86,29 +80,15 @@ assert_sx(struct lock_object *lock, int what)
void
lock_sx(struct lock_object *lock, int how)
{
- struct sx *sx;
-
- sx = (struct sx *)lock;
- if (how)
- sx_xlock(sx);
- else
- sx_slock(sx);
+ sx_xlock((struct sx *)lock);
}
int
unlock_sx(struct lock_object *lock)
{
- struct sx *sx;
+ sx_xunlock((struct sx *)lock);
- sx = (struct sx *)lock;
- sx_assert(sx, SA_LOCKED | SA_NOTRECURSED);
- if (sx_xlocked(sx)) {
- sx_xunlock(sx);
- return (1);
- } else {
- sx_sunlock(sx);
- return (0);
- }
+ return (0);
}
#ifdef KDTRACE_HOOKS
@@ -136,89 +116,46 @@ void
sx_init_flags(struct sx *sx, const char *description, int opts)
{
int flags;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
- rtems_id id = RTEMS_ID_NONE;
- rtems_attribute attr = RTEMS_LOCAL | RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE;
flags = LO_SLEEPABLE | LO_UPGRADABLE;
if (opts & SX_RECURSE)
flags |= LO_RECURSABLE;
- lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags);
-
- sc = rtems_semaphore_create(
- rtems_build_name( '_', 'S', 'X', ' '),
- 1,
- attr,
- 0,
- &id
- );
- BSD_ASSERT_SC(sc);
-
- sx->lock_object.lo_id = id;
-
- rtems_chain_append(&rtems_bsd_sx_chain, &sx->lock_object.lo_node);
+ rtems_bsd_mutex_init(&sx->lock_object, &sx->mutex, &lock_class_sx,
+ description, NULL, flags);
}
void
sx_destroy(struct sx *sx)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
-
- sc = rtems_semaphore_delete( sx->lock_object.lo_id);
- BSD_ASSERT_SC(sc);
-
- rtems_chain_extract(&sx->lock_object.lo_node);
- sx->lock_object.lo_id = 0;
- sx->lock_object.lo_flags &= ~LO_INITIALIZED;
+ rtems_bsd_mutex_destroy(&sx->lock_object, &sx->mutex);
}
int
_sx_xlock(struct sx *sx, int opts, const char *file, int line)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_bsd_mutex_lock(&sx->lock_object, &sx->mutex);
- #warning "SX_INTERRUPTIBLE NOT SUPPORTED YET"
- /* BSD_ASSERT((opts & SX_INTERRUPTIBLE) == 0); */
- BSD_ASSERT(!rtems_interrupt_is_in_progress());
-
- sc = rtems_semaphore_obtain( sx->lock_object.lo_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
- BSD_ASSERT_SC(sc);
-
- return 0;
+ return (0);
}
int
_sx_try_xlock(struct sx *sx, const char *file, int line)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
-
- sc = rtems_semaphore_obtain( sx->lock_object.lo_id, RTEMS_NO_WAIT, 0);
- if (sc == RTEMS_SUCCESSFUL) {
- return 1;
- } else if (sc == RTEMS_UNSATISFIED) {
- return 0;
- } else {
- BSD_ASSERT_SC(sc);
-
- return 0;
- }
+ return (rtems_bsd_mutex_trylock(&sx->lock_object, &sx->mutex));
}
void
_sx_xunlock(struct sx *sx, const char *file, int line)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
-
- sc = rtems_semaphore_release( sx->lock_object.lo_id);
- BSD_ASSERT_SC(sc);
+ rtems_bsd_mutex_unlock(&sx->mutex);
}
int
_sx_try_upgrade(struct sx *sx, const char *file, int line)
{
- return 1;
+ return (1);
}
void
@@ -322,18 +259,5 @@ _sx_assert(struct sx *sx, int what, const char *file, int line)
int
sx_xlocked(struct sx *sx)
{
- Objects_Locations location;
- Semaphore_Control *sema = _Semaphore_Get(sx->lock_object.lo_id, &location);
-
- if (location == OBJECTS_LOCAL && !_Attributes_Is_counting_semaphore(sema->attribute_set)) {
- int xlocked = sema->Core_control.mutex.holder == _Thread_Executing;
-
- _Thread_Enable_dispatch();
-
- return xlocked;
- } else {
- _Thread_Enable_dispatch();
-
- BSD_PANIC("unexpected semaphore location or attributes");
- }
+ return (rtems_bsd_mutex_owned(&sx->mutex));
}