Skip to content

Commit d27566c

Browse files
c1728p90xc0170
authored andcommitted
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.
1 parent 7283f9b commit d27566c

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

drivers/FlashIAP.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <algorithm>
2626
#include "FlashIAP.h"
2727
#include "platform/mbed_assert.h"
28-
#include "platform/MpuXnLock.h"
28+
#include "platform/ScopedMpuXnLock.h"
2929

3030

3131
#ifdef DEVICE_FLASH
@@ -58,7 +58,7 @@ int FlashIAP::init()
5858
int ret = 0;
5959
_mutex->lock();
6060
{
61-
MpuXnLock xn;
61+
ScopedMpuXnLock xn;
6262
if (flash_init(&_flash)) {
6363
ret = -1;
6464
}
@@ -75,7 +75,7 @@ int FlashIAP::deinit()
7575
int ret = 0;
7676
_mutex->lock();
7777
{
78-
MpuXnLock xn;
78+
ScopedMpuXnLock xn;
7979
if (flash_free(&_flash)) {
8080
ret = -1;
8181
}
@@ -91,7 +91,7 @@ int FlashIAP::read(void *buffer, uint32_t addr, uint32_t size)
9191
int32_t ret = -1;
9292
_mutex->lock();
9393
{
94-
MpuXnLock xn;
94+
ScopedMpuXnLock xn;
9595
ret = flash_read(&_flash, addr, (uint8_t *) buffer, size);
9696
}
9797
_mutex->unlock();
@@ -137,7 +137,7 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
137137
prog_size = chunk;
138138
}
139139
{
140-
MpuXnLock xn;
140+
ScopedMpuXnLock xn;
141141
if (flash_program_page(&_flash, addr, prog_buf, prog_size)) {
142142
ret = -1;
143143
break;
@@ -184,7 +184,7 @@ int FlashIAP::erase(uint32_t addr, uint32_t size)
184184
_mutex->lock();
185185
while (size) {
186186
{
187-
MpuXnLock xn;
187+
ScopedMpuXnLock xn;
188188
ret = flash_erase_sector(&_flash, addr);
189189
}
190190
if (ret != 0) {

mbed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
#include "platform/DirHandle.h"
9696
#include "platform/CriticalSectionLock.h"
9797
#include "platform/DeepSleepLock.h"
98-
#include "platform/MpuXnLock.h"
98+
#include "platform/ScopedMpuXnLock.h"
9999
#include "platform/mbed_stats.h"
100100

101101
// mbed Non-hardware components

platform/MpuXnLock.h renamed to platform/ScopedMpuXnLock.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#ifndef MBED_MPUXNLOCK_H
17-
#define MBED_MPUXNLOCK_H
16+
#ifndef MBED_SCOPEDMPUXNLOCK_H
17+
#define MBED_SCOPEDMPUXNLOCK_H
1818

1919
#include "platform/mbed_mpu_mgmt.h"
20+
#include "platform/NonCopyable.h"
2021

2122
namespace mbed {
2223

@@ -30,14 +31,14 @@ namespace mbed {
3031
* void f() {
3132
* // some code here
3233
* {
33-
* MpuXnLock xn;
34+
* ScopedMpuXnLock xn;
3435
* // Code in this block is allowed to call functions in RAM
3536
* }
3637
* // Execution from RAM is no longer allowed
3738
* }
3839
* @endcode
3940
*/
40-
class MpuXnLock {
41+
class ScopedMpuXnLock : private mbed::NonCopyable<ScopedMpuXnLock> {
4142
public:
4243

4344
/**
@@ -47,7 +48,7 @@ class MpuXnLock {
4748
* be executed from RAM. This class uses RAII to allow
4849
* execution from ram while it is in scope.
4950
*/
50-
MpuXnLock()
51+
ScopedMpuXnLock()
5152
{
5253
mbed_mpu_manager_lock_mem_xn();
5354
}
@@ -58,7 +59,7 @@ class MpuXnLock {
5859
* Decrement the execute never lock to return execute from RAM
5960
* to its prior state.
6061
*/
61-
~MpuXnLock()
62+
~ScopedMpuXnLock()
6263
{
6364
mbed_mpu_manager_unlock_mem_xn();
6465
}

0 commit comments

Comments
 (0)