summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorNaresh Munagala <nareshm@codeaurora.org>2018-10-10 16:53:28 +0530
committerGerrit - the friendly Code Review server <code-review@localhost>2019-02-20 08:37:19 -0800
commitae8db6cf15b243e58efddae88d2790a4a59bca81 (patch)
treece604ca3cb83a5c1c645aac4e9b8e61ca4b7650a /utils
parent8e120b1ed9b7c3f600f946828e29c6eb42286a31 (diff)
downloadgps-ae8db6cf15b243e58efddae88d2790a4a59bca81.tar.gz
add remove api for message queue
Change-Id: I278eca90ebb50e291a1b9076caf46f41a074b1d7 CRs-Fixed: 2338245
Diffstat (limited to 'utils')
-rw-r--r--utils/linked_list.h2
-rw-r--r--utils/msg_q.c45
-rw-r--r--utils/msg_q.h23
3 files changed, 70 insertions, 0 deletions
diff --git a/utils/linked_list.h b/utils/linked_list.h
index a85f09a..0b33ecb 100644
--- a/utils/linked_list.h
+++ b/utils/linked_list.h
@@ -50,6 +50,8 @@ typedef enum
/**< Failed because an there were not enough resources. */
eLINKED_LIST_INSUFFICIENT_BUFFER = -5,
/**< Failed because an the supplied buffer was too small. */
+ eLINKED_LIST_EMPTY = -6
+ /**< Failed because list is empty. */
}linked_list_err_type;
/*===========================================================================
diff --git a/utils/msg_q.c b/utils/msg_q.c
index 76c1478..2d49b4a 100644
--- a/utils/msg_q.c
+++ b/utils/msg_q.c
@@ -267,6 +267,51 @@ msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj)
/*===========================================================================
+ FUNCTION: msg_q_rmv
+
+ ===========================================================================*/
+msq_q_err_type msg_q_rmv(void* msg_q_data, void** msg_obj)
+{
+ msq_q_err_type rv;
+ if (msg_q_data == NULL) {
+ LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__);
+ return eMSG_Q_INVALID_HANDLE;
+ }
+
+ if (msg_obj == NULL) {
+ LOC_LOGE("%s: Invalid msg_obj parameter!\n", __FUNCTION__);
+ return eMSG_Q_INVALID_PARAMETER;
+ }
+
+ msg_q* p_msg_q = (msg_q*)msg_q_data;
+
+ pthread_mutex_lock(&p_msg_q->list_mutex);
+
+ if (p_msg_q->unblocked) {
+ LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__);
+ pthread_mutex_unlock(&p_msg_q->list_mutex);
+ return eMSG_Q_UNAVAILABLE_RESOURCE;
+ }
+
+ if (linked_list_empty(p_msg_q->msg_list)) {
+ LOC_LOGW("%s: list is empty !!\n", __FUNCTION__);
+ pthread_mutex_unlock(&p_msg_q->list_mutex);
+ return eLINKED_LIST_EMPTY;
+ }
+
+ rv = convert_linked_list_err_type(linked_list_remove(p_msg_q->msg_list, msg_obj));
+
+ pthread_mutex_unlock(&p_msg_q->list_mutex);
+
+ LOC_LOGV("%s: Removed message %p rv = %d\n", __FUNCTION__, *msg_obj, rv);
+
+ return rv;
+}
+
+
+
+/*===========================================================================
+
FUNCTION: msg_q_flush
===========================================================================*/
diff --git a/utils/msg_q.h b/utils/msg_q.h
index 453b8ce..16df494 100644
--- a/utils/msg_q.h
+++ b/utils/msg_q.h
@@ -158,6 +158,29 @@ SIDE EFFECTS
msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj);
/*===========================================================================
+FUNCTION msg_q_rmv
+
+DESCRIPTION
+ Remove data from the message queue. msg_obj is the oldest message received
+ and pointer is simply removed from message queue.
+
+ msg_q_data: Message Queue to copy data from into msgp.
+ msg_obj: Pointer to space to copy msg_q contents to.
+
+DEPENDENCIES
+ N/A
+
+RETURN VALUE
+ Look at error codes above.
+
+SIDE EFFECTS
+ N/A
+
+===========================================================================*/
+msq_q_err_type msg_q_rmv(void* msg_q_data, void** msg_obj);
+
+
+/*===========================================================================
FUNCTION msg_q_flush
DESCRIPTION