mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-26 02:18:06 +01:00
Fixed wrong handling of shared messages
The shared reference count was not shared but copied. msg_t cannot store the refcnt itsef but has to store a pointer to an externally allocated (shared) refcnter. The changes to lmsg are reverted to use content_t again. Howver, this introduces an allocation in v2_decoder when creating the message which can be avoided. When allocating the reception buffer, space is allocated for the maximum number of reference counts (8192 / max_vsm_size = 8192/64 = 128 zmq:atomic_counter objects). This increases the buffer by 128*sizeof(atomic_counter) = 128*4 = 512 bytes only. When creating a message, the refcnt member is set to the address of one of the pre-allocated atomic_counter_t objects. To do so, a new msg_t type zcmsg is introduced because msg::copy must discriminate between the message types when releasing memory.
This commit is contained in:
@@ -63,8 +63,6 @@ namespace zmq
|
||||
// the messages constructed on top of it.
|
||||
unsigned char* release();
|
||||
|
||||
void reset(unsigned char* b);
|
||||
|
||||
void inc_ref();
|
||||
|
||||
static void call_dec_ref(void*, void* buffer);
|
||||
@@ -85,6 +83,12 @@ namespace zmq
|
||||
bufsize = new_size;
|
||||
}
|
||||
|
||||
//
|
||||
zmq::atomic_counter_t* create_refcnt()
|
||||
{
|
||||
return msg_refcnt++;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned char* buf;
|
||||
size_t bufsize;
|
||||
|
||||
Reference in New Issue
Block a user