mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-21 15:51:45 +02:00
advance refcnt only if it was used
This commit is contained in:
@@ -132,9 +132,14 @@ namespace zmq
|
|||||||
bufsize = new_size;
|
bufsize = new_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq::atomic_counter_t* create_refcnt ()
|
zmq::atomic_counter_t* provide_refcnt ()
|
||||||
{
|
{
|
||||||
return msg_refcnt++;
|
return msg_refcnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void advance_refcnt ()
|
||||||
|
{
|
||||||
|
msg_refcnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -63,11 +63,12 @@ int zmq::raw_decoder_t::decode (const uint8_t *data_, size_t size_,
|
|||||||
int rc = in_progress.init ((unsigned char*)data_, size_,
|
int rc = in_progress.init ((unsigned char*)data_, size_,
|
||||||
shared_message_memory_allocator::call_dec_ref,
|
shared_message_memory_allocator::call_dec_ref,
|
||||||
allocator.buffer(),
|
allocator.buffer(),
|
||||||
allocator.create_refcnt() );
|
allocator.provide_refcnt() );
|
||||||
|
|
||||||
// if the buffer serves as memory for a zero-copy message, release it
|
// if the buffer serves as memory for a zero-copy message, release it
|
||||||
// and allocate a new buffer in get_buffer for the next decode
|
// and allocate a new buffer in get_buffer for the next decode
|
||||||
if (in_progress.is_zcmsg()) {
|
if (in_progress.is_zcmsg()) {
|
||||||
|
allocator.advance_refcnt();
|
||||||
allocator.release();
|
allocator.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -129,11 +129,12 @@ int zmq::v2_decoder_t::size_ready(uint64_t msg_size, unsigned char const* read_p
|
|||||||
// if the message will be a large message, pass a valid refcnt memory location as well
|
// if the message will be a large message, pass a valid refcnt memory location as well
|
||||||
rc = in_progress.init( (unsigned char*)read_pos, msg_size,
|
rc = in_progress.init( (unsigned char*)read_pos, msg_size,
|
||||||
shared_message_memory_allocator::call_dec_ref, buffer(),
|
shared_message_memory_allocator::call_dec_ref, buffer(),
|
||||||
create_refcnt() );
|
provide_refcnt() );
|
||||||
|
|
||||||
// For small messages, data has been copied and refcount does not have to be increased
|
// For small messages, data has been copied and refcount does not have to be increased
|
||||||
if (in_progress.is_zcmsg())
|
if (in_progress.is_zcmsg())
|
||||||
{
|
{
|
||||||
|
advance_refcnt();
|
||||||
inc_ref();
|
inc_ref();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user