From ab5abf6c7ec7668c4a8373d87c491d22d0db144d Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Wed, 16 Dec 2009 15:08:37 +0100 Subject: hint parameter added to zmq_free function --- bindings/c/zmq.h | 4 ++-- bindings/cpp/zmq.hpp | 10 ++++++---- src/msg_content.hpp | 1 + src/zmq.cpp | 6 ++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bindings/c/zmq.h b/bindings/c/zmq.h index 37bad52..bda6c01 100644 --- a/bindings/c/zmq.h +++ b/bindings/c/zmq.h @@ -106,12 +106,12 @@ typedef struct unsigned char vsm_data [ZMQ_MAX_VSM_SIZE]; } zmq_msg_t; -typedef void (zmq_free_fn) (void *data); +typedef void (zmq_free_fn) (void *data, void *hint); ZMQ_EXPORT int zmq_msg_init (zmq_msg_t *msg); ZMQ_EXPORT int zmq_msg_init_size (zmq_msg_t *msg, size_t size); ZMQ_EXPORT int zmq_msg_init_data (zmq_msg_t *msg, void *data, - size_t size, zmq_free_fn *ffn); + size_t size, zmq_free_fn *ffn, void *hint); ZMQ_EXPORT int zmq_msg_close (zmq_msg_t *msg); ZMQ_EXPORT int zmq_msg_move (zmq_msg_t *dest, zmq_msg_t *src); ZMQ_EXPORT int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src); diff --git a/bindings/cpp/zmq.hpp b/bindings/cpp/zmq.hpp index 1867270..4349f0b 100644 --- a/bindings/cpp/zmq.hpp +++ b/bindings/cpp/zmq.hpp @@ -74,9 +74,10 @@ namespace zmq throw error_t (); } - inline message_t (void *data_, size_t size_, free_fn *ffn_) + inline message_t (void *data_, size_t size_, free_fn *ffn_, + void *hint_ = NULL) { - int rc = zmq_msg_init_data (this, data_, size_, ffn_); + int rc = zmq_msg_init_data (this, data_, size_, ffn_, hint_); if (rc != 0) throw error_t (); } @@ -108,12 +109,13 @@ namespace zmq throw error_t (); } - inline void rebuild (void *data_, size_t size_, free_fn *ffn_) + inline void rebuild (void *data_, size_t size_, free_fn *ffn_, + void *hint_ = NULL) { int rc = zmq_msg_close (this); if (rc != 0) throw error_t (); - rc = zmq_msg_init_data (this, data_, size_, ffn_); + rc = zmq_msg_init_data (this, data_, size_, ffn_, hint_); if (rc != 0) throw error_t (); } diff --git a/src/msg_content.hpp b/src/msg_content.hpp index 22dd915..cb217b7 100644 --- a/src/msg_content.hpp +++ b/src/msg_content.hpp @@ -42,6 +42,7 @@ namespace zmq void *data; size_t size; zmq_free_fn *ffn; + void *hint; zmq::atomic_counter_t refcnt; }; diff --git a/src/zmq.cpp b/src/zmq.cpp index d523036..cce07af 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -103,13 +103,14 @@ int zmq_msg_init_size (zmq_msg_t *msg_, size_t size_) content->data = (void*) (content + 1); content->size = size_; content->ffn = NULL; + content->hint = NULL; new (&content->refcnt) zmq::atomic_counter_t (); } return 0; } int zmq_msg_init_data (zmq_msg_t *msg_, void *data_, size_t size_, - zmq_free_fn *ffn_) + zmq_free_fn *ffn_, void *hint_) { msg_->shared = 0; msg_->content = (zmq::msg_content_t*) malloc (sizeof (zmq::msg_content_t)); @@ -118,6 +119,7 @@ int zmq_msg_init_data (zmq_msg_t *msg_, void *data_, size_t size_, content->data = data_; content->size = size_; content->ffn = ffn_; + content->hint = hint_; new (&content->refcnt) zmq::atomic_counter_t (); return 0; } @@ -139,7 +141,7 @@ int zmq_msg_close (zmq_msg_t *msg_) content->refcnt.~atomic_counter_t (); if (content->ffn) - content->ffn (content->data); + content->ffn (content->data, content->hint); free (content); } -- cgit v1.2.3