Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
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
spdlog
Commits
65e8349c
Commit
65e8349c
authored
Jan 31, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added move support to pop queque
parent
0cf139bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
10 deletions
+55
-10
blocking_queue.h
include/c11log/details/blocking_queue.h
+1
-1
test.cpp
src/test.cpp
+54
-9
No files found.
include/c11log/details/blocking_queue.h
View file @
65e8349c
...
@@ -75,7 +75,7 @@ public:
...
@@ -75,7 +75,7 @@ public:
if
(
!
item_pushed_cond_
.
wait_until
(
ul
,
clock
::
now
()
+
timeout
,
[
this
]()
{
return
!
this
->
q_
.
empty
();
}))
if
(
!
item_pushed_cond_
.
wait_until
(
ul
,
clock
::
now
()
+
timeout
,
[
this
]()
{
return
!
this
->
q_
.
empty
();
}))
return
false
;
return
false
;
}
}
item
=
q_
.
front
();
item
=
std
::
move
(
q_
.
front
());
q_
.
pop
();
q_
.
pop
();
if
(
q_
.
size
()
>=
max_size_
-
1
)
if
(
q_
.
size
()
>=
max_size_
-
1
)
{
{
...
...
src/test.cpp
View file @
65e8349c
...
@@ -15,26 +15,62 @@
...
@@ -15,26 +15,62 @@
std
::
atomic
<
uint64_t
>
push_count
,
pop_count
;
std
::
atomic
<
uint64_t
>
push_count
,
pop_count
;
std
::
atomic
<
bool
>
active
;
std
::
atomic
<
bool
>
active
;
using
Q
=
c11log
::
details
::
blocking_queue
<
std
::
string
>
;
class
A
{
public
:
A
()
{
std
::
cout
<<
"Regular ctor
\n
"
;
}
A
(
const
A
&
)
{
std
::
cout
<<
"Copy ctor
\n
"
;
}
A
&
operator
=
(
const
A
&
)
{
std
::
cout
<<
"operator=
\n
"
;
return
*
this
;
}
A
&
operator
=
(
A
&&
)
{
std
::
cout
<<
"operator=&&
\n
"
;
return
*
this
;
}
A
(
A
&&
a
)
{
std
::
cout
<<
"Move ctor
\n
"
;
}
~
A
()
{
//std::cout << "Dtor\n";
}
};
using
std
::
string
;
using
std
::
chrono
::
seconds
;
using
std
::
chrono
::
seconds
;
using
Q
=
c11log
::
details
::
blocking_queue
<
string
>
;
void
pusher
(
Q
*
q
)
void
pusher
(
Q
*
q
)
{
{
string
a
=
"Hello"
;
while
(
active
)
while
(
active
)
{
{
//if(q->push("Hello", seconds(10)))
q
->
push
(
a
);
q
->
push
(
"hello"
);
++
push_count
;
++
push_count
;
}
}
}
}
void
popper
(
Q
*
q
)
void
popper
(
Q
*
q
)
{
{
st
d
::
st
ring
output
;
string
output
;
while
(
active
)
while
(
active
)
{
{
//if(q->pop(output, seconds(10)))
q
->
pop
(
output
);
q
->
pop
(
output
);
++
pop_count
;
++
pop_count
;
}
}
}
}
...
@@ -44,7 +80,14 @@ void testq(int size, int pushers, int poppers)
...
@@ -44,7 +80,14 @@ void testq(int size, int pushers, int poppers)
active
=
true
;
active
=
true
;
Q
q
{
static_cast
<
Q
::
size_type
>
(
size
)};
Q
q
{
static_cast
<
Q
::
size_type
>
(
size
)};
/*
A a;
q.push(a);
std::cout << "Befor pop..\n";
q.pop(a);
return;
*/
for
(
int
i
=
0
;
i
<
poppers
;
i
++
)
for
(
int
i
=
0
;
i
<
poppers
;
i
++
)
new
std
::
thread
(
std
::
bind
(
popper
,
&
q
));
new
std
::
thread
(
std
::
bind
(
popper
,
&
q
));
...
@@ -69,10 +112,12 @@ void testq(int size, int pushers, int poppers)
...
@@ -69,10 +112,12 @@ void testq(int size, int pushers, int poppers)
cout
<<
"---------------------------------------------------------------------"
<<
endl
;
cout
<<
"---------------------------------------------------------------------"
<<
endl
;
}
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
if
(
argc
!=
4
)
if
(
argc
!=
4
)
{
{
std
::
cerr
<<
"Usage: "
<<
argv
[
0
]
<<
" qsize, pushers, poppers"
<<
std
::
endl
;
std
::
cerr
<<
"Usage: "
<<
argv
[
0
]
<<
" qsize, pushers, poppers"
<<
std
::
endl
;
...
...
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