You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current device management framework is lacking in thread safety and maintainability, as the implementation for shell programs was simply repurposed for convenience at the time.
As it stands, functional operation of the device system is opaque and non trivial to understand at a glance.
A refactor is proposed to improve the structure of device management, allowing new devices to be added through a more streamlined process with greater clarity to developers not familiar with the codebase.
Detailed Description
Key areas for improvement:
Device Handle Management:
Implement a static array of device handles indexed by a header-defined enum. Provide a unified getter and setter for accessing device handles based on index.
Encapsulation:
Make device state variables opaque and expose getters and setters in the device API struct.
Thread Safety:
Assign a mutex to the state variables of each device driver. Add mutex locking to methods that modify device state to prevent race conditions.
Error Checking:
Add comprehensive error checking across device drivers -- in particular device initialisation and handle creation -- to ensure robustness and inform users of device status.
Optional
Configuration:
Extract device configuration variables to a header-defined struct and pass it to an initialization method to simplify and standardize device setup.
Example Implementation
Example code pending.
example.c
example.h
#ifndefEXAMPLE_H#defineEXAMPLE_H#endif
Motivation
This refactor will improve:
Readability: By redesigning the approach to device management to consider a simpler implementation.
Thread Safety: Ensuring consistent and safe device state manipulation in multi-threaded environments with critical sections where appropriate.
Scalability: Simplifying the addition of new devices by following a clearer standardized framework.
Portability: By allowing configuration parameters to be passed as a struct during initialization, making configuration more programmatic compared to the current design requiring positional arguments.
Dependencies
N/A
Other Considerations
N/A
The text was updated successfully, but these errors were encountered:
[REFACTOR] Refactor device management framework
Summary
The current device management framework is lacking in thread safety and maintainability, as the implementation for shell programs was simply repurposed for convenience at the time.
As it stands, functional operation of the device system is opaque and non trivial to understand at a glance.
A refactor is proposed to improve the structure of device management, allowing new devices to be added through a more streamlined process with greater clarity to developers not familiar with the codebase.
Detailed Description
Key areas for improvement:
Device Handle Management:
Implement a static array of device handles indexed by a header-defined
enum
. Provide a unified getter and setter for accessing device handles based on index.Encapsulation:
Make device state variables opaque and expose getters and setters in the device API struct.
Thread Safety:
Assign a mutex to the state variables of each device driver. Add mutex locking to methods that modify device state to prevent race conditions.
Error Checking:
Add comprehensive error checking across device drivers -- in particular device initialisation and handle creation -- to ensure robustness and inform users of device status.
Optional
Extract device configuration variables to a header-defined struct and pass it to an initialization method to simplify and standardize device setup.
Example Implementation
Example code pending.
example.c
example.h
Motivation
This refactor will improve:
Readability: By redesigning the approach to device management to consider a simpler implementation.
Thread Safety: Ensuring consistent and safe device state manipulation in multi-threaded environments with critical sections where appropriate.
Scalability: Simplifying the addition of new devices by following a clearer standardized framework.
Portability: By allowing configuration parameters to be passed as a struct during initialization, making configuration more programmatic compared to the current design requiring positional arguments.
Dependencies
N/A
Other Considerations
N/A
The text was updated successfully, but these errors were encountered: