From d27566c9556a078d5a630c4e45f89194f7a4b67d Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Tue, 6 Nov 2018 15:57:28 -0600 Subject: [PATCH] Rename MpuXnLock Rename MpuXnLock to ScopedMpuXnLock so it has the same naming convention as ScopedMutexLock. Also make this class inherit from NonCopyable to prevent misuse. --- drivers/FlashIAP.cpp | 12 ++++++------ mbed.h | 2 +- platform/{MpuXnLock.h => ScopedMpuXnLock.h} | 13 +++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) rename platform/{MpuXnLock.h => ScopedMpuXnLock.h} (86%) diff --git a/drivers/FlashIAP.cpp b/drivers/FlashIAP.cpp index a265066ea4..fc8a42bf84 100644 --- a/drivers/FlashIAP.cpp +++ b/drivers/FlashIAP.cpp @@ -25,7 +25,7 @@ #include #include "FlashIAP.h" #include "platform/mbed_assert.h" -#include "platform/MpuXnLock.h" +#include "platform/ScopedMpuXnLock.h" #ifdef DEVICE_FLASH @@ -58,7 +58,7 @@ int FlashIAP::init() int ret = 0; _mutex->lock(); { - MpuXnLock xn; + ScopedMpuXnLock xn; if (flash_init(&_flash)) { ret = -1; } @@ -75,7 +75,7 @@ int FlashIAP::deinit() int ret = 0; _mutex->lock(); { - MpuXnLock xn; + ScopedMpuXnLock xn; if (flash_free(&_flash)) { ret = -1; } @@ -91,7 +91,7 @@ int FlashIAP::read(void *buffer, uint32_t addr, uint32_t size) int32_t ret = -1; _mutex->lock(); { - MpuXnLock xn; + ScopedMpuXnLock xn; ret = flash_read(&_flash, addr, (uint8_t *) buffer, size); } _mutex->unlock(); @@ -137,7 +137,7 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size) prog_size = chunk; } { - MpuXnLock xn; + ScopedMpuXnLock xn; if (flash_program_page(&_flash, addr, prog_buf, prog_size)) { ret = -1; break; @@ -184,7 +184,7 @@ int FlashIAP::erase(uint32_t addr, uint32_t size) _mutex->lock(); while (size) { { - MpuXnLock xn; + ScopedMpuXnLock xn; ret = flash_erase_sector(&_flash, addr); } if (ret != 0) { diff --git a/mbed.h b/mbed.h index d01c30ce5a..dfca470aab 100644 --- a/mbed.h +++ b/mbed.h @@ -95,7 +95,7 @@ #include "platform/DirHandle.h" #include "platform/CriticalSectionLock.h" #include "platform/DeepSleepLock.h" -#include "platform/MpuXnLock.h" +#include "platform/ScopedMpuXnLock.h" #include "platform/mbed_stats.h" // mbed Non-hardware components diff --git a/platform/MpuXnLock.h b/platform/ScopedMpuXnLock.h similarity index 86% rename from platform/MpuXnLock.h rename to platform/ScopedMpuXnLock.h index 59cbfe2f16..59a564ac9c 100644 --- a/platform/MpuXnLock.h +++ b/platform/ScopedMpuXnLock.h @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MBED_MPUXNLOCK_H -#define MBED_MPUXNLOCK_H +#ifndef MBED_SCOPEDMPUXNLOCK_H +#define MBED_SCOPEDMPUXNLOCK_H #include "platform/mbed_mpu_mgmt.h" +#include "platform/NonCopyable.h" namespace mbed { @@ -30,14 +31,14 @@ namespace mbed { * void f() { * // some code here * { - * MpuXnLock xn; + * ScopedMpuXnLock xn; * // Code in this block is allowed to call functions in RAM * } * // Execution from RAM is no longer allowed * } * @endcode */ -class MpuXnLock { +class ScopedMpuXnLock : private mbed::NonCopyable { public: /** @@ -47,7 +48,7 @@ public: * be executed from RAM. This class uses RAII to allow * execution from ram while it is in scope. */ - MpuXnLock() + ScopedMpuXnLock() { mbed_mpu_manager_lock_mem_xn(); } @@ -58,7 +59,7 @@ public: * Decrement the execute never lock to return execute from RAM * to its prior state. */ - ~MpuXnLock() + ~ScopedMpuXnLock() { mbed_mpu_manager_unlock_mem_xn(); }