mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-16 19:59:59 +08:00
Import and use subr_lock.c
This commit is contained in:
0
rtemsbsd/include/rtems/bsd/local/opt_mprof.h
Normal file
0
rtemsbsd/include/rtems/bsd/local/opt_mprof.h
Normal file
@@ -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,
|
||||
};
|
||||
|
@@ -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);
|
||||
|
@@ -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 */
|
||||
}
|
||||
flags = LO_UPGRADABLE;
|
||||
if (opts & RW_RECURSE)
|
||||
flags |= LO_RECURSABLE;
|
||||
|
||||
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));
|
||||
|
||||
/* 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);
|
||||
|
@@ -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 */
|
||||
}
|
||||
flags = LO_SLEEPABLE | LO_UPGRADABLE;
|
||||
if (opts & SX_RECURSE)
|
||||
flags |= LO_RECURSABLE;
|
||||
|
||||
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));
|
||||
|
||||
/* 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);
|
||||
|
Reference in New Issue
Block a user