Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of FATFileSystem by
Diff: FATDirHandle.cpp
- Revision:
- 8:c4baca9a2c3d
- Parent:
- 5:b3b3370574cf
--- a/FATDirHandle.cpp Fri Dec 11 16:16:25 2015 +0000 +++ b/FATDirHandle.cpp Thu Aug 25 09:34:29 2016 +0100 @@ -25,12 +25,14 @@ using namespace mbed; -FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir) { +FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir, PlatformMutex * mutex): _mutex(mutex) { dir = the_dir; } int FATDirHandle::closedir() { + lock(); int retval = f_closedir(&dir); + unlock(); delete this; return retval; } @@ -38,6 +40,7 @@ struct dirent *FATDirHandle::readdir() { FILINFO finfo; + lock(); #if _USE_LFN finfo.lfname = cur_entry.d_name; finfo.lfsize = sizeof(cur_entry.d_name); @@ -47,33 +50,52 @@ #if _USE_LFN if(res != 0 || finfo.fname[0]==0) { + unlock(); return NULL; } else { if(cur_entry.d_name[0]==0) { // No long filename so use short filename. memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); } + unlock(); return &cur_entry; } #else if(res != 0 || finfo.fname[0]==0) { + unlock(); return NULL; } else { memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); + unlock(); return &cur_entry; } #endif /* _USE_LFN */ } void FATDirHandle::rewinddir() { + lock(); dir.index = 0; + unlock(); } off_t FATDirHandle::telldir() { - return dir.index; + lock(); + off_t offset = dir.index; + unlock(); + return offset; } void FATDirHandle::seekdir(off_t location) { + lock(); dir.index = location; + unlock(); } +void FATDirHandle::lock() { + _mutex->lock(); +} + +void FATDirHandle::unlock() { + _mutex->unlock(); +} +