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
0cf139bf
Commit
0cf139bf
authored
Jan 31, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Universal ref support
parent
a7194295
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
blocking_queue.h
include/c11log/details/blocking_queue.h
+7
-6
No files found.
include/c11log/details/blocking_queue.h
View file @
0cf139bf
...
...
@@ -37,8 +37,8 @@ public:
// Push copy of item into the back of the queue.
// If the queue is full, block the calling thread util there is room or timeout have passed.
// Return: false on timeout, true on successful push.
template
<
class
Duration_Rep
,
class
Duration_Period
>
bool
push
(
const
T
&
item
,
const
std
::
chrono
::
duration
<
Duration_Rep
,
Duration_Period
>&
timeout
)
template
<
typename
Duration_Rep
,
typename
Duration_Period
,
typename
TT
>
bool
push
(
TT
&
&
item
,
const
std
::
chrono
::
duration
<
Duration_Rep
,
Duration_Period
>&
timeout
)
{
std
::
unique_lock
<
std
::
mutex
>
ul
(
mutex_
);
if
(
q_
.
size
()
>=
max_size_
)
...
...
@@ -46,7 +46,7 @@ public:
if
(
!
item_popped_cond_
.
wait_until
(
ul
,
clock
::
now
()
+
timeout
,
[
this
]()
{
return
this
->
q_
.
size
()
<
this
->
max_size_
;
}))
return
false
;
}
q_
.
push
(
item
);
q_
.
push
(
std
::
forward
<
TT
>
(
item
)
);
if
(
q_
.
size
()
<=
1
)
{
ul
.
unlock
();
//So the notified thread will have better chance to accuire the lock immediatly..
...
...
@@ -57,9 +57,10 @@ public:
// Push copy of item into the back of the queue.
// If the queue is full, block the calling thread until there is room.
void
push
(
const
T
&
item
)
template
<
typename
TT
>
void
push
(
TT
&&
item
)
{
while
(
!
push
(
item
,
one_hour
));
while
(
!
push
(
std
::
forward
<
TT
>
(
item
)
,
one_hour
));
}
// Pop a copy of the front item in the queue into the given item ref.
...
...
@@ -104,7 +105,7 @@ private:
std
::
mutex
mutex_
;
std
::
condition_variable
item_pushed_cond_
;
std
::
condition_variable
item_popped_cond_
;
static
constexpr
auto
one_hour
=
std
::
chrono
::
hours
(
1
);
const
std
::
chrono
::
hours
one_hour
{
1
};
};
}
...
...
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