You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2017/06/02 22:51:18 UTC

[04/20] qpid-proton git commit: PROTON-1288: allocate extra storage with pn_message for internal use

PROTON-1288: allocate extra storage with pn_message for internal use

Allow extra space to be allocated in the same block used by pn_message_t


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

Branch: refs/heads/PROTON-1488
Commit: 860b32291fa31c343cc3dad63524a36ce9082a9c
Parents: d588798
Author: Alan Conway <ac...@redhat.com>
Authored: Wed May 17 13:43:33 2017 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed May 24 14:38:25 2017 -0400

----------------------------------------------------------------------
 proton-c/include/proton/message.h | 11 ++++++++
 proton-c/src/core/max_align.h     | 47 ++++++++++++++++++++++++++++++++++
 proton-c/src/core/message.c       | 24 +++++++++++++++--
 3 files changed, 80 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/860b3229/proton-c/include/proton/message.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/message.h b/proton-c/include/proton/message.h
index 5c310b0..4f71db2 100644
--- a/proton-c/include/proton/message.h
+++ b/proton-c/include/proton/message.h
@@ -744,6 +744,17 @@ PN_EXTERN int pn_message_encode(pn_message_t *msg, char *bytes, size_t *size);
  */
 PN_EXTERN int pn_message_data(pn_message_t *msg, pn_data_t *data);
 
+/** @cond INTERNAL @{ */
+
+/** Construct a message with extra storage */
+PN_EXTERN pn_message_t * pn_message_with_extra(size_t extra);
+
+/** Pointer to extra space allocated by pn_message_with_extra(). */
+PN_EXTERN void* pn_message_get_extra(pn_message_t *msg);
+
+/** @} */
+
+
 /** @}
  */
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/860b3229/proton-c/src/core/max_align.h
----------------------------------------------------------------------
diff --git a/proton-c/src/core/max_align.h b/proton-c/src/core/max_align.h
new file mode 100644
index 0000000..ff9a6e5
--- /dev/null
+++ b/proton-c/src/core/max_align.h
@@ -0,0 +1,47 @@
+#ifndef MAX_ALIGN_H
+#define MAX_ALIGN_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/type_compat.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if __STDC_VERSION__ >= 201112
+/* Use standard max_align_t for alignment on c11 */
+typedef max_align_t pn_max_align_t;
+#else
+/* Align on a union of likely largest types for older compilers */
+typedef union pn_max_align_t {
+  uint64_t i;
+  long double d;
+  void *v;
+  void (*fp)(void);
+} pn_max_align_t;
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // MAX_ALIGN_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/860b3229/proton-c/src/core/message.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/message.c b/proton-c/src/core/message.c
index f2fb20e..ecf8f43 100644
--- a/proton-c/src/core/message.c
+++ b/proton-c/src/core/message.c
@@ -20,6 +20,8 @@
  */
 
 #include "platform/platform_fmt.h"
+
+#include "max_align.h"
 #include "protocol.h"
 #include "util.h"
 
@@ -303,10 +305,10 @@ int pn_message_inspect(void *obj, pn_string_t *dst)
 #define pn_message_hashcode NULL
 #define pn_message_compare NULL
 
-pn_message_t *pn_message()
+static pn_message_t *pni_message_new(size_t size)
 {
   static const pn_class_t clazz = PN_CLASS(pn_message);
-  pn_message_t *msg = (pn_message_t *) pn_class_new(&clazz, sizeof(pn_message_t));
+  pn_message_t *msg = (pn_message_t *) pn_class_new(&clazz, size);
   msg->durable = false;
   msg->priority = PN_DEFAULT_PRIORITY;
   msg->ttl = 0;
@@ -337,6 +339,24 @@ pn_message_t *pn_message()
   return msg;
 }
 
+pn_message_t *pn_message() {
+  return pni_message_new(sizeof(pn_message_t));
+}
+
+/* Maximally aligned message to make extra storage safe for any type */
+typedef union {
+  pn_message_t m;
+  pn_max_align_t a;
+}  pni_aligned_message_t;
+
+pn_message_t *pn_message_with_extra(size_t extra) {
+  return pni_message_new(sizeof(pni_aligned_message_t) + extra);
+}
+
+void *pn_message_get_extra(pn_message_t *m) {
+  return ((char*)m) + sizeof(pni_aligned_message_t);
+}
+
 void pn_message_free(pn_message_t *msg)
 {
   pn_free(msg);


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