aboutsummaryrefslogtreecommitdiffstats
path: root/os/various
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-04-28 08:46:55 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-04-28 08:46:55 +0000
commit8b367be11b7f6f3868c0a58f3afcbbc73d63b219 (patch)
tree2af724c03bcce46c6b4810cacdd355a7c32286c1 /os/various
parent81b7c3b5a541e4a24438ed87735e4eb1da5999e7 (diff)
downloadChibiOS-8b367be11b7f6f3868c0a58f3afcbbc73d63b219.tar.gz
ChibiOS-8b367be11b7f6f3868c0a58f3afcbbc73d63b219.tar.bz2
ChibiOS-8b367be11b7f6f3868c0a58f3afcbbc73d63b219.zip
Added RAII helpers to the C++ wrapper.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11962 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os/various')
-rw-r--r--os/various/cpp_wrappers/ch.hpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/os/various/cpp_wrappers/ch.hpp b/os/various/cpp_wrappers/ch.hpp
index d52f80730..7bfaea5d2 100644
--- a/os/various/cpp_wrappers/ch.hpp
+++ b/os/various/cpp_wrappers/ch.hpp
@@ -381,10 +381,26 @@ namespace chibios_rt {
};
/*------------------------------------------------------------------------*
+ * chibios_rt::CriticalSectionLocker *
+ *------------------------------------------------------------------------*/
+ /**
+ * @brief RAII helper for reentrant critical sections.
+ */
+ class CriticalSectionLocker {
+ volatile const ::syssts_t syssts = chSysGetStatusAndLockX();
+
+ public:
+ ~CriticalSectionLocker() {
+
+ chSysRestoreStatusX(syssts);
+ }
+ };
+
+ /*------------------------------------------------------------------------*
* chibios_rt::Scheduler *
*------------------------------------------------------------------------*/
/**
- * @brief Class encapsulating thelow level scheduler functionalities.
+ * @brief Class encapsulating the low level scheduler functionalities.
*/
class Scheduler {
public:
@@ -2057,6 +2073,28 @@ namespace chibios_rt {
}
};
+ /*------------------------------------------------------------------------*
+ * chibios_rt::MutexLocker *
+ *------------------------------------------------------------------------*/
+ /**
+ * @brief RAII helper for mutexes.
+ */
+ class MutexLocker
+ {
+ chibios_rt::Mutex& mutex;
+
+ public:
+ MutexLocker(Mutex& m) : mutex(m) {
+
+ mutex.lock();
+ }
+
+ ~MutexLocker() {
+
+ mutex.unlock();
+ }
+ };
+
#if (CH_CFG_USE_CONDVARS == TRUE) || defined(__DOXYGEN__)
/*------------------------------------------------------------------------*
* chibios_rt::CondVar *
@@ -2926,7 +2964,7 @@ namespace chibios_rt {
*
* @api
*/
- inline size_t status(size_t &frag, size_t *largestp=0) {
+ size_t status(size_t &frag, size_t *largestp=0) {
return chHeapStatus(&heap, &frag, largestp);
}