nvs_flash: Reduced visibility of handle counter

Monotonically increasing handle counter need not be visible outside the HandleEntry class.

Signed-off-by: Amey Inamdar <amey.inamdar@gmail.com>
This commit is contained in:
Amey Inamdar 2017-08-16 09:46:34 +05:30
parent 9b18625d29
commit 3e4e4dd07a

View file

@ -30,11 +30,12 @@ static const char* TAG = "nvs";
class HandleEntry : public intrusive_list_node<HandleEntry> class HandleEntry : public intrusive_list_node<HandleEntry>
{ {
static uint32_t s_nvs_next_handle;
public: public:
HandleEntry() {} HandleEntry() {}
HandleEntry(nvs_handle handle, bool readOnly, uint8_t nsIndex) : HandleEntry(bool readOnly, uint8_t nsIndex) :
mHandle(handle), mHandle(++s_nvs_next_handle), // Begin the handle value with 1
mReadOnly(readOnly), mReadOnly(readOnly),
mNsIndex(nsIndex) mNsIndex(nsIndex)
{ {
@ -53,7 +54,7 @@ using namespace std;
using namespace nvs; using namespace nvs;
static intrusive_list<HandleEntry> s_nvs_handles; static intrusive_list<HandleEntry> s_nvs_handles;
static uint32_t s_nvs_next_handle = 1; uint32_t HandleEntry::s_nvs_next_handle;
static nvs::Storage s_nvs_storage; static nvs::Storage s_nvs_storage;
extern "C" void nvs_dump() extern "C" void nvs_dump()
@ -121,11 +122,11 @@ extern "C" esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_han
return err; return err;
} }
uint32_t handle = s_nvs_next_handle; HandleEntry *handle_entry = new HandleEntry(open_mode==NVS_READONLY, nsIndex);
++s_nvs_next_handle; s_nvs_handles.push_back(handle_entry);
*out_handle = handle;
*out_handle = handle_entry->mHandle;
s_nvs_handles.push_back(new HandleEntry(handle, open_mode==NVS_READONLY, nsIndex));
return ESP_OK; return ESP_OK;
} }