You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2018/02/21 22:14:54 UTC

[1/3] qpid-proton git commit: PROTON-1766: [c] Move pn_connection_driver_ptr back to to connection_driver.h

Repository: qpid-proton
Updated Branches:
  refs/heads/master 431a86a80 -> 391397f59


PROTON-1766: [c] Move pn_connection_driver_ptr back to to connection_driver.h


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/06667197
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/06667197
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/06667197

Branch: refs/heads/master
Commit: 06667197824bf1bbf8dc903c80ad3c651302e73c
Parents: 431a86a
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Feb 21 14:49:12 2018 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Feb 21 17:01:55 2018 -0500

----------------------------------------------------------------------
 proton-c/include/proton/connection_driver.h    | 13 ++++++++
 proton-c/src/core/connection_driver-internal.h | 35 ---------------------
 proton-c/src/core/connection_driver.c          |  2 +-
 proton-c/src/proactor/epoll.c                  |  1 -
 4 files changed, 14 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/06667197/proton-c/include/proton/connection_driver.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/connection_driver.h b/proton-c/include/proton/connection_driver.h
index 8e39551..e83e2e9 100644
--- a/proton-c/include/proton/connection_driver.h
+++ b/proton-c/include/proton/connection_driver.h
@@ -267,6 +267,19 @@ PN_EXTERN void pn_connection_driver_logf(pn_connection_driver_t *d, const char *
 PN_EXTERN void pn_connection_driver_vlogf(pn_connection_driver_t *d, const char *fmt, va_list ap);
 
 /**
+ * Associate a pn_connection_t with its pn_connection_driver_t.
+ *
+ * **NOTE**: this is only for use by IO integration writers. If you are using the standard
+ * pn_proactor_t you *must not* use this function.
+ *
+ * @return pointer to the pn_connection_driver_t* field in a pn_connection_t.
+ *
+ * Return type is pointer to a pointer so that the caller can (if desired) use
+ * atomic operations when loading and storing the value.
+ */
+PN_EXTERN pn_connection_driver_t **pn_connection_driver_ptr(pn_connection_t *connection);
+
+/**
  * @}
  */
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/06667197/proton-c/src/core/connection_driver-internal.h
----------------------------------------------------------------------
diff --git a/proton-c/src/core/connection_driver-internal.h b/proton-c/src/core/connection_driver-internal.h
deleted file mode 100644
index 519a25b..0000000
--- a/proton-c/src/core/connection_driver-internal.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef CORE_CONNECTION_DRIVER_INTERNAL_H
-#define CORE_CONNECTION_DRIVER_INTERNAL_H
-
-/*
- * 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 <proton/import_export.h>
-#include <proton/connection_driver.h>
-
-/**
- * @return pointer to the pn_connection_driver_t* field in a pn_connection_t.
- * Only for use by IO integration code (e.g. pn_proactor_t implementations use this pointer)
- *
- * Return type is pointer to a pointer so that the caller can (if desired) use
- * atomic operations when loading and storing the value.
- */
-PN_EXTERN pn_connection_driver_t **pn_connection_driver_ptr(pn_connection_t *connection);
-
-#endif // CORE_CONNECTION_DRIVER_INTERNAL_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/06667197/proton-c/src/core/connection_driver.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/connection_driver.c b/proton-c/src/core/connection_driver.c
index 2460a4a..7120f2c 100644
--- a/proton-c/src/core/connection_driver.c
+++ b/proton-c/src/core/connection_driver.c
@@ -18,9 +18,9 @@
  */
 
 #include "engine-internal.h"
-#include "connection_driver-internal.h"
 #include <proton/condition.h>
 #include <proton/connection.h>
+#include <proton/connection_driver.h>
 #include <proton/event.h>
 #include <proton/transport.h>
 #include <string.h>

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/06667197/proton-c/src/proactor/epoll.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c
index 4094b43..d9090f0 100644
--- a/proton-c/src/proactor/epoll.c
+++ b/proton-c/src/proactor/epoll.c
@@ -27,7 +27,6 @@
 #undef _GNU_SOURCE
 
 #include "../core/log_private.h"
-#include "../core/connection_driver-internal.h"
 #include "./proactor-internal.h"
 
 #include <proton/condition.h>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[3/3] qpid-proton git commit: PROTON-1766: [c] Remove use of pn_record_t in libuv proactor.

Posted by ac...@apache.org.
PROTON-1766: [c] Remove use of pn_record_t in libuv proactor.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/391397f5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/391397f5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/391397f5

Branch: refs/heads/master
Commit: 391397f59d53e4f6ed72e0bf97b114bc96e2f695
Parents: 103cdd5
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Feb 21 16:49:28 2018 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Feb 21 17:02:00 2018 -0500

----------------------------------------------------------------------
 proton-c/src/proactor/libuv.c | 52 +++++++++++++++++++++++++-------------
 1 file changed, 34 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/391397f5/proton-c/src/proactor/libuv.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/libuv.c b/proton-c/src/proactor/libuv.c
index edbe214..3d6c9a4 100644
--- a/proton-c/src/proactor/libuv.c
+++ b/proton-c/src/proactor/libuv.c
@@ -32,7 +32,6 @@
 #include <proton/engine.h>
 #include <proton/listener.h>
 #include <proton/message.h>
-#include <proton/object.h>
 #include <proton/proactor.h>
 #include <proton/transport.h>
 
@@ -73,9 +72,6 @@
 const char *AMQP_PORT = "5672";
 const char *AMQP_PORT_NAME = "amqp";
 
-/* Record id for proactor attachments to pn_connection_t */
-PN_HANDLE(PN_PROACTOR)
-
 /* pn_proactor_t and pn_listener_t are plain C structs with normal memory management.
    CLASSDEF is for identification when used as a pn_event_t context.
 */
@@ -298,6 +294,36 @@ static void parse_addr(addr_t *addr, const char *str) {
   pni_parse_addr(str, addr->addr_buf, sizeof(addr->addr_buf), &addr->host, &addr->port);
 }
 
+/* Protect read/update of pn_connnection_t pointer to it's pconnection_t
+ *
+ * Global because pn_connection_wake()/pn_connection_proactor() navigate from
+ * the pn_connection_t before we know the proactor or driver. Critical sections
+ * are small: only get/set of the pn_connection_t driver pointer.
+ *
+ * TODO: replace mutex with atomic load/store
+ */
+static pthread_mutex_t driver_ptr_mutex;
+
+static uv_once_t global_init_once = UV_ONCE_INIT;
+static void global_init_fn() {  /* Call via uv_once(&global_init_once, global_init_fn) */
+  uv_mutex_init(&driver_ptr_mutex);
+}
+
+static pconnection_t *get_pconnection(pn_connection_t* c) {
+  if (!c) return NULL;
+  uv_mutex_lock(&driver_ptr_mutex);
+  pn_connection_driver_t *d = *pn_connection_driver_ptr(c);
+  uv_mutex_unlock(&driver_ptr_mutex);
+  if (!d) return NULL;
+  return (pconnection_t*)((char*)d-offsetof(pconnection_t, driver));
+}
+
+static void set_pconnection(pn_connection_t* c, pconnection_t *pc) {
+  uv_mutex_lock(&driver_ptr_mutex);
+  *pn_connection_driver_ptr(c) = pc ? &pc->driver : NULL;
+  uv_mutex_unlock(&driver_ptr_mutex);
+}
+
 static pconnection_t *pconnection(pn_proactor_t *p, pn_connection_t *c, pn_transport_t *t, bool server) {
   pconnection_t *pc = (pconnection_t*)calloc(1, sizeof(*pc));
   if (!pc || pn_connection_driver_init(&pc->driver, c, t) != 0) {
@@ -310,15 +336,13 @@ static pconnection_t *pconnection(pn_proactor_t *p, pn_connection_t *c, pn_trans
   if (server) {
     pn_transport_set_server(pc->driver.transport);
   }
-  pn_record_t *r = pn_connection_attachments(pc->driver.connection);
-  pn_record_def(r, PN_PROACTOR, PN_VOID);
-  pn_record_set(r, PN_PROACTOR, pc);
+  set_pconnection(pc->driver.connection, pc);
   return pc;
 }
 
 static void pconnection_free(pconnection_t *pc) {
   pn_connection_t *c = pc->driver.connection;
-  if (c) pn_record_set(pn_connection_attachments(c), PN_PROACTOR, NULL);
+  if (c) set_pconnection(c, NULL);
   pn_connection_driver_destroy(&pc->driver);
   if (pc->addr.getaddrinfo.addrinfo) {
     uv_freeaddrinfo(pc->addr.getaddrinfo.addrinfo); /* Interrupted after resolve */
@@ -420,14 +444,6 @@ static void on_close_lsocket(uv_handle_t *h) {
   free(ls);
 }
 
-static pconnection_t *get_pconnection(pn_connection_t* c) {
-  if (!c) {
-    return NULL;
-  }
-  pn_record_t *r = pn_connection_attachments(c);
-  return (pconnection_t*) pn_record_get(r, PN_PROACTOR);
-}
-
 /* Remember the first error code from a bad connect attempt.
  * This is not yet a full-blown error as we might succeed connecting
  * to a different address if there are several.
@@ -1175,6 +1191,7 @@ static void work_free(work_t *w) {
 }
 
 pn_proactor_t *pn_proactor() {
+  uv_once(&global_init_once, global_init_fn);
   pn_proactor_t *p = (pn_proactor_t*)calloc(1, sizeof(pn_proactor_t));
   p->collector = pn_collector();
   if (!p->collector) {
@@ -1240,8 +1257,7 @@ void pn_connection_wake(pn_connection_t* c) {
 void pn_proactor_release_connection(pn_connection_t *c) {
   pconnection_t *pc = get_pconnection(c);
   if (pc) {
-    pn_record_t *r = pn_connection_attachments(c);
-    pn_record_set(r, PN_PROACTOR, NULL); /* Clear the reference from the connection */
+    set_pconnection(c, NULL);
     pn_connection_driver_release_connection(&pc->driver);
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[2/3] qpid-proton git commit: PROTON-1766: [c] Fix missing NULL check in epoll proactor

Posted by ac...@apache.org.
PROTON-1766: [c] Fix missing NULL check in epoll proactor


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/103cdd5b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/103cdd5b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/103cdd5b

Branch: refs/heads/master
Commit: 103cdd5b1824c9f1e4a577256965af179b8a8030
Parents: 0666719
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Feb 21 15:05:40 2018 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Feb 21 17:01:58 2018 -0500

----------------------------------------------------------------------
 proton-c/src/proactor/epoll.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/103cdd5b/proton-c/src/proactor/epoll.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c
index d9090f0..5f8c495 100644
--- a/proton-c/src/proactor/epoll.c
+++ b/proton-c/src/proactor/epoll.c
@@ -545,13 +545,13 @@ static pconnection_t *get_pconnection(pn_connection_t* c) {
   lock(&driver_ptr_mutex);
   pn_connection_driver_t *d = *pn_connection_driver_ptr(c);
   unlock(&driver_ptr_mutex);
-  pconnection_t *pc = (pconnection_t*)((char*)d-offsetof(pconnection_t, driver));
-  return pc;
+  if (!d) return NULL;
+  return (pconnection_t*)((char*)d-offsetof(pconnection_t, driver));
 }
 
 static void set_pconnection(pn_connection_t* c, pconnection_t *pc) {
   lock(&driver_ptr_mutex);
-  *pn_connection_driver_ptr(c) = &pc->driver;
+  *pn_connection_driver_ptr(c) = pc ? &pc->driver : NULL;
   unlock(&driver_ptr_mutex);
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org