summaryrefslogtreecommitdiffstats
path: root/lib/4a-hal-utilities
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-14 18:15:32 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-18 11:34:58 +0200
commit6a572877593e592dbaaba6f5649bc7744cd714c7 (patch)
treeee1582e411eac8a30913036efc3da0112a90de7c /lib/4a-hal-utilities
parent24046bfdb0568077a074b503d58a343a06f4234a (diff)
Refactoring 'hal data' linked list
Refactoring 'hal data' linked list code using liburcu. BUG-AGL: SPEC-2329 Change-Id: Ia51d362f96838f4b5bb77e8d1b85fa8d1ab4bed1 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'lib/4a-hal-utilities')
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.c171
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.h18
2 files changed, 61 insertions, 128 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c
index 98e3fa0..979f46d 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c
@@ -33,6 +33,7 @@
void HalUtlFreeSelectedProbedDeviceAllocation(struct InternalHalProbedDevice *probedDeviceToFree);
void HalUtlFreeSelectedMixerDataAllocation(struct InternalHalMixerData *mixerDataToFree);
+void HalUtlFreeSelectedHalAllocation(struct HalData *halDataToFree);
/*******************************************************************************
* Internal Hal - Generic function for linked list *
@@ -61,6 +62,13 @@ void *HalUtlAddNodeInList(struct cds_list_head *listHead, enum LinkedListType li
nodeToAdd = &((struct InternalHalMixerData *) returned)->node;
break;
+ case LINKED_LIST_FOR_HAL_DATA:
+ returned = calloc(1, sizeof(struct HalData));
+ if(! returned)
+ return NULL;
+ nodeToAdd = &((struct HalData *) returned)->node;
+ break;
+
default:
return NULL;
}
@@ -88,6 +96,12 @@ int HalUtlRemoveNodeFromList(struct cds_list_head *listHead, void *dataToRemove,
HalUtlFreeSelectedMixerDataAllocation((struct InternalHalMixerData *) dataToRemove);
break;
+ case LINKED_LIST_FOR_HAL_DATA:
+ cds_list_del(&((struct HalData *) dataToRemove)->node);
+
+ HalUtlFreeSelectedHalAllocation((struct HalData *) dataToRemove);
+ break;
+
default:
return -2;
}
@@ -121,8 +135,14 @@ int HalUtlRemoveAllNodeFromList(struct cds_list_head *listHead, enum LinkedListT
return -3;
break;
+ case LINKED_LIST_FOR_HAL_DATA:
+ if(HalUtlRemoveSelectedHalFromList(listHead,
+ cds_list_entry(nodeToRemove, struct HalData, node)))
+ return -4;
+ break;
+
default:
- return -4;
+ return -5;
}
nodesRemoved++;
@@ -745,150 +765,64 @@ json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct cds_
* Hal data handling functions *
******************************************************************************/
-struct HalData *HalUtlAddHalToHalList(struct HalData **halDataList)
+void HalUtlFreeSelectedHalAllocation(struct HalData *halDataToFree)
{
- struct HalData *currentHalData;
+ if(! halDataToFree)
+ return;
- if(! halDataList)
- return NULL;
+ free(halDataToFree->apiName);
+ free(halDataToFree->sndCardPath);
+ free(halDataToFree->info);
+ free(halDataToFree->author);
+ free(halDataToFree->version);
+ free(halDataToFree->date);
- currentHalData = *halDataList;
- if(! currentHalData) {
- currentHalData = (struct HalData *) calloc(1, sizeof(struct HalData));
- if(! currentHalData)
- return NULL;
+ if(halDataToFree->internal) {
+ free(halDataToFree->internalHalData->mixerApiName);
+ free(halDataToFree->internalHalData->prefix);
- *halDataList = currentHalData;
- }
- else {
- while(currentHalData->next)
- currentHalData = currentHalData->next;
+ HalUtlRemoveAllProbedDevicesFromList(&halDataToFree->internalHalData->probedDevicesListHead);
- currentHalData->next = calloc(1, sizeof(struct HalData));
- if(! currentHalData->next)
- return NULL;
+ HalUtlRemoveAllMixerData(&halDataToFree->internalHalData->streamsDataListHead);
- currentHalData = currentHalData->next;
+ HalUtlFreeAlsaCtlsMap(halDataToFree->internalHalData->alsaMapT);
+
+ free(halDataToFree->internalHalData);
}
- return currentHalData;
+ free(halDataToFree);
}
-int HalUtlRemoveSelectedHalFromList(struct HalData **halDataList, struct HalData *halToRemove)
+struct HalData *HalUtlAddHalToHalList(struct cds_list_head *halDataListHead)
{
- struct HalData *currentHalData, *matchingHal;
-
- if(! halDataList || ! *halDataList || ! halToRemove)
- return -1;
-
- currentHalData = *halDataList;
- if(currentHalData == halToRemove) {
- *halDataList = currentHalData->next;
- matchingHal = currentHalData;
- }
- else {
- while(currentHalData && currentHalData->next != halToRemove)
- currentHalData = currentHalData->next;
-
- if(currentHalData) {
- matchingHal = currentHalData->next;
- currentHalData->next = currentHalData->next->next;
- }
- else {
- return -2;
- }
- }
-
- free(matchingHal->apiName);
- free(matchingHal->sndCardPath);
- free(matchingHal->info);
- free(matchingHal->author);
- free(matchingHal->version);
- free(matchingHal->date);
-
- if(matchingHal->internal) {
- free(matchingHal->internalHalData->mixerApiName);
- free(matchingHal->internalHalData->prefix);
-
- HalUtlRemoveAllProbedDevicesFromList(&matchingHal->internalHalData->probedDevicesListHead);
-
- HalUtlRemoveAllMixerData(&matchingHal->internalHalData->streamsDataListHead);
-
- HalUtlFreeAlsaCtlsMap(matchingHal->internalHalData->alsaMapT);
-
- free(matchingHal->internalHalData);
- }
-
- free(matchingHal);
-
- return 0;
+ return (struct HalData *) HalUtlAddNodeInList(halDataListHead, LINKED_LIST_FOR_HAL_DATA);
}
-int HalUtlRemoveAllHalFromList(struct HalData **halDataList)
+int HalUtlRemoveSelectedHalFromList(struct cds_list_head *halDataListHead, struct HalData *halToRemove)
{
- int halRemoved = 0;
-
- if(! halDataList)
- return -1;
-
- while(*halDataList) {
- if(HalUtlRemoveSelectedHalFromList(halDataList, *halDataList))
- return -2;
-
- halRemoved++;
- }
-
- return halRemoved;
+ return HalUtlRemoveNodeFromList(halDataListHead, (void *) halToRemove, LINKED_LIST_FOR_HAL_DATA);
}
-int HalUtlGetNumberOfHalInList(struct HalData **halDataList)
+int HalUtlRemoveAllHalFromList(struct cds_list_head *halDataListHead)
{
- int numberOfHal = 0;
- struct HalData *currentHalData;
-
- if(! halDataList)
- return -1;
-
- currentHalData = *halDataList;
- while(currentHalData) {
- currentHalData = currentHalData->next;
- numberOfHal++;
- }
-
- return numberOfHal;
+ return HalUtlRemoveAllNodeFromList(halDataListHead, LINKED_LIST_FOR_HAL_DATA);
}
-struct HalData *HalUtlSearchHalDataByApiName(struct HalData **halDataList, char *apiName)
+int HalUtlGetNumberOfHalInList(struct cds_list_head *halDataListHead)
{
- struct HalData *currentHalData;
-
- if(! halDataList || ! *halDataList || ! apiName)
- return NULL;
-
- currentHalData = *halDataList;
- while(currentHalData) {
- if(! strcmp(apiName, currentHalData->apiName))
- return currentHalData;
-
- currentHalData = currentHalData->next;
- }
-
- return NULL;
+ return HalUtlGetNumberOfNodesInList(halDataListHead);
}
-struct HalData *HalUtlSearchReadyHalDataByCardId(struct HalData **halDataList, int cardId)
+struct HalData *HalUtlSearchHalDataByApiName(struct cds_list_head *halDataListHead, char *apiName)
{
struct HalData *currentHalData;
- if(! halDataList || ! *halDataList)
+ if(! halDataListHead || cds_list_empty(halDataListHead) || ! apiName)
return NULL;
- currentHalData = *halDataList;
- while(currentHalData) {
- if(currentHalData->status == HAL_STATUS_READY && currentHalData->sndCardId == cardId)
+ cds_list_for_each_entry(currentHalData, halDataListHead, node) {
+ if(! strcmp(apiName, currentHalData->apiName))
return currentHalData;
-
- currentHalData = currentHalData->next;
}
return NULL;
@@ -922,8 +856,7 @@ void HalUtlRemoveHalMgrData(struct HalMgrData *halMgrData)
if(! halMgrData)
return;
- if(halMgrData->halDataList)
- HalUtlRemoveAllHalFromList(&halMgrData->halDataList);
+ HalUtlRemoveAllHalFromList(&halMgrData->halDataListHead);
free(halMgrData->apiName);
free(halMgrData->info);
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.h b/lib/4a-hal-utilities/4a-hal-utilities-data.h
index 8bddbbb..48420cd 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.h
@@ -37,7 +37,8 @@
// Enum for linked list type
enum LinkedListType {
LINKED_LIST_FOR_DEPENDENCIES_DATA = 0,
- LINKED_LIST_FOR_MIXER_DATA = 1
+ LINKED_LIST_FOR_MIXER_DATA = 1,
+ LINKED_LIST_FOR_HAL_DATA = 2
};
// Enum for hal status
@@ -138,7 +139,7 @@ struct HalData {
struct InternalHalData *internalHalData; // Can be NULL if external api
- struct HalData *next;
+ struct cds_list_head node;
};
// Structure to store hal manager data
@@ -148,7 +149,7 @@ struct HalMgrData {
afb_api_t apiHandle;
- struct HalData *halDataList;
+ struct cds_list_head halDataListHead;
};
// Internal Hal - Probed devices structure handling functions
@@ -190,12 +191,11 @@ json_object *HalUtlGetJsonArrayForSpecificMixerData(afb_api_t apiHandle, struct
json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct cds_list_head *mixerDataListHead);
// Hal data handling functions
-struct HalData *HalUtlAddHalToHalList(struct HalData **halDataList);
-int HalUtlRemoveSelectedHalFromList(struct HalData **halDataList, struct HalData *halToRemove);
-int HalUtlRemoveAllHalFromList(struct HalData **halDataList);
-int HalUtlGetNumberOfHalInList(struct HalData **halDataList);
-struct HalData *HalUtlSearchHalDataByApiName(struct HalData **halDataList, char *apiName);
-struct HalData *HalUtlSearchReadyHalDataByCardId(struct HalData **halDataList, int cardId);
+struct HalData *HalUtlAddHalToHalList(struct cds_list_head *halDataListHead);
+int HalUtlRemoveSelectedHalFromList(struct cds_list_head *halDataListHead, struct HalData *halToRemove);
+int HalUtlRemoveAllHalFromList(struct cds_list_head *halDataListHead);
+int HalUtlGetNumberOfHalInList(struct cds_list_head *halDataListHead);
+struct HalData *HalUtlSearchHalDataByApiName(struct cds_list_head *halDataListHead, char *apiName);
// Hal Manager data handling functions
int HalUtlInitializeHalMgrData(afb_api_t apiHandle, struct HalMgrData *halMgrData, char *apiName, char *info);