VineQueue: modify pop() to operate like std::queue 77/258377/2
authorSeonah Moon <seonah1.moon@samsung.com>
Fri, 14 May 2021 08:57:01 +0000 (17:57 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 20 May 2021 05:35:10 +0000 (14:35 +0900)
Change-Id: I92f75a430848b630d9cc280d7d336749c26d122d

plugins/libwebsockets/libwebsockets-plugin.cpp
src/include/vine-queue.h
src/vine-dp.cpp
src/vine-event-loop.cpp

index a9918a4..fed2d1b 100755 (executable)
@@ -231,7 +231,10 @@ static void _del_websocket_op_request(websocket_op_s *op)
 
 static void _process_websocket_op_request(void)
 {
-       websocket_op_s *op = op_queue.pop();
+       RET_IF(op_queue.empty(), "operation queue is NULL");
+
+       websocket_op_s *op = op_queue.front();
+       op_queue.pop();
        RET_IF(op == NULL, "op is NULL");
 
        if (!op->ws) {
@@ -764,10 +767,12 @@ static int _write_data(websocket_s *ws)
        websocket_data_s *wd = NULL;
        int bytes = 0;
 
-       if (!ws->write_buffer)
+       if (!ws->write_buffer || ws->write_buffer->empty())
                return bytes;
 
-       if ((wd = ws->write_buffer->pop())) {
+       wd = ws->write_buffer->front();
+       ws->write_buffer->pop();
+       if (wd) {
                unsigned char *out = (unsigned char *)calloc(LWS_PRE + wd->len,
                                sizeof(unsigned char));
                memcpy(out + LWS_PRE, wd->buf, wd->len);
@@ -810,7 +815,7 @@ static int websocket_read(vine_dp_plugin_h handle, unsigned char *buf, size_t le
        while (!ws->recv_buffer->empty() && len > 0) {
                wd = ws->recv_buffer->front();
                if (wd == nullptr) {
-                       ws->recv_buffer->erase();
+                       ws->recv_buffer->pop();
                        return bytes;
                }
 
@@ -821,7 +826,7 @@ static int websocket_read(vine_dp_plugin_h handle, unsigned char *buf, size_t le
                bytes += read_len;
 
                if (read_len >= wd->len) {
-                       ws->recv_buffer->erase();
+                       ws->recv_buffer->pop();
                        bool last = wd->last;
                        __destroy_websocket_data(wd);
                        wd = NULL;
index 4996394..5b805e8 100755 (executable)
@@ -40,20 +40,11 @@ public:
                _queue.push(element);
        }
 
-       T pop()
+       void pop()
        {
                std::lock_guard<std::mutex> lock_guard(_q_mutex);
                if (_queue.empty())
-                       return NULL;
-
-               T element = _queue.front();
-               _queue.pop();
-               return element;
-       }
-
-       void erase() // void pop
-       {
-               std::lock_guard<std::mutex> lock_guard(_q_mutex);
+                       return;
                _queue.pop();
        }
 
index 52c94db..f6f4f68 100644 (file)
@@ -1038,7 +1038,7 @@ int DPPubSub::recv(unsigned char *buf, size_t buf_len, size_t *read_len)
 
        *read_len = bytes;
        if (dp_info.second == 0)
-               mRecvDataPathList.erase();
+               mRecvDataPathList.pop();
 
        return VINE_ERROR_NONE;
 }
index d4af0c7..f069db0 100644 (file)
@@ -154,11 +154,15 @@ void vine_event_queue_destroy(vine_event_queue_h event_fd)
 {
        vine_event_queue_s *event_fd_handle = (vine_event_queue_s *)event_fd;
 
-       vine_event *event;
-       while ( (event = event_fd_handle->event_queue.pop()) != NULL) {
-               if (event->free_func)
+       vine_event *event = NULL;
+       while(!event_fd_handle->event_queue.empty()) {
+               event = event_fd_handle->event_queue.front();
+               if (event && event->free_func)
                        event->free_func(event->event_data);
+               event_fd_handle->event_queue.pop();
+               free(event);
        }
+
        if (event_fd_handle->fd >= 0)
                close(event_fd_handle->fd);
        delete event_fd_handle;
@@ -286,17 +290,18 @@ int vine_event_loop_process(vine_event_queue_h event_fd)
 
        VINE_LOGD("eventfd counter: %lld", u);
 
-       while (u--) {
-               vine_event *event = event_fd_handle->event_queue.pop();
+       while (u-- && !event_fd_handle->event_queue.empty()) {
+               vine_event *event = event_fd_handle->event_queue.front();
+               event_fd_handle->event_queue.pop();
                if (event == NULL) {
                        VINE_LOGE("vine event queue is empty");
-                       return VINE_ERROR_INVALID_OPERATION;
+                       continue;
                }
 
                VINE_LOGD("Vine event[%p]", event);
                if (event->handler == NULL) {
                        VINE_LOGI("No event handler");
-                       return VINE_ERROR_NONE;
+                       continue;
                }
 
                event->handler(event->event_data, event->user_data);