Thread-Safe and RAII conformant getData() and modifyData() pool calls #74
Labels
No Label
API Change
Breaking API Change
bug
build
cosmetics
Documentation
duplicate
feature
help wanted
hotfix
invalid
question
Refactor
Tests
wontfix
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: fsfw/fsfw#74
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
As discussed in #68 and #60 ,
I implemented a thread-safe and RAII conformant access wrapper for the modifyData() and getData() calls. Using this wrapper/accessor allows to reduce the number of output/input variables to a minimum: The call takes the storeId and returns a std::pair consisting of a returnvalue and a StoreAccessor class instance (move semantics) which can be used to access and modify the locked datapool.
The current test code uses the new DHB interface so it doesn't make a lot of sense to make a pull request right now, I can't check whether it compiles now without changing the test code back or writing unit tests, I stil requested a WIP pull request to allow reviewers to inspect a first version.
An alternative constructor could be written which takes a reference to a previously created StoreAccessor() and assigns it. Good thing about the ctor which simply takes a storeId is that it prevents using an uninitialized StoreAccessor instance.
When the accessor exits the scope, itis destroyed, unlocks the mutex und deletes the data. If deletion is not desired,
release()
can be used to prevent deletion.Manual locking and unlocking is possible with
lock(...)
andunlock()
.Some other adaptions in other parts of the code:
I can't use exceptions so I used an internal state the track failed mutex locks.
I had to adapt the StorageManagerIF*, I need an explicit function to lock the pool without a mutex lock, otherwise a double lock is attempted.
I also adapted the mutexHelper to have an internal state, because I could not use exceptions in the constructor to track failed locks.
The accessor it also use of modern C++ features like move semantics and smart pointers.
Accessor was simplified and only handles storage deletion now.
Two new calls for modifyData() and getData() could be used:
Fist call takes a store ID and returns a pair of a returnvalue and a (Const)Storage Acessor instance
Second call takes a store ID and a reference to a storage helper instance (Const)StorageAccessor
Maybe something for the future:
I suggest a lockPool() and unlockPool() call for the PoolManager, in case the developer still wants thread-safe access (however, this propably would require a special PoolManagerIF which just requires implementing those functions)