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
0f697fe2
Commit
0f697fe2
authored
Feb 03, 2010
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ZMQII-56: Avoid allocation of chunk in yqueue.hpp by keeping a spare one
parent
72bbc92b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
5 deletions
+27
-5
AUTHORS
AUTHORS
+1
-0
yqueue.hpp
src/yqueue.hpp
+26
-5
No files found.
AUTHORS
View file @
0f697fe2
...
...
@@ -11,6 +11,7 @@ Erich Heine
Erik Rigtorp
Frank Denis
George Neill
Joe Thornber
Jon Dyte
Kamil Shakirov
Martin Hurton
...
...
src/yqueue.hpp
View file @
0f697fe2
...
...
@@ -24,6 +24,7 @@
#include <stddef.h>
#include "err.hpp"
#include "atomic_ptr.hpp"
namespace
zmq
{
...
...
@@ -37,9 +38,9 @@ namespace zmq
// pop on the empty queue and that both threads don't access the same
// element in unsynchronised manner.
//
// T is the type of the object in the queue
// T is the type of the object in the queue
.
// N is granularity of the queue (how many pushes have to be done till
// actual memory allocation is required)
// actual memory allocation is required)
.
template
<
typename
T
,
int
N
>
class
yqueue_t
{
...
...
@@ -69,6 +70,10 @@ namespace zmq
begin_chunk
=
begin_chunk
->
next
;
delete
o
;
}
chunk_t
*
sc
=
spare_chunk
.
xchg
(
NULL
);
if
(
sc
)
delete
sc
;
}
// Returns reference to the front element of the queue.
...
...
@@ -94,8 +99,13 @@ namespace zmq
if
(
++
end_pos
!=
N
)
return
;
end_chunk
->
next
=
new
(
std
::
nothrow
)
chunk_t
;
zmq_assert
(
end_chunk
->
next
);
chunk_t
*
sc
=
spare_chunk
.
xchg
(
NULL
);
if
(
sc
)
{
end_chunk
->
next
=
sc
;
}
else
{
end_chunk
->
next
=
new
(
std
::
nothrow
)
chunk_t
;
zmq_assert
(
end_chunk
->
next
);
}
end_chunk
=
end_chunk
->
next
;
end_pos
=
0
;
}
...
...
@@ -107,7 +117,13 @@ namespace zmq
chunk_t
*
o
=
begin_chunk
;
begin_chunk
=
begin_chunk
->
next
;
begin_pos
=
0
;
delete
o
;
// 'o' has been more recently used than spare_chunk,
// so for cache reasons we'll get rid of the spare and
// use 'o' as the spare.
chunk_t
*
cs
=
spare_chunk
.
xchg
(
o
);
if
(
cs
)
delete
cs
;
}
}
...
...
@@ -131,6 +147,11 @@ namespace zmq
chunk_t
*
end_chunk
;
int
end_pos
;
// People are likely to produce and consume at similar rates. In
// this scenario holding onto the most recently freed chunk saves
// us from having to call new/delete.
atomic_ptr_t
<
chunk_t
>
spare_chunk
;
// Disable copying of yqueue.
yqueue_t
(
const
yqueue_t
&
);
void
operator
=
(
const
yqueue_t
&
);
...
...
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