Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ganeshInduri434
Copy link

This change replaces the use of icLinkedList and icHashMap with GList and GHashTable.

Refs: BARTON-245

This change replaces the use of `icLinkedList` and `icHashMap`
with `GList` and `GHashTable`.

Refs: BARTON-245

Signed-off-by: gindur772 <Ganesh_Induri@comcast.com>
@CLAassistant
Copy link

CLAassistant commented May 5, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@tleacmcsa tleacmcsa left a 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();
Copy link
Contributor

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_*)

@ganeshInduri434
Copy link
Author

I will write the tests for subSystemManager.c first then will do the refactoring making nothing is broken.
until then I will put this in draft.

scoped_icLinkedListGeneric *subsystems = subsystemManagerGetRegisteredSubsystems();
sbIcLinkedListIterator *subsystemsIt = linkedListIteratorCreate(subsystems);
while (linkedListIteratorHasNext(subsystemsIt))
GList *subsystems = subsystemManagerGetRegisteredSubsystems();
Copy link
Contributor

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(&reg->mtx);
free(reg);
g_free(reg);
Copy link
Contributor

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.

@cleithner-comcast
Copy link
Contributor

This looks like it should maybe also be in draft?

@ganeshInduri434 ganeshInduri434 marked this pull request as draft May 12, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants