summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-11-15 13:21:01 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-11-15 13:22:40 +0100
commitd4b99ae3f8698df11c865c83ec65b316bb5bb64b (patch)
tree92465ddb68bb032761c12903b396e2b1e87b6e33
parentdl01, dl02, dl05: Fix unresolved printf symbol (diff)
downloadrtems-d4b99ae3f8698df11c865c83ec65b316bb5bb64b.tar.bz2
libio: Add assert to rtems_libio_iop_drop()
This assert helps to detect an invalid reference counting in RTEMS_DEBUG configurations. Update #3132.
-rw-r--r--cpukit/libcsupport/include/rtems/libio_.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index cf4ea78f7e..5cc31eed64 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -29,6 +29,7 @@
#include <rtems.h>
#include <rtems/libio.h>
#include <rtems/seterr.h>
+#include <rtems/score/assert.h>
#ifdef __cplusplus
extern "C" {
@@ -181,11 +182,33 @@ static inline unsigned int rtems_libio_iop_hold( rtems_libio_t *iop )
*/
static inline void rtems_libio_iop_drop( rtems_libio_t *iop )
{
+#if defined(RTEMS_DEBUG)
+ unsigned int flags;
+ bool success;
+
+ flags = _Atomic_Load_uint( &iop->flags, ATOMIC_ORDER_RELAXED );
+
+ do {
+ unsigned int desired;
+
+ _Assert( flags >= LIBIO_FLAGS_REFERENCE_INC );
+
+ desired = flags - LIBIO_FLAGS_REFERENCE_INC;
+ success = _Atomic_Compare_exchange_uint(
+ &iop->flags,
+ &flags,
+ desired,
+ ATOMIC_ORDER_RELEASE,
+ ATOMIC_ORDER_RELAXED
+ );
+ } while ( !success );
+#else
_Atomic_Fetch_sub_uint(
&iop->flags,
LIBIO_FLAGS_REFERENCE_INC,
ATOMIC_ORDER_RELEASE
);
+#endif
}
/*