Skip to content

Commit 78464dd

Browse files
committed
skip lock FS for File name()/isDirectory()/isOpen()
1 parent f8cfa3d commit 78464dd

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ bool File::open (char const *filepath, uint8_t mode)
104104
{
105105
bool ret = false;
106106
_fs->_lockFS();
107+
107108
ret = this->_open(filepath, mode);
109+
108110
_fs->_unlockFS();
109111
return ret;
110112
}
@@ -114,7 +116,7 @@ bool File::_open (char const *filepath, uint8_t mode)
114116
bool ret = false;
115117

116118
// close if currently opened
117-
if ( this->_isOpen() ) _close();
119+
if ( this->isOpen() ) _close();
118120

119121
struct lfs_info info;
120122
int rc = lfs_stat(_fs->_getFS(), filepath, &info);
@@ -152,6 +154,7 @@ size_t File::write (uint8_t const *buf, size_t size)
152154
{
153155
lfs_ssize_t wrcount = 0;
154156
_fs->_lockFS();
157+
155158
if (!this->_is_dir)
156159
{
157160
wrcount = lfs_file_write(_fs->_getFS(), _file, buf, size);
@@ -160,6 +163,7 @@ size_t File::write (uint8_t const *buf, size_t size)
160163
wrcount = 0;
161164
}
162165
}
166+
163167
_fs->_unlockFS();
164168
return wrcount;
165169
}
@@ -180,10 +184,12 @@ int File::read (void *buf, uint16_t nbyte)
180184
{
181185
int ret = 0;
182186
_fs->_lockFS();
187+
183188
if (!this->_is_dir)
184189
{
185190
ret = lfs_file_read(_fs->_getFS(), _file, buf, nbyte);
186191
}
192+
187193
_fs->_unlockFS();
188194
return ret;
189195
}
@@ -192,6 +198,7 @@ int File::peek (void)
192198
{
193199
int ret = -1;
194200
_fs->_lockFS();
201+
195202
if (!this->_is_dir)
196203
{
197204
uint32_t pos = lfs_file_tell(_fs->_getFS(), _file);
@@ -200,8 +207,9 @@ int File::peek (void)
200207
{
201208
ret = static_cast<int>(ch);
202209
}
203-
(void)lfs_file_seek(_fs->_getFS(), _file, pos, LFS_SEEK_SET);
210+
(void) lfs_file_seek(_fs->_getFS(), _file, pos, LFS_SEEK_SET);
204211
}
212+
205213
_fs->_unlockFS();
206214
return ret;
207215
}
@@ -210,12 +218,14 @@ int File::available (void)
210218
{
211219
int ret = 0;
212220
_fs->_lockFS();
221+
213222
if (!this->_is_dir)
214223
{
215224
uint32_t size = lfs_file_size(_fs->_getFS(), _file);
216225
uint32_t pos = lfs_file_tell(_fs->_getFS(), _file);
217226
ret = size - pos;
218227
}
228+
219229
_fs->_unlockFS();
220230
return ret;
221231
}
@@ -224,10 +234,12 @@ bool File::seek (uint32_t pos)
224234
{
225235
bool ret = false;
226236
_fs->_lockFS();
237+
227238
if (!this->_is_dir)
228239
{
229240
ret = lfs_file_seek(_fs->_getFS(), _file, pos, LFS_SEEK_SET) >= 0;
230241
}
242+
231243
_fs->_unlockFS();
232244
return ret;
233245
}
@@ -236,10 +248,12 @@ uint32_t File::position (void)
236248
{
237249
uint32_t ret = 0;
238250
_fs->_lockFS();
251+
239252
if (!this->_is_dir)
240253
{
241254
ret = lfs_file_tell(_fs->_getFS(), _file);
242255
}
256+
243257
_fs->_unlockFS();
244258
return ret;
245259
}
@@ -248,22 +262,25 @@ uint32_t File::size (void)
248262
{
249263
uint32_t ret = 0;
250264
_fs->_lockFS();
265+
251266
if (!this->_is_dir)
252267
{
253268
ret = lfs_file_size(_fs->_getFS(), _file);
254269
}
270+
255271
_fs->_unlockFS();
256272
return ret;
257-
258273
}
259274

260275
void File::flush (void)
261276
{
262277
_fs->_lockFS();
278+
263279
if (!this->_is_dir)
264280
{
265281
lfs_file_sync(_fs->_getFS(), _file);
266282
}
283+
267284
_fs->_unlockFS();
268285
return;
269286
}
@@ -277,7 +294,7 @@ void File::close (void)
277294

278295
void File::_close(void)
279296
{
280-
if ( this->_isOpen() )
297+
if ( this->isOpen() )
281298
{
282299
if ( this->_is_dir )
283300
{
@@ -303,14 +320,6 @@ File::operator bool (void)
303320
}
304321

305322
bool File::isOpen(void)
306-
{
307-
bool ret = 0;
308-
_fs->_lockFS();
309-
ret = this->_isOpen();
310-
_fs->_unlockFS();
311-
return ret;
312-
}
313-
bool File::_isOpen(void)
314323
{
315324
return (_file != NULL) || (_dir != NULL);
316325
}
@@ -322,19 +331,12 @@ bool File::_isOpen(void)
322331
// suddenly (unexpectedly?) have different values.
323332
char const* File::name (void)
324333
{
325-
_fs->_lockFS();
326-
char const* ret = this->_name;
327-
_fs->_unlockFS();
328-
return ret;
334+
return this->_name;
329335
}
330336

331337
bool File::isDirectory (void)
332338
{
333-
_fs->_lockFS();
334-
bool ret = this->_is_dir;
335-
_fs->_unlockFS();
336-
return ret;
337-
339+
return this->_is_dir;
338340
}
339341

340342
File File::openNextFile (uint8_t mode)
@@ -381,6 +383,5 @@ void File::rewindDirectory (void)
381383
lfs_dir_rewind(_fs->_getFS(), _dir);
382384
}
383385
_fs->_unlockFS();
384-
return;
385386
}
386387

libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class File : public Stream
9898
bool _open_file(char const *filepath, uint8_t mode);
9999
bool _open_dir (char const *filepath);
100100
void _close(void);
101-
bool _isOpen(void);
102101
};
103102

104103
}

0 commit comments

Comments
 (0)