summaryrefslogtreecommitdiffstats
path: root/rtemsbsd
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-09-22 16:24:34 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-09-22 16:50:44 +0200
commitdce8247e388bd990d04229a4dfe33e7582d9d64a (patch)
tree23d4c5a3f7655040015692b3f5d75c6586b47169 /rtemsbsd
parentInstall missing header files (diff)
downloadrtems-libbsd-dce8247e388bd990d04229a4dfe33e7582d9d64a.tar.bz2
Import and use subr_lock.c
Diffstat (limited to 'rtemsbsd')
-rw-r--r--rtemsbsd/include/rtems/bsd/local/opt_mprof.h0
-rw-r--r--rtemsbsd/rtems/rtems-bsd-lock.c62
-rw-r--r--rtemsbsd/rtems/rtems-bsd-mutex.c38
-rw-r--r--rtemsbsd/rtems/rtems-bsd-rwlock.c27
-rw-r--r--rtemsbsd/rtems/rtems-bsd-sx.c27
5 files changed, 21 insertions, 133 deletions
diff --git a/rtemsbsd/include/rtems/bsd/local/opt_mprof.h b/rtemsbsd/include/rtems/bsd/local/opt_mprof.h
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/rtemsbsd/include/rtems/bsd/local/opt_mprof.h
diff --git a/rtemsbsd/rtems/rtems-bsd-lock.c b/rtemsbsd/rtems/rtems-bsd-lock.c
deleted file mode 100644
index 9dce5811..00000000
--- a/rtemsbsd/rtems/rtems-bsd-lock.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * @file
- *
- * @ingroup rtems_bsd_rtems
- *
- * @brief TODO.
- */
-
-/*
- * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
- *
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * 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.
- */
-
-/* Necessary to obtain some internal functions */
-#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
-
-#include <machine/rtems-bsd-kernel-space.h>
-
-#include <rtems/bsd/sys/param.h>
-#include <rtems/bsd/sys/types.h>
-#include <sys/systm.h>
-#include <sys/ktr.h>
-#include <rtems/bsd/sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/sx.h>
-#include <sys/rwlock.h>
-#include <sys/proc.h>
-
-struct lock_class *lock_classes[LOCK_CLASS_MAX + 1] = {
- &lock_class_mtx_spin,
- &lock_class_mtx_sleep,
- &lock_class_sx,
- &lock_class_rw,
- &lock_class_rw,
-};
-
diff --git a/rtemsbsd/rtems/rtems-bsd-mutex.c b/rtemsbsd/rtems/rtems-bsd-mutex.c
index c6daab0b..b975b977 100644
--- a/rtemsbsd/rtems/rtems-bsd-mutex.c
+++ b/rtemsbsd/rtems/rtems-bsd-mutex.c
@@ -133,36 +133,22 @@ owner_mtx(struct lock_object *lock, struct thread **owner)
void
mtx_init(struct mtx *m, const char *name, const char *type, int opts)
{
- struct lock_class *class;
- int i;
+ 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;
- if ((opts & MTX_RECURSE) != 0 )
- {
- /*FIXME*/
- }
+ /* Determine lock class and lock flags. */
+ if (opts & MTX_SPIN)
+ class = &lock_class_mtx_spin;
+ else
+ class = &lock_class_mtx_sleep;
+ flags = 0;
+ if (opts & MTX_RECURSE)
+ flags |= LO_RECURSABLE;
- /* Determine lock class and lock flags. */
- if (opts & MTX_SPIN)
- class = &lock_class_mtx_spin;
- else
- class = &lock_class_mtx_sleep;
-
- /* Check for double-init and zero object. */
- KASSERT(!lock_initalized(&m->lock_object), ("lock \"%s\" %p already initialized", name, m->lock_object));
-
- /* Look up lock class to find its index. */
- for (i = 0; i < LOCK_CLASS_MAX; i++)
- {
- if (lock_classes[i] == class)
- {
- m->lock_object.lo_flags = i << LO_CLASSSHIFT;
- break;
- }
- }
- KASSERT(i < LOCK_CLASS_MAX, ("unknown lock class %p", class));
+ lock_init(&m->lock_object, class, name, type, flags);
sc = rtems_semaphore_create(
rtems_build_name('_', 'M', 'T', 'X'),
@@ -173,8 +159,6 @@ mtx_init(struct mtx *m, const char *name, const char *type, int opts)
);
BSD_ASSERT_SC(sc);
- m->lock_object.lo_name = name;
- m->lock_object.lo_flags |= LO_INITIALIZED;
m->lock_object.lo_id = id;
rtems_chain_append(&rtems_bsd_mtx_chain, &m->lock_object.lo_node);
diff --git a/rtemsbsd/rtems/rtems-bsd-rwlock.c b/rtemsbsd/rtems/rtems-bsd-rwlock.c
index 58e44392..b85f3742 100644
--- a/rtemsbsd/rtems/rtems-bsd-rwlock.c
+++ b/rtemsbsd/rtems/rtems-bsd-rwlock.c
@@ -135,31 +135,16 @@ owner_rw(struct lock_object *lock, struct thread **owner)
void
rw_init_flags(struct rwlock *rw, const char *name, int opts)
{
- struct lock_class *class;
- int i;
+ int flags;
rtems_status_code sc;
rtems_id id;
rtems_attribute attr = RTEMS_LOCAL | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY;
- if ((opts & RW_RECURSE) != 0) {
- /* FIXME */
- }
-
- class = &lock_class_rw;
-
- /* Check for double-init and zero object. */
- KASSERT(!lock_initalized(&rw->lock_object), ("lock \"%s\" %p already initialized", name, rw->lock_object));
+ flags = LO_UPGRADABLE;
+ if (opts & RW_RECURSE)
+ flags |= LO_RECURSABLE;
- /* Look up lock class to find its index. */
- for (i = 0; i < LOCK_CLASS_MAX; i++)
- {
- if (lock_classes[i] == class)
- {
- rw->lock_object.lo_flags = i << LO_CLASSSHIFT;
- break;
- }
- }
- KASSERT(i < LOCK_CLASS_MAX, ("unknown lock class %p", class));
+ lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags);
sc = rtems_semaphore_create(
rtems_build_name('_', '_', 'R', 'W'),
@@ -170,8 +155,6 @@ rw_init_flags(struct rwlock *rw, const char *name, int opts)
);
BSD_ASSERT_SC(sc);
- rw->lock_object.lo_name = name;
- rw->lock_object.lo_flags |= LO_INITIALIZED;
rw->lock_object.lo_id = id;
rtems_chain_append(&rtems_bsd_rwlock_chain, &rw->lock_object.lo_node);
diff --git a/rtemsbsd/rtems/rtems-bsd-sx.c b/rtemsbsd/rtems/rtems-bsd-sx.c
index b8bc336a..3d0e79e0 100644
--- a/rtemsbsd/rtems/rtems-bsd-sx.c
+++ b/rtemsbsd/rtems/rtems-bsd-sx.c
@@ -135,31 +135,16 @@ sx_sysinit(void *arg)
void
sx_init_flags(struct sx *sx, const char *description, int opts)
{
- struct lock_class *class;
- int i;
+ int flags;
rtems_status_code sc = RTEMS_SUCCESSFUL;
rtems_id id = RTEMS_ID_NONE;
rtems_attribute attr = RTEMS_LOCAL | RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE;
- if ((opts & SX_RECURSE) != 0) {
- /* FIXME */
- }
-
- class = &lock_class_sx;
-
- /* Check for double-init and zero object. */
- KASSERT(!lock_initalized(&sx->lock_object), ("lock \"%s\" %p already initialized", name, sx->lock_object));
+ flags = LO_SLEEPABLE | LO_UPGRADABLE;
+ if (opts & SX_RECURSE)
+ flags |= LO_RECURSABLE;
- /* Look up lock class to find its index. */
- for (i = 0; i < LOCK_CLASS_MAX; i++)
- {
- if (lock_classes[i] == class)
- {
- sx->lock_object.lo_flags = i << LO_CLASSSHIFT;
- break;
- }
- }
- KASSERT(i < LOCK_CLASS_MAX, ("unknown lock class %p", class));
+ lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags);
sc = rtems_semaphore_create(
rtems_build_name( '_', 'S', 'X', ' '),
@@ -170,8 +155,6 @@ sx_init_flags(struct sx *sx, const char *description, int opts)
);
BSD_ASSERT_SC(sc);
- sx->lock_object.lo_name = description;
- sx->lock_object.lo_flags |= LO_INITIALIZED;
sx->lock_object.lo_id = id;
rtems_chain_append(&rtems_bsd_sx_chain, &sx->lock_object.lo_node);