removing output parameter from avoid_conflict_nvstore_tdbstore function.

pull/9136/head
Yossi Levy 2018-12-19 14:47:52 +02:00
parent fcd24aa62b
commit 677dbd1612
4 changed files with 15 additions and 18 deletions

View File

@ -953,7 +953,6 @@ int TDBStore::init()
uint32_t actual_data_size; uint32_t actual_data_size;
int os_ret, ret = MBED_SUCCESS, reserved_ret; int os_ret, ret = MBED_SUCCESS, reserved_ret;
uint16_t versions[_num_areas]; uint16_t versions[_num_areas];
internal_mem_resident_type_e out_in_mem_res;
_mutex.lock(); _mutex.lock();
@ -963,7 +962,7 @@ int TDBStore::init()
//Check if we are on internal memory && try to set the internal memory for TDBStore use. //Check if we are on internal memory && try to set the internal memory for TDBStore use.
if (strcmp(_bd->get_type(), "FLASHIAP") == 0 && if (strcmp(_bd->get_type(), "FLASHIAP") == 0 &&
set_internal_storage_ownership(TDBSTORE, &out_in_mem_res) == MBED_ERROR_ALREADY_INITIALIZED) { avoid_conflict_nvstore_tdbstore(TDBSTORE) == MBED_ERROR_ALREADY_INITIALIZED) {
MBED_ERROR(MBED_ERROR_ALREADY_INITIALIZED, "TDBStore in internal memory can not be initialize when NVStore is in use"); MBED_ERROR(MBED_ERROR_ALREADY_INITIALIZED, "TDBStore in internal memory can not be initialize when NVStore is in use");
} }

View File

@ -851,14 +851,13 @@ int NVStore::init()
uint16_t keys[NVSTORE_NUM_AREAS]; uint16_t keys[NVSTORE_NUM_AREAS];
uint16_t actual_size; uint16_t actual_size;
uint8_t owner; uint8_t owner;
internal_mem_resident_type_e out_in_mem_res;
if (_init_done) { if (_init_done) {
return NVSTORE_SUCCESS; return NVSTORE_SUCCESS;
} }
//Check if we are on internal memory && try to set the internal memory for TDBStore use. //Check if we are on internal memory && try to set the internal memory for TDBStore use.
ret = set_internal_storage_ownership(NVSTORE, &out_in_mem_res); ret = avoid_conflict_nvstore_tdbstore(NVSTORE);
//NVstore in internal memory can not be initialize when TDBStore is in use //NVstore in internal memory can not be initialize when TDBStore is in use
MBED_ASSERT(ret != MBED_ERROR_ALREADY_INITIALIZED); MBED_ASSERT(ret != MBED_ERROR_ALREADY_INITIALIZED);

View File

@ -43,27 +43,27 @@
using namespace mbed; using namespace mbed;
static internal_mem_resident_type_e internal_memory_residency = NONE;
static SingletonPtr<PlatformMutex> system_storage_mutex;
MBED_WEAK int set_internal_storage_ownership(internal_mem_resident_type_e in_mem_res, internal_mem_resident_type_e *out_mem_res)
MBED_WEAK int avoid_conflict_nvstore_tdbstore(owner_type_e in_mem_owner)
{ {
int status = MBED_SUCCESS; int status = MBED_SUCCESS;
static PlatformMutex _mutex;
static owner_type_e internal_memory_owner = NONE;
system_storage_mutex->lock(); _mutex.lock();
if (internal_memory_residency != NONE && if (internal_memory_owner != NONE &&
internal_memory_residency != in_mem_res) { internal_memory_owner != in_mem_owner) {
status = MBED_ERROR_ALREADY_INITIALIZED; status = MBED_ERROR_ALREADY_INITIALIZED;
} else { } else {
internal_memory_residency = in_mem_res; internal_memory_owner = in_mem_owner;
} }
*out_mem_res = internal_memory_residency; _mutex.unlock();
system_storage_mutex->unlock();
return status; return status;
} }

View File

@ -22,16 +22,15 @@ typedef enum {
NONE = 0, NONE = 0,
NVSTORE, NVSTORE,
TDBSTORE TDBSTORE
} internal_mem_resident_type_e; } owner_type_e;
/** /**
* @brief Try to get an ownership for the internal flash memory storage type. * @brief Try to get an ownership for the internal flash memory storage type.
* KVSTORE or NVSTORE is the current option and once the ownership is taken by one * KVSTORE or NVSTORE is the current option and once the ownership is taken by one
* second one can not be initialize. * second one can not be initialize.
* @param[in] in_mem_res Enum parameter to specify NVSTORE or KVSTORE as the storage owner * @param[in] in_mem_owner Enum parameter to specify NVSTORE or KVSTORE as the storage owner
* @param[in] out_mem_res Enum parameter which specify who is the current owner of the storage.
* @returns MBED_SUCCESS if succeeded or MBED_ERROR_ALREADY_INITIALIZED if fails. * @returns MBED_SUCCESS if succeeded or MBED_ERROR_ALREADY_INITIALIZED if fails.
*/ */
int set_internal_storage_ownership(internal_mem_resident_type_e in_mem_res, internal_mem_resident_type_e *out_mem_res); int avoid_conflict_nvstore_tdbstore(owner_type_e in_mem_owner);
#endif #endif