Skip to content

Commit

Permalink
wutdevoptab: Use scoped_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Apr 8, 2023
1 parent d73dc40 commit b076627
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 13 deletions.
1 change: 0 additions & 1 deletion libraries/wutdevoptab/MutexWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class MutexWrapper {

void unlock() {
OSUnlockMutex(&mutex);
OSMemoryBarrier();
}

private:
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_close.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ __wut_fsa_close(struct _reent *r,

deviceData = (__wut_fsa_device_t *) r->deviceData;

std::lock_guard<MutexWrapper> lock(file->mutex);
std::scoped_lock lock(file->mutex);

status = FSACloseFile(deviceData->clientHandle, file->fd);
if (status < 0) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_dirclose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ __wut_fsa_dirclose(struct _reent *r,

deviceData = (__wut_fsa_device_t *) r->deviceData;

std::lock_guard<MutexWrapper> lock(dir->mutex);
std::scoped_lock lock(dir->mutex);

status = FSACloseDir(deviceData->clientHandle, dir->fd);
if (status < 0) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_dirnext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ __wut_fsa_dirnext(struct _reent *r,
deviceData = (__wut_fsa_device_t *) r->deviceData;
dir = (__wut_fsa_dir_t *) (dirState->dirStruct);

std::lock_guard<MutexWrapper> lock(dir->mutex);
std::scoped_lock lock(dir->mutex);
memset(&dir->entry_data, 0, sizeof(dir->entry_data));

status = FSAReadDir(deviceData->clientHandle, dir->fd, &dir->entry_data);
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_diropen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ __wut_fsa_diropen(struct _reent *r,
free(fixedPath);

dir->mutex.init(dir->name);
std::lock_guard<MutexWrapper> lock(dir->mutex);
std::scoped_lock lock(dir->mutex);

deviceData = (__wut_fsa_device_t *) r->deviceData;
status = FSAOpenDir(deviceData->clientHandle, dir->name, &fd);
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_dirreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ __wut_fsa_dirreset(struct _reent *r,
dir = (__wut_fsa_dir_t *) (dirState->dirStruct);
deviceData = (__wut_fsa_device_t *) r->deviceData;

std::lock_guard<MutexWrapper> lock(dir->mutex);
std::scoped_lock lock(dir->mutex);

status = FSARewindDir(deviceData->clientHandle, dir->fd);
if (status < 0) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_fstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ __wut_fsa_fstat(struct _reent *r,
file = (__wut_fsa_file_t *) fd;
deviceData = (__wut_fsa_device_t *) r->deviceData;

std::lock_guard<MutexWrapper> lock(file->mutex);
std::scoped_lock lock(file->mutex);

status = FSAGetStatFile(deviceData->clientHandle, file->fd, &fsStat);
if (status < 0) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_fsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ __wut_fsa_fsync(struct _reent *r,

deviceData = (__wut_fsa_device_t *) r->deviceData;

std::lock_guard<MutexWrapper> lock(file->mutex);
std::scoped_lock lock(file->mutex);

status = FSAFlushFile(deviceData->clientHandle, file->fd);
if (status < 0) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ __wut_fsa_open(struct _reent *r,

// Init mutex and lock
file->mutex.init(file->fullPath);
std::lock_guard<MutexWrapper> lock(file->mutex);
std::scoped_lock lock(file->mutex);

if (createFileIfNotFound || failIfFileNotFound || (flags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) {
// Check if file exists
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ssize_t __wut_fsa_read(struct _reent *r, void *fd, char *ptr, size_t len) {

deviceData = (__wut_fsa_device_t *) r->deviceData;

std::lock_guard<MutexWrapper> lock(file->mutex);
std::scoped_lock lock(file->mutex);

size_t bytesRead = 0;
while (bytesRead < len) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_seek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ __wut_fsa_seek(struct _reent *r,

deviceData = (__wut_fsa_device_t *) r->deviceData;

std::lock_guard<MutexWrapper> lock(file->mutex);
std::scoped_lock lock(file->mutex);

// Find the offset to see from
switch (whence) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_truncate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ __wut_fsa_ftruncate(struct _reent *r,

deviceData = (__wut_fsa_device_t *) r->deviceData;

std::lock_guard<MutexWrapper> lock(file->mutex);
std::scoped_lock lock(file->mutex);

// Set the new file size
status = FSASetPosFile(deviceData->clientHandle, file->fd, len);
Expand Down
2 changes: 1 addition & 1 deletion libraries/wutdevoptab/devoptab_fsa_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ssize_t __wut_fsa_write(struct _reent *r, void *fd, const char *ptr, size_t len)

deviceData = (__wut_fsa_device_t *) r->deviceData;

std::lock_guard<MutexWrapper> lock(file->mutex);
std::scoped_lock lock(file->mutex);

// If O_APPEND is set, we always write to the end of the file.
// When writing we file->offset to the file size to keep in sync.
Expand Down

0 comments on commit b076627

Please sign in to comment.