summaryrefslogtreecommitdiffstats
path: root/rtemsbsd
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-03-12 14:38:46 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-03-13 11:27:11 +0100
commiteae664ea8fdae9e514dc7970c6cf21a0b9767ddd (patch)
tree7c4c2ec603cde7c2dcc9bc2f6abaae2a8e4c34fd /rtemsbsd
parentdwc_otg: Default to USB host mode (diff)
downloadrtems-libbsd-eae664ea8fdae9e514dc7970c6cf21a0b9767ddd.tar.bz2
mutex: Use panic() after ISR lock release
Using panic() with interrupts disabled could lead to an additional error (INTERNAL_ERROR_BAD_THREAD_DISPATCH_ENVIRONMENT) due to a potentially blocking output.
Diffstat (limited to 'rtemsbsd')
-rw-r--r--rtemsbsd/include/machine/rtems-bsd-muteximpl.h21
-rw-r--r--rtemsbsd/rtems/rtems-kernel-muteximpl.c10
2 files changed, 25 insertions, 6 deletions
diff --git a/rtemsbsd/include/machine/rtems-bsd-muteximpl.h b/rtemsbsd/include/machine/rtems-bsd-muteximpl.h
index 4706201b..c947e2ba 100644
--- a/rtemsbsd/include/machine/rtems-bsd-muteximpl.h
+++ b/rtemsbsd/include/machine/rtems-bsd-muteximpl.h
@@ -8,7 +8,7 @@
*/
/*
- * Copyright (c) 2014, 2017 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2014, 2018 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
@@ -46,6 +46,9 @@
#include <sys/types.h>
#include <sys/lock.h>
+#include <sys/systm.h>
+
+#include <inttypes.h>
#include <rtems/score/threadimpl.h>
#include <rtems/score/threadqimpl.h>
@@ -160,7 +163,12 @@ rtems_bsd_mutex_trylock(struct lock_object *lock, rtems_bsd_mutex *m)
_Thread_Resource_count_increment(executing);
success = 1;
} else if (owner == executing) {
- BSD_ASSERT(lock->lo_flags & LO_RECURSABLE);
+ if ((lock->lo_flags & LO_RECURSABLE) == 0) {
+ rtems_bsd_mutex_release(m, isr_level, &queue_context);
+ panic("mutex trylock: %s: not LO_RECURSABLE\n",
+ m->queue.Queue.name);
+ }
+
++m->nest_level;
success = 1;
} else {
@@ -178,6 +186,7 @@ rtems_bsd_mutex_unlock(rtems_bsd_mutex *m)
ISR_Level isr_level;
Thread_queue_Context queue_context;
Thread_Control *owner;
+ Thread_Control *executing;
int nest_level;
_Thread_queue_Context_initialize(&queue_context);
@@ -186,8 +195,14 @@ rtems_bsd_mutex_unlock(rtems_bsd_mutex *m)
nest_level = m->nest_level;
owner = m->queue.Queue.owner;
+ executing = _Thread_Executing;
- BSD_ASSERT(owner == _Thread_Executing);
+ if (__predict_false(owner != executing)) {
+ rtems_bsd_mutex_release(m, isr_level, &queue_context);
+ panic("mutex unlock: %s: owner 0x%08" PRIx32
+ " != executing 0x%08" PRIx32 "\n", m->queue.Queue.name,
+ owner->Object.id, executing->Object.id);
+ }
if (__predict_true(nest_level == 0)) {
Thread_queue_Heads *heads;
diff --git a/rtemsbsd/rtems/rtems-kernel-muteximpl.c b/rtemsbsd/rtems/rtems-kernel-muteximpl.c
index d2400282..8a832b4e 100644
--- a/rtemsbsd/rtems/rtems-kernel-muteximpl.c
+++ b/rtemsbsd/rtems/rtems-kernel-muteximpl.c
@@ -7,7 +7,7 @@
*/
/*
- * Copyright (c) 2014, 2016 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2014, 2018 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
@@ -48,9 +48,13 @@ rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m,
Thread_queue_Context *queue_context)
{
if (owner == executing) {
- BSD_ASSERT(lock->lo_flags & LO_RECURSABLE);
- ++m->nest_level;
+ if ((lock->lo_flags & LO_RECURSABLE) == 0) {
+ _Thread_queue_Release(&m->queue, queue_context);
+ panic("mutex lock: %s: not LO_RECURSABLE\n",
+ m->queue.Queue.name);
+ }
+ ++m->nest_level;
_Thread_queue_Release(&m->queue, queue_context);
} else {
_Thread_queue_Context_set_thread_state(queue_context,