Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
b2718149
Commit
b2718149
authored
Jan 29, 2016
by
somdoron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msg external storage is using content_t
parent
15ad6f80
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
68 deletions
+60
-68
decoder_allocators.cpp
src/decoder_allocators.cpp
+5
-5
decoder_allocators.hpp
src/decoder_allocators.hpp
+6
-5
msg.cpp
src/msg.cpp
+23
-24
msg.hpp
src/msg.hpp
+20
-28
raw_decoder.cpp
src/raw_decoder.cpp
+4
-4
v2_decoder.cpp
src/v2_decoder.cpp
+2
-2
No files found.
src/decoder_allocators.cpp
View file @
b2718149
...
@@ -37,7 +37,7 @@ zmq::shared_message_memory_allocator::shared_message_memory_allocator (std::size
...
@@ -37,7 +37,7 @@ zmq::shared_message_memory_allocator::shared_message_memory_allocator (std::size
buf
(
NULL
),
buf
(
NULL
),
bufsize
(
0
),
bufsize
(
0
),
max_size
(
bufsize_
),
max_size
(
bufsize_
),
msg_
refc
nt
(
NULL
),
msg_
conte
nt
(
NULL
),
maxCounters
(
static_cast
<
size_t
>
(
std
::
ceil
(
static_cast
<
double
>
(
max_size
)
/
static_cast
<
double
>
(
msg_t
::
max_vsm_size
))))
maxCounters
(
static_cast
<
size_t
>
(
std
::
ceil
(
static_cast
<
double
>
(
max_size
)
/
static_cast
<
double
>
(
msg_t
::
max_vsm_size
))))
{
{
}
}
...
@@ -46,7 +46,7 @@ zmq::shared_message_memory_allocator::shared_message_memory_allocator (std::size
...
@@ -46,7 +46,7 @@ zmq::shared_message_memory_allocator::shared_message_memory_allocator (std::size
buf
(
NULL
),
buf
(
NULL
),
bufsize
(
0
),
bufsize
(
0
),
max_size
(
bufsize_
),
max_size
(
bufsize_
),
msg_
refc
nt
(
NULL
),
msg_
conte
nt
(
NULL
),
maxCounters
(
maxMessages
)
maxCounters
(
maxMessages
)
{
{
}
}
...
@@ -77,7 +77,7 @@ unsigned char* zmq::shared_message_memory_allocator::allocate ()
...
@@ -77,7 +77,7 @@ unsigned char* zmq::shared_message_memory_allocator::allocate ()
// allocate memory for reference counters together with reception buffer
// allocate memory for reference counters together with reception buffer
std
::
size_t
const
allocationsize
=
std
::
size_t
const
allocationsize
=
max_size
+
sizeof
(
zmq
::
atomic_counter_t
)
+
max_size
+
sizeof
(
zmq
::
atomic_counter_t
)
+
maxCounters
*
sizeof
(
zmq
::
atomic_counter
_t
);
maxCounters
*
sizeof
(
zmq
::
msg_t
::
content
_t
);
buf
=
static_cast
<
unsigned
char
*>
(
std
::
malloc
(
allocationsize
));
buf
=
static_cast
<
unsigned
char
*>
(
std
::
malloc
(
allocationsize
));
alloc_assert
(
buf
);
alloc_assert
(
buf
);
...
@@ -90,7 +90,7 @@ unsigned char* zmq::shared_message_memory_allocator::allocate ()
...
@@ -90,7 +90,7 @@ unsigned char* zmq::shared_message_memory_allocator::allocate ()
}
}
bufsize
=
max_size
;
bufsize
=
max_size
;
msg_
refcnt
=
reinterpret_cast
<
zmq
::
atomic_counter
_t
*>
(
buf
+
sizeof
(
atomic_counter_t
)
+
max_size
);
msg_
content
=
reinterpret_cast
<
zmq
::
msg_t
::
content
_t
*>
(
buf
+
sizeof
(
atomic_counter_t
)
+
max_size
);
return
buf
+
sizeof
(
zmq
::
atomic_counter_t
);
return
buf
+
sizeof
(
zmq
::
atomic_counter_t
);
}
}
...
@@ -108,7 +108,7 @@ unsigned char* zmq::shared_message_memory_allocator::release ()
...
@@ -108,7 +108,7 @@ unsigned char* zmq::shared_message_memory_allocator::release ()
unsigned
char
*
b
=
buf
;
unsigned
char
*
b
=
buf
;
buf
=
NULL
;
buf
=
NULL
;
bufsize
=
0
;
bufsize
=
0
;
msg_
refc
nt
=
NULL
;
msg_
conte
nt
=
NULL
;
return
b
;
return
b
;
}
}
...
...
src/decoder_allocators.hpp
View file @
b2718149
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include <cstdlib>
#include <cstdlib>
#include "atomic_counter.hpp"
#include "atomic_counter.hpp"
#include "msg.hpp"
#include "err.hpp"
#include "err.hpp"
namespace
zmq
namespace
zmq
...
@@ -132,21 +133,21 @@ namespace zmq
...
@@ -132,21 +133,21 @@ namespace zmq
bufsize
=
new_size
;
bufsize
=
new_size
;
}
}
zmq
::
atomic_counter_t
*
provide_refc
nt
()
zmq
::
msg_t
::
content_t
*
provide_conte
nt
()
{
{
return
msg_
refc
nt
;
return
msg_
conte
nt
;
}
}
void
advance_
refc
nt
()
void
advance_
conte
nt
()
{
{
msg_
refc
nt
++
;
msg_
conte
nt
++
;
}
}
private
:
private
:
unsigned
char
*
buf
;
unsigned
char
*
buf
;
std
::
size_t
bufsize
;
std
::
size_t
bufsize
;
std
::
size_t
max_size
;
std
::
size_t
max_size
;
zmq
::
atomic_counter_t
*
msg_refc
nt
;
zmq
::
msg_t
::
content_t
*
msg_conte
nt
;
std
::
size_t
maxCounters
;
std
::
size_t
maxCounters
;
};
};
}
}
...
...
src/msg.cpp
View file @
b2718149
...
@@ -53,7 +53,7 @@ bool zmq::msg_t::check ()
...
@@ -53,7 +53,7 @@ bool zmq::msg_t::check ()
int
zmq
::
msg_t
::
init
(
void
*
data_
,
size_t
size_
,
int
zmq
::
msg_t
::
init
(
void
*
data_
,
size_t
size_
,
msg_free_fn
*
ffn_
,
void
*
hint
,
msg_free_fn
*
ffn_
,
void
*
hint
,
zmq
::
atomic_counter_t
*
refc
nt_
)
content_t
*
conte
nt_
)
{
{
if
(
size_
<
max_vsm_size
)
{
if
(
size_
<
max_vsm_size
)
{
int
const
rc
=
init_size
(
size_
);
int
const
rc
=
init_size
(
size_
);
...
@@ -68,9 +68,9 @@ int zmq::msg_t::init (void* data_, size_t size_,
...
@@ -68,9 +68,9 @@ int zmq::msg_t::init (void* data_, size_t size_,
return
-
1
;
return
-
1
;
}
}
}
}
else
if
(
refc
nt_
)
else
if
(
conte
nt_
)
{
{
return
init_external_storage
(
data_
,
size_
,
refcnt
_
,
ffn_
,
hint
);
return
init_external_storage
(
content_
,
data_
,
size
_
,
ffn_
,
hint
);
}
}
else
else
{
{
...
@@ -122,12 +122,11 @@ int zmq::msg_t::init_size (size_t size_)
...
@@ -122,12 +122,11 @@ int zmq::msg_t::init_size (size_t size_)
return
0
;
return
0
;
}
}
int
zmq
::
msg_t
::
init_external_storage
(
void
*
data_
,
size_t
size_
,
zmq
::
atomic_counter_t
*
ctr
,
int
zmq
::
msg_t
::
init_external_storage
(
content_t
*
content_
,
void
*
data_
,
size_t
size_
,
msg_free_fn
*
ffn_
,
void
*
hint_
)
msg_free_fn
*
ffn_
,
void
*
hint_
)
{
{
zmq_assert
(
NULL
!=
data_
);
zmq_assert
(
NULL
!=
data_
);
zmq_assert
(
NULL
!=
ctr
);
zmq_assert
(
NULL
!=
content_
);
u
.
zclmsg
.
metadata
=
NULL
;
u
.
zclmsg
.
metadata
=
NULL
;
u
.
zclmsg
.
type
=
type_zclmsg
;
u
.
zclmsg
.
type
=
type_zclmsg
;
...
@@ -135,12 +134,12 @@ int zmq::msg_t::init_external_storage(void *data_, size_t size_, zmq::atomic_cou
...
@@ -135,12 +134,12 @@ int zmq::msg_t::init_external_storage(void *data_, size_t size_, zmq::atomic_cou
u
.
zclmsg
.
routing_id
=
0
;
u
.
zclmsg
.
routing_id
=
0
;
u
.
zclmsg
.
fd
=
retired_fd
;
u
.
zclmsg
.
fd
=
retired_fd
;
u
.
zclmsg
.
data
=
data
_
;
u
.
zclmsg
.
content
=
content
_
;
u
.
zclmsg
.
size
=
size
_
;
u
.
zclmsg
.
content
->
data
=
data
_
;
u
.
zclmsg
.
ffn
=
ffn
_
;
u
.
zclmsg
.
content
->
size
=
size
_
;
u
.
zclmsg
.
hint
=
hint
_
;
u
.
zclmsg
.
content
->
ffn
=
ffn
_
;
u
.
zclmsg
.
refcnt
=
ctr
;
u
.
zclmsg
.
content
->
hint
=
hint_
;
new
(
u
.
zclmsg
.
refcnt
)
zmq
::
atomic_counter_t
();
new
(
&
u
.
zclmsg
.
content
->
refcnt
)
zmq
::
atomic_counter_t
();
return
0
;
return
0
;
}
}
...
@@ -222,19 +221,19 @@ int zmq::msg_t::close ()
...
@@ -222,19 +221,19 @@ int zmq::msg_t::close ()
if
(
is_zcmsg
())
if
(
is_zcmsg
())
{
{
zmq_assert
(
u
.
zclmsg
.
ffn
);
zmq_assert
(
u
.
zclmsg
.
content
->
ffn
);
// If the content is not shared, or if it is shared and the reference
// If the content is not shared, or if it is shared and the reference
// count has dropped to zero, deallocate it.
// count has dropped to zero, deallocate it.
if
(
!
(
u
.
zclmsg
.
flags
&
msg_t
::
shared
)
||
if
(
!
(
u
.
zclmsg
.
flags
&
msg_t
::
shared
)
||
!
u
.
zclmsg
.
refcnt
->
sub
(
1
))
{
!
u
.
zclmsg
.
content
->
refcnt
.
sub
(
1
))
{
// We used "placement new" operator to initialize the reference
// We used "placement new" operator to initialize the reference
// counter so we call the destructor explicitly now.
// counter so we call the destructor explicitly now.
u
.
zclmsg
.
refcnt
->
~
atomic_counter_t
();
u
.
zclmsg
.
content
->
refcnt
.
~
atomic_counter_t
();
u
.
zclmsg
.
ffn
(
u
.
zclmsg
.
data
,
u
.
zclmsg
.
content
->
ffn
(
u
.
zclmsg
.
content
->
data
,
u
.
zclmsg
.
hint
);
u
.
zclmsg
.
content
->
hint
);
}
}
}
}
...
@@ -329,7 +328,7 @@ void *zmq::msg_t::data ()
...
@@ -329,7 +328,7 @@ void *zmq::msg_t::data ()
case
type_cmsg
:
case
type_cmsg
:
return
u
.
cmsg
.
data
;
return
u
.
cmsg
.
data
;
case
type_zclmsg
:
case
type_zclmsg
:
return
u
.
zclmsg
.
data
;
return
u
.
zclmsg
.
content
->
data
;
default
:
default
:
zmq_assert
(
false
);
zmq_assert
(
false
);
return
NULL
;
return
NULL
;
...
@@ -347,7 +346,7 @@ size_t zmq::msg_t::size ()
...
@@ -347,7 +346,7 @@ size_t zmq::msg_t::size ()
case
type_lmsg
:
case
type_lmsg
:
return
u
.
lmsg
.
content
->
size
;
return
u
.
lmsg
.
content
->
size
;
case
type_zclmsg
:
case
type_zclmsg
:
return
u
.
zclmsg
.
size
;
return
u
.
zclmsg
.
content
->
size
;
case
type_cmsg
:
case
type_cmsg
:
return
u
.
cmsg
.
size
;
return
u
.
cmsg
.
size
;
default
:
default
:
...
@@ -487,10 +486,10 @@ bool zmq::msg_t::rm_refs (int refs_)
...
@@ -487,10 +486,10 @@ bool zmq::msg_t::rm_refs (int refs_)
return
false
;
return
false
;
}
}
if
(
is_zcmsg
()
&&
!
u
.
zclmsg
.
refcnt
->
sub
(
refs_
))
{
if
(
is_zcmsg
()
&&
!
u
.
zclmsg
.
content
->
refcnt
.
sub
(
refs_
))
{
// storage for rfcnt is provided externally
// storage for rfcnt is provided externally
if
(
u
.
zclmsg
.
ffn
)
{
if
(
u
.
zclmsg
.
content
->
ffn
)
{
u
.
zclmsg
.
ffn
(
u
.
zclmsg
.
data
,
u
.
zclmsg
.
hint
);
u
.
zclmsg
.
content
->
ffn
(
u
.
zclmsg
.
content
->
data
,
u
.
zclmsg
.
content
->
hint
);
}
}
return
false
;
return
false
;
...
@@ -527,7 +526,7 @@ zmq::atomic_counter_t *zmq::msg_t::refcnt()
...
@@ -527,7 +526,7 @@ zmq::atomic_counter_t *zmq::msg_t::refcnt()
case
type_lmsg
:
case
type_lmsg
:
return
&
u
.
lmsg
.
content
->
refcnt
;
return
&
u
.
lmsg
.
content
->
refcnt
;
case
type_zclmsg
:
case
type_zclmsg
:
return
u
.
zclmsg
.
refcnt
;
return
&
u
.
zclmsg
.
content
->
refcnt
;
default
:
default
:
zmq_assert
(
false
);
zmq_assert
(
false
);
return
NULL
;
return
NULL
;
...
...
src/msg.hpp
View file @
b2718149
...
@@ -56,6 +56,22 @@ namespace zmq
...
@@ -56,6 +56,22 @@ namespace zmq
{
{
public
:
public
:
// Shared message buffer. Message data are either allocated in one
// continuous block along with this structure - thus avoiding one
// malloc/free pair or they are stored in used-supplied memory.
// In the latter case, ffn member stores pointer to the function to be
// used to deallocate the data. If the buffer is actually shared (there
// are at least 2 references to it) refcount member contains number of
// references.
struct
content_t
{
void
*
data
;
size_t
size
;
msg_free_fn
*
ffn
;
void
*
hint
;
zmq
::
atomic_counter_t
refcnt
;
};
// Message flags.
// Message flags.
enum
enum
{
{
...
@@ -71,12 +87,12 @@ namespace zmq
...
@@ -71,12 +87,12 @@ namespace zmq
int
init
(
void
*
data
,
size_t
size_
,
int
init
(
void
*
data
,
size_t
size_
,
msg_free_fn
*
ffn_
,
void
*
hint
,
msg_free_fn
*
ffn_
,
void
*
hint
,
zmq
::
atomic_counter_t
*
refc
nt_
=
NULL
);
content_t
*
conte
nt_
=
NULL
);
int
init_size
(
size_t
size_
);
int
init_size
(
size_t
size_
);
int
init_data
(
void
*
data_
,
size_t
size_
,
msg_free_fn
*
ffn_
,
int
init_data
(
void
*
data_
,
size_t
size_
,
msg_free_fn
*
ffn_
,
void
*
hint_
);
void
*
hint_
);
int
init_external_storage
(
void
*
data_
,
size_t
size_
,
zmq
::
atomic_counter_t
*
ctr
,
int
init_external_storage
(
content_t
*
content_
,
void
*
data_
,
size_t
size_
,
msg_free_fn
*
ffn_
,
void
*
hint_
);
msg_free_fn
*
ffn_
,
void
*
hint_
);
int
init_delimiter
();
int
init_delimiter
();
int
close
();
int
close
();
...
@@ -121,22 +137,6 @@ namespace zmq
...
@@ -121,22 +137,6 @@ namespace zmq
private
:
private
:
zmq
::
atomic_counter_t
*
refcnt
();
zmq
::
atomic_counter_t
*
refcnt
();
// Shared message buffer. Message data are either allocated in one
// continuous block along with this structure - thus avoiding one
// malloc/free pair or they are stored in used-supplied memory.
// In the latter case, ffn member stores pointer to the function to be
// used to deallocate the data. If the buffer is actually shared (there
// are at least 2 references to it) refcount member contains number of
// references.
struct
content_t
{
void
*
data
;
size_t
size
;
msg_free_fn
*
ffn
;
void
*
hint
;
zmq
::
atomic_counter_t
refcnt
;
};
// Different message types.
// Different message types.
enum
type_t
enum
type_t
{
{
...
@@ -196,17 +196,9 @@ namespace zmq
...
@@ -196,17 +196,9 @@ namespace zmq
}
lmsg
;
}
lmsg
;
struct
{
struct
{
metadata_t
*
metadata
;
metadata_t
*
metadata
;
void
*
data
;
content_t
*
content
;
size_t
size
;
msg_free_fn
*
ffn
;
void
*
hint
;
zmq
::
atomic_counter_t
*
refcnt
;
unsigned
char
unused
[
msg_t_size
-
(
sizeof
(
metadata_t
*
)
+
unsigned
char
unused
[
msg_t_size
-
(
sizeof
(
metadata_t
*
)
+
sizeof
(
void
*
)
+
sizeof
(
content_t
*
)
+
sizeof
(
size_t
)
+
sizeof
(
msg_free_fn
*
)
+
sizeof
(
void
*
)
+
sizeof
(
zmq
::
atomic_counter_t
*
)
+
2
+
2
+
sizeof
(
uint32_t
)
+
sizeof
(
uint32_t
)
+
sizeof
(
fd_t
))];
sizeof
(
fd_t
))];
...
...
src/raw_decoder.cpp
View file @
b2718149
...
@@ -62,13 +62,13 @@ int zmq::raw_decoder_t::decode (const uint8_t *data_, size_t size_,
...
@@ -62,13 +62,13 @@ 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
.
provide_
refcnt
()
);
allocator
.
provide_
content
()
);
// 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_
refc
nt
();
allocator
.
advance_
conte
nt
();
allocator
.
release
();
allocator
.
release
();
}
}
...
...
src/v2_decoder.cpp
View file @
b2718149
...
@@ -127,12 +127,12 @@ int zmq::v2_decoder_t::size_ready(uint64_t msg_size, unsigned char const* read_p
...
@@ -127,12 +127,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
,
static_cast
<
size_t
>
(
msg_size
),
rc
=
in_progress
.
init
((
unsigned
char
*
)
read_pos
,
static_cast
<
size_t
>
(
msg_size
),
shared_message_memory_allocator
::
call_dec_ref
,
buffer
(),
shared_message_memory_allocator
::
call_dec_ref
,
buffer
(),
provide_
refc
nt
());
provide_
conte
nt
());
// 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_
refc
nt
();
advance_
conte
nt
();
inc_ref
();
inc_ref
();
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment