-
Notifications
You must be signed in to change notification settings - Fork 2
refactor(core): Use GLib containers in subsystemManager #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This change replaces the use of `icLinkedList` and `icHashMap` with `GList` and `GHashTable`. Refs: BARTON-245 Signed-off-by: gindur772 <Ganesh_Induri@comcast.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactoring is a perfect time to first add tests (unit in this case). You can then be sure that the tests are good before the refactoring, and that after refactoring it works as well.
scoped_icLinkedListGeneric *subsystems = subsystemManagerGetRegisteredSubsystems(); | ||
sbIcLinkedListIterator *subsystemsIt = linkedListIteratorCreate(subsystems); | ||
while (linkedListIteratorHasNext(subsystemsIt)) | ||
GList *subsystems = subsystemManagerGetRegisteredSubsystems(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use g_auto style cleanup. Especially if refactoring another auto cleanup method (scoped_*)
I will write the tests for subSystemManager.c first then will do the refactoring making nothing is broken. |
scoped_icLinkedListGeneric *subsystems = subsystemManagerGetRegisteredSubsystems(); | ||
sbIcLinkedListIterator *subsystemsIt = linkedListIteratorCreate(subsystems); | ||
while (linkedListIteratorHasNext(subsystemsIt)) | ||
GList *subsystems = subsystemManagerGetRegisteredSubsystems(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try not to remove scoped bound resource management where it is used. GLib has an expansive g_auto* system for automatic resource cleanup (such as g_autolist).
Another thing is I would recommend exploring swapping lists of strings to GPtrArray as it's going to usually be much more performant than doubly linked lists without the complexity/headache of trying to use arrays of arrays in C directly.
static bool allDriversStarted = false; | ||
static subsystemManagerReadyForDevicesFunc readyForDevicesCB = NULL; | ||
static void checkSubsystemForMigration(SubsystemRegistration *registration); | ||
|
||
static void subsystemRegistrationDestroy(SubsystemRegistration *reg) | ||
{ | ||
pthread_mutex_destroy(®->mtx); | ||
free(reg); | ||
g_free(reg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the future, no need to swap frees to g_frees. Technically glib's allocator/deallocator implementations will (mostly) use platform-specific malloc/free but we're not too concerned with an extremely high level of portability - free/malloc/calloc are perfectly fine for non-glib types.
This looks like it should maybe also be in draft? |
This change replaces the use of
icLinkedList
andicHashMap
withGList
andGHashTable
.Refs: BARTON-245