File tree Expand file tree Collapse file tree 4 files changed +15
-18
lines changed Expand file tree Collapse file tree 4 files changed +15
-18
lines changed Original file line number Diff line number Diff line change @@ -983,7 +983,6 @@ int TDBStore::init()
983983 uint32_t actual_data_size;
984984 int os_ret, ret = MBED_SUCCESS, reserved_ret;
985985 uint16_t versions[_num_areas];
986- internal_mem_resident_type_e out_in_mem_res;
987986
988987 _mutex.lock ();
989988
@@ -992,8 +991,8 @@ int TDBStore::init()
992991 }
993992
994993 // Check if we are on internal memory && try to set the internal memory for TDBStore use.
995- if (strcmp (_bd->get_type (), " FLASHIAP" )== 0 &&
996- set_internal_storage_ownership (TDBSTORE, &out_in_mem_res ) == MBED_ERROR_ALREADY_INITIALIZED) {
994+ if (strcmp (_bd->get_type (), " FLASHIAP" ) == 0 &&
995+ avoid_conflict_nvstore_tdbstore (TDBSTORE) == MBED_ERROR_ALREADY_INITIALIZED) {
997996
998997 MBED_ERROR (MBED_ERROR_ALREADY_INITIALIZED, " TDBStore in internal memory can not be initialize when NVStore is in use" );
999998 }
Original file line number Diff line number Diff line change @@ -851,14 +851,13 @@ int NVStore::init()
851851 uint16_t keys[NVSTORE_NUM_AREAS];
852852 uint16_t actual_size;
853853 uint8_t owner;
854- internal_mem_resident_type_e out_in_mem_res;
855854
856855 if (_init_done) {
857856 return NVSTORE_SUCCESS;
858857 }
859858
860859 // Check if we are on internal memory && try to set the internal memory for TDBStore use.
861- ret = set_internal_storage_ownership (NVSTORE, &out_in_mem_res );
860+ ret = avoid_conflict_nvstore_tdbstore (NVSTORE);
862861 // NVstore in internal memory can not be initialize when TDBStore is in use
863862 MBED_ASSERT (ret != MBED_ERROR_ALREADY_INITIALIZED);
864863
Original file line number Diff line number Diff line change 4343
4444using namespace mbed ;
4545
46- static internal_mem_resident_type_e internal_memory_residency = NONE;
47- static SingletonPtr<PlatformMutex> system_storage_mutex;
4846
49- MBED_WEAK int set_internal_storage_ownership (internal_mem_resident_type_e in_mem_res, internal_mem_resident_type_e *out_mem_res)
47+
48+ MBED_WEAK int avoid_conflict_nvstore_tdbstore (owner_type_e in_mem_owner)
5049{
5150 int status = MBED_SUCCESS;
51+ static PlatformMutex _mutex;
52+ static owner_type_e internal_memory_owner = NONE;
5253
53- system_storage_mutex-> lock ();
54+ _mutex. lock ();
5455
55- if (internal_memory_residency != NONE &&
56- internal_memory_residency != in_mem_res ) {
56+ if (internal_memory_owner != NONE &&
57+ internal_memory_owner != in_mem_owner ) {
5758
5859 status = MBED_ERROR_ALREADY_INITIALIZED;
5960
6061 } else {
6162
62- internal_memory_residency = in_mem_res ;
63+ internal_memory_owner = in_mem_owner ;
6364 }
6465
65- *out_mem_res = internal_memory_residency;
66- system_storage_mutex->unlock ();
66+ _mutex.unlock ();
6767
6868 return status;
6969}
Original file line number Diff line number Diff line change @@ -22,16 +22,15 @@ typedef enum {
2222 NONE = 0 ,
2323 NVSTORE ,
2424 TDBSTORE
25- } internal_mem_resident_type_e ;
25+ } owner_type_e ;
2626
2727/**
2828 * @brief Try to get an ownership for the internal flash memory storage type.
2929 * KVSTORE or NVSTORE is the current option and once the ownership is taken by one
3030 * second one can not be initialize.
31- * @param[in] in_mem_res Enum parameter to specify NVSTORE or KVSTORE as the storage owner
32- * @param[in] out_mem_res Enum parameter which specify who is the current owner of the storage.
31+ * @param[in] in_mem_owner Enum parameter to specify NVSTORE or KVSTORE as the storage owner
3332 * @returns MBED_SUCCESS if succeeded or MBED_ERROR_ALREADY_INITIALIZED if fails.
3433 */
35- int set_internal_storage_ownership ( internal_mem_resident_type_e in_mem_res , internal_mem_resident_type_e * out_mem_res );
34+ int avoid_conflict_nvstore_tdbstore ( owner_type_e in_mem_owner );
3635
3736#endif
You can’t perform that action at this time.
0 commit comments