szaszm commented on a change in pull request #674: Minificpp 1007 - ECU C2 
integration.
URL: https://github.com/apache/nifi-minifi-cpp/pull/674#discussion_r371957567
 
 

 ##########
 File path: nanofi/src/core/message_queue.c
 ##########
 @@ -0,0 +1,276 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <core/string_utils.h>
+#include <core/synchutils.h>
+#include <core/message_queue.h>
+#include <core/log.h>
+
+message_queue_t * create_msg_queue(uint64_t capacity_bytes) {
+    ring_buffer_t * rb = (ring_buffer_t *)malloc(sizeof(ring_buffer_t));
+    memset(rb, 0, sizeof(ring_buffer_t));
+    rb->capacity = capacity_bytes;
+    rb->data = (char *)malloc(rb->capacity);
+    message_queue_t * mq = (message_queue_t *)malloc(sizeof(message_queue_t));
+    memset(mq, 0, sizeof(message_queue_t));
+    mq->ring_buff = rb;
+    initialize_lock(&mq->queue_lock);
+#ifndef WIN32
+    initialize_cvattr(&mq->wrt_notify_attr);
+#ifndef __APPLE__
+    condition_attr_set_clock(&mq->wrt_notify_attr, CLOCK_MONOTONIC);
+#endif
+    initialize_cv(&mq->write_notify, &mq->wrt_notify_attr);
+#else
+    initialize_cv(&mq->write_notify, NULL);
+#endif
+    return mq;
+}
+
+void set_attribute_update_cb(message_queue_t * mq, attribute_set_cb_t cb) {
+    mq->attr_cb = cb;
+}
+
+void free_queue(message_queue_t * mq) {
+    if (!mq) return;
+    acquire_lock(&mq->queue_lock);
+    message_attrs_t * head = mq->attrs;
+    while (head) {
+        message_attrs_t * tmp = head;
+        head = head->next;
+        free_attributes(tmp->as);
+        free(tmp);
+    }
+    free_ring_buffer(mq->ring_buff);
+    destroy_lock(&mq->queue_lock);
+    destroy_cvattr(&mq->wrt_notify_attr);
+    destroy_cv(&mq->write_notify);
+    free(mq);
+}
+
+attribute_set prepare_attributes(properties_t * attributes) {
+    attribute_set as;
+    memset(&as, 0, sizeof(attribute_set));
+    if (!attributes) return as;
+
+    as.size = HASH_COUNT(attributes);
+    attribute * attrs = (attribute *)malloc(as.size * sizeof(attribute));
+
+    properties_t *p, *tmp;
+    int i = 0;
+    HASH_ITER(hh, attributes, p, tmp) {
+        attrs[i].key = (char *)malloc(strlen(p->key) + 1);
+        strcpy(attrs[i].key, p->key);
 
 Review comment:
   The `const` qualifier on `attrs[i].key` is ignored. We should first create 
the string as `char*` (non-`const`) then assign it to `attrs[i].key`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to