mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-14 23:07:59 +02:00
[decoder*] Style fixes for consistency
This commit is contained in:
@@ -33,79 +33,76 @@
|
||||
|
||||
#include "msg.hpp"
|
||||
|
||||
zmq::shared_message_memory_allocator::shared_message_memory_allocator(size_t bufsize_):
|
||||
buf(NULL),
|
||||
bufsize( 0 ),
|
||||
max_size( bufsize_ ),
|
||||
msg_refcnt( NULL ),
|
||||
maxCounters( std::ceil( static_cast<double>(max_size) / static_cast<double>(msg_t::max_vsm_size)) )
|
||||
zmq::shared_message_memory_allocator::shared_message_memory_allocator (std::size_t bufsize_) :
|
||||
buf(NULL),
|
||||
bufsize(0),
|
||||
max_size(bufsize_),
|
||||
msg_refcnt(NULL),
|
||||
maxCounters (std::ceil (static_cast <double> (max_size) / static_cast <double> (msg_t::max_vsm_size)))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
zmq::shared_message_memory_allocator::shared_message_memory_allocator(size_t bufsize_, size_t maxMessages):
|
||||
buf(NULL),
|
||||
bufsize( 0 ),
|
||||
max_size( bufsize_ ),
|
||||
msg_refcnt( NULL ),
|
||||
maxCounters( maxMessages )
|
||||
zmq::shared_message_memory_allocator::shared_message_memory_allocator (std::size_t bufsize_, std::size_t maxMessages) :
|
||||
buf(NULL),
|
||||
bufsize(0),
|
||||
max_size(bufsize_),
|
||||
msg_refcnt(NULL),
|
||||
maxCounters(maxMessages)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
zmq::shared_message_memory_allocator::~shared_message_memory_allocator()
|
||||
zmq::shared_message_memory_allocator::~shared_message_memory_allocator ()
|
||||
{
|
||||
deallocate();
|
||||
}
|
||||
|
||||
unsigned char* zmq::shared_message_memory_allocator::allocate()
|
||||
unsigned char* zmq::shared_message_memory_allocator::allocate ()
|
||||
{
|
||||
if (buf)
|
||||
{
|
||||
if (buf) {
|
||||
// release reference count to couple lifetime to messages
|
||||
zmq::atomic_counter_t *c = reinterpret_cast<zmq::atomic_counter_t *>(buf);
|
||||
zmq::atomic_counter_t* c = reinterpret_cast<zmq::atomic_counter_t* >(buf);
|
||||
|
||||
// if refcnt drops to 0, there are no message using the buffer
|
||||
// because either all messages have been closed or only vsm-messages
|
||||
// were created
|
||||
if (c->sub(1)) {
|
||||
if (c->sub (1)) {
|
||||
// buffer is still in use as message data. "Release" it and create a new one
|
||||
// release pointer because we are going to create a new buffer
|
||||
release();
|
||||
release ();
|
||||
}
|
||||
}
|
||||
|
||||
// if buf != NULL it is not used by any message so we can re-use it for the next run
|
||||
if (!buf) {
|
||||
// allocate memory for reference counters together with reception buffer
|
||||
size_t const allocationsize = max_size + sizeof(zmq::atomic_counter_t) + maxCounters * sizeof(zmq::atomic_counter_t);
|
||||
std::size_t const allocationsize =
|
||||
max_size + sizeof (zmq::atomic_counter_t) +
|
||||
maxCounters * sizeof (zmq::atomic_counter_t);
|
||||
|
||||
buf = static_cast<unsigned char *>( malloc(allocationsize) );
|
||||
buf = static_cast <unsigned char *> (std::malloc (allocationsize));
|
||||
alloc_assert (buf);
|
||||
|
||||
new(buf) atomic_counter_t(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
new (buf) atomic_counter_t (1);
|
||||
} else {
|
||||
// release reference count to couple lifetime to messages
|
||||
zmq::atomic_counter_t *c = reinterpret_cast<zmq::atomic_counter_t *>(buf);
|
||||
c->set(1);
|
||||
zmq::atomic_counter_t *c = reinterpret_cast <zmq::atomic_counter_t *> (buf);
|
||||
c->set (1);
|
||||
}
|
||||
|
||||
bufsize = max_size;
|
||||
msg_refcnt = reinterpret_cast<zmq::atomic_counter_t*>( buf + sizeof(atomic_counter_t) + max_size );
|
||||
return buf + sizeof( zmq::atomic_counter_t);
|
||||
msg_refcnt = reinterpret_cast <zmq::atomic_counter_t*> (buf + sizeof (atomic_counter_t) + max_size);
|
||||
return buf + sizeof (zmq::atomic_counter_t);
|
||||
}
|
||||
|
||||
void zmq::shared_message_memory_allocator::deallocate()
|
||||
void zmq::shared_message_memory_allocator::deallocate ()
|
||||
{
|
||||
std::free(buf);
|
||||
std::free (buf);
|
||||
buf = NULL;
|
||||
bufsize = 0;
|
||||
msg_refcnt = NULL;
|
||||
}
|
||||
|
||||
unsigned char* zmq::shared_message_memory_allocator::release()
|
||||
unsigned char* zmq::shared_message_memory_allocator::release ()
|
||||
{
|
||||
unsigned char* b = buf;
|
||||
buf = NULL;
|
||||
@@ -115,30 +112,31 @@ unsigned char* zmq::shared_message_memory_allocator::release()
|
||||
return b;
|
||||
}
|
||||
|
||||
void zmq::shared_message_memory_allocator::inc_ref()
|
||||
void zmq::shared_message_memory_allocator::inc_ref ()
|
||||
{
|
||||
(reinterpret_cast<zmq::atomic_counter_t*>(buf))->add(1);
|
||||
(reinterpret_cast <zmq::atomic_counter_t*> (buf))->add (1);
|
||||
}
|
||||
|
||||
void zmq::shared_message_memory_allocator::call_dec_ref(void*, void* hint) {
|
||||
zmq_assert( hint );
|
||||
unsigned char* buf = static_cast<unsigned char*>(hint);
|
||||
zmq::atomic_counter_t *c = reinterpret_cast<zmq::atomic_counter_t *>(buf);
|
||||
void zmq::shared_message_memory_allocator::call_dec_ref(void*, void* hint)
|
||||
{
|
||||
zmq_assert (hint);
|
||||
unsigned char* buf = static_cast <unsigned char*> (hint);
|
||||
zmq::atomic_counter_t* c = reinterpret_cast <zmq::atomic_counter_t*> (buf);
|
||||
|
||||
if (!c->sub(1)) {
|
||||
c->~atomic_counter_t();
|
||||
free(buf);
|
||||
if (!c->sub (1)) {
|
||||
c->~atomic_counter_t ();
|
||||
std::free (buf);
|
||||
buf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t zmq::shared_message_memory_allocator::size() const
|
||||
std::size_t zmq::shared_message_memory_allocator::size () const
|
||||
{
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
unsigned char* zmq::shared_message_memory_allocator::data()
|
||||
unsigned char* zmq::shared_message_memory_allocator::data ()
|
||||
{
|
||||
return buf + sizeof(zmq::atomic_counter_t);
|
||||
}
|
||||
return buf + sizeof (zmq::atomic_counter_t);
|
||||
}
|
||||
|
Reference in New Issue
Block a user