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
16bb62e6
Commit
16bb62e6
authored
May 28, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: ctx_t::_slots is a plain array
Solution: use a std::vector instead
parent
a0a60e80
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
23 deletions
+16
-23
ctx.cpp
src/ctx.cpp
+15
-21
ctx.hpp
src/ctx.hpp
+1
-2
No files found.
src/ctx.cpp
View file @
16bb62e6
...
...
@@ -70,8 +70,6 @@ zmq::ctx_t::ctx_t () :
_starting
(
true
),
_terminating
(
false
),
_reaper
(
NULL
),
_slot_count
(
0
),
_slots
(
NULL
),
_max_sockets
(
clipped_maxsocket
(
ZMQ_MAX_SOCKETS_DFLT
)),
_max_msgsz
(
INT_MAX
),
_io_thread_count
(
ZMQ_IO_THREADS_DFLT
),
...
...
@@ -115,10 +113,8 @@ zmq::ctx_t::~ctx_t ()
// Deallocate the reaper thread object.
LIBZMQ_DELETE
(
_reaper
);
// Deallocate the array of mailboxes. No special work is
// needed as mailboxes themselves were deallocated with their
// The mailboxes in _slots themselves were deallocated with their
// corresponding io_thread/socket objects.
free
(
_slots
);
// De-initialise crypto library, if needed.
zmq
::
random_close
();
...
...
@@ -290,13 +286,16 @@ bool zmq::ctx_t::start ()
const
int
mazmq
=
_max_sockets
;
const
int
ios
=
_io_thread_count
;
_opt_sync
.
unlock
();
_slot_count
=
mazmq
+
ios
+
term_and_reaper_threads_count
;
_slots
=
static_cast
<
i_mailbox
**>
(
malloc
(
sizeof
(
i_mailbox
*
)
*
_slot_count
));
if
(
!
_slots
)
{
int
slot_count
=
mazmq
+
ios
+
term_and_reaper_threads_count
;
try
{
_slots
.
reserve
(
slot_count
);
_empty_slots
.
reserve
(
slot_count
-
term_and_reaper_threads_count
);
}
catch
(
const
std
::
bad_alloc
&
)
{
errno
=
ENOMEM
;
goto
fail
;
return
false
;
}
_slots
.
resize
(
term_and_reaper_threads_count
);
// Initialise the infrastructure for zmq_ctx_term thread.
_slots
[
term_tid
]
=
&
_term_mailbox
;
...
...
@@ -313,12 +312,10 @@ bool zmq::ctx_t::start ()
_reaper
->
start
();
// Create I/O thread objects and launch them.
for
(
int32_t
i
=
static_cast
<
int32_t
>
(
_slot_count
)
-
1
;
i
>=
static_cast
<
int32_t
>
(
term_and_reaper_threads_count
);
i
--
)
{
_slots
[
i
]
=
NULL
;
}
_slots
.
resize
(
slot_count
,
NULL
);
for
(
int
i
=
2
;
i
!=
ios
+
2
;
i
++
)
{
for
(
int
i
=
term_and_reaper_threads_count
;
i
!=
ios
+
term_and_reaper_threads_count
;
i
++
)
{
io_thread_t
*
io_thread
=
new
(
std
::
nothrow
)
io_thread_t
(
this
,
i
);
if
(
!
io_thread
)
{
errno
=
ENOMEM
;
...
...
@@ -334,8 +331,8 @@ bool zmq::ctx_t::start ()
}
// In the unused part of the slot array, create a list of empty slots.
for
(
int32_t
i
=
static_cast
<
int32_t
>
(
_slot
_count
)
-
1
;
i
>=
static_cast
<
int32_t
>
(
ios
)
+
2
;
i
--
)
{
for
(
int32_t
i
=
static_cast
<
int32_t
>
(
_slot
s
.
size
()
)
-
1
;
i
>=
static_cast
<
int32_t
>
(
ios
)
+
term_and_reaper_threads_count
;
i
--
)
{
_empty_slots
.
push_back
(
i
);
}
...
...
@@ -348,10 +345,7 @@ fail_cleanup_reaper:
_reaper
=
NULL
;
fail_cleanup_slots
:
free
(
_slots
);
_slots
=
NULL
;
fail
:
_slots
.
clear
();
return
false
;
}
...
...
src/ctx.hpp
View file @
16bb62e6
...
...
@@ -198,8 +198,7 @@ class ctx_t : public thread_ctx_t
io_threads_t
_io_threads
;
// Array of pointers to mailboxes for both application and I/O threads.
uint32_t
_slot_count
;
i_mailbox
**
_slots
;
std
::
vector
<
i_mailbox
*>
_slots
;
// Mailbox for zmq_ctx_term thread.
mailbox_t
_term_mailbox
;
...
...
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