qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject qpid-proton git commit: PROTON-1766: [cpp] API cleanup of pn_connection_driver_data
Date Tue, 20 Feb 2018 20:41:39 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 233855fce -> b6b3dd612


PROTON-1766: [cpp] API cleanup of pn_connection_driver_data

Moved pn_connection_driver_data out of the public header files.
Renamed to pn_connection_driver_ptr, changed return from void** to pn_connection_driver_t**

This is more type safe and clarifies that this is not a general-purpose
"context" pointer but a dedicated link from a pn_connection_t to the optional
pn_connection_driver_t that is running its IO.


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

Branch: refs/heads/master
Commit: b6b3dd612472d4d62c7628c924866b97949c48f1
Parents: 233855f
Author: Alan Conway <aconway@redhat.com>
Authored: Tue Feb 20 15:21:34 2018 -0500
Committer: Alan Conway <aconway@redhat.com>
Committed: Tue Feb 20 15:25:51 2018 -0500

----------------------------------------------------------------------
 proton-c/include/proton/connection_driver.h    | 10 ------
 proton-c/src/core/connection_driver-internal.h | 35 +++++++++++++++++++++
 proton-c/src/core/connection_driver.c          |  4 +--
 proton-c/src/core/engine-internal.h            |  2 +-
 proton-c/src/core/engine.c                     |  2 +-
 proton-c/src/proactor/epoll.c                  | 16 +++++-----
 6 files changed, 48 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b6b3dd61/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 c99be1d..8e39551 100644
--- a/proton-c/include/proton/connection_driver.h
+++ b/proton-c/include/proton/connection_driver.h
@@ -267,16 +267,6 @@ 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);
 
 /**
- * @cond INTERNAL
- * @return pointer to location in the pn_connection_t private struct that can hold a `void*`.
- * Only for use by IO integration code (e.g. pn_proactor_t implementations use this pointer)
- */
-PN_EXTERN void **pn_connection_driver_data(pn_connection_t *connection);
-/**
- *  @endcond
- */
-
-/**
  * @}
  */
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b6b3dd61/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
new file mode 100644
index 0000000..519a25b
--- /dev/null
+++ b/proton-c/src/core/connection_driver-internal.h
@@ -0,0 +1,35 @@
+#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/b6b3dd61/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 c253e72..2460a4a 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>
@@ -188,4 +188,4 @@ pn_connection_driver_t* pn_event_batch_connection_driver(pn_event_batch_t
*batch
     NULL;
 }
 
-void** pn_connection_driver_data(pn_connection_t *c) { return &c->driver_data; }
+pn_connection_driver_t** pn_connection_driver_ptr(pn_connection_t *c) { return &c->driver;
}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b6b3dd61/proton-c/src/core/engine-internal.h
----------------------------------------------------------------------
diff --git a/proton-c/src/core/engine-internal.h b/proton-c/src/core/engine-internal.h
index 573ab56..b1c6123 100644
--- a/proton-c/src/core/engine-internal.h
+++ b/proton-c/src/core/engine-internal.h
@@ -248,7 +248,7 @@ struct pn_connection_t {
   pn_collector_t *collector;
   pn_record_t *context;
   pn_list_t *delivery_pool;
-  void *driver_data;            /* See pn_connection_driver_data */
+  struct pn_connection_driver_t *driver;
 };
 
 struct pn_session_t {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b6b3dd61/proton-c/src/core/engine.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/engine.c b/proton-c/src/core/engine.c
index dd90b4d..f49886d 100644
--- a/proton-c/src/core/engine.c
+++ b/proton-c/src/core/engine.c
@@ -536,7 +536,7 @@ pn_connection_t *pn_connection()
   conn->collector = NULL;
   conn->context = pn_record();
   conn->delivery_pool = pn_list(PN_OBJECT, 0);
-  conn->driver_data = NULL;
+  conn->driver = NULL;
 
   return conn;
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b6b3dd61/proton-c/src/proactor/epoll.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c
index 1afb78e..4094b43 100644
--- a/proton-c/src/proactor/epoll.c
+++ b/proton-c/src/proactor/epoll.c
@@ -27,6 +27,7 @@
 #undef _GNU_SOURCE
 
 #include "../core/log_private.h"
+#include "../core/connection_driver-internal.h"
 #include "./proactor-internal.h"
 
 #include <proton/condition.h>
@@ -538,20 +539,21 @@ typedef struct pconnection_t {
  *
  * TODO: replace mutex with atomic load/store
  */
-static pthread_mutex_t driver_data_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t driver_ptr_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static pconnection_t *get_pconnection(pn_connection_t* c) {
   if (!c) return NULL;
-  lock(&driver_data_mutex);
-  pconnection_t *pc = (pconnection_t*)*pn_connection_driver_data(c);
-  unlock(&driver_data_mutex);
+  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;
 }
 
 static void set_pconnection(pn_connection_t* c, pconnection_t *pc) {
-  lock(&driver_data_mutex);
-  *pn_connection_driver_data(c) = pc;
-  unlock(&driver_data_mutex);
+  lock(&driver_ptr_mutex);
+  *pn_connection_driver_ptr(c) = &pc->driver;
+  unlock(&driver_ptr_mutex);
 }
 
 /*


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


Mime
View raw message