Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
af6b3fe5
Commit
af6b3fe5
authored
Aug 05, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delay the release mutex in the async queue only for mingw
parent
74e8bebb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
13 deletions
+57
-13
include/spdlog/details/mpmc_blocking_q.h
include/spdlog/details/mpmc_blocking_q.h
+57
-13
No files found.
include/spdlog/details/mpmc_blocking_q.h
View file @
af6b3fe5
...
@@ -30,26 +30,32 @@ public:
...
@@ -30,26 +30,32 @@ public:
{
{
}
}
#ifndef __MINGW32__
// try to enqueue and block if no room left
// try to enqueue and block if no room left
void
enqueue
(
T
&&
item
)
void
enqueue
(
T
&&
item
)
{
{
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
queue_mutex_
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
queue_mutex_
);
pop_cv_
.
wait
(
lock
,
[
this
]
{
return
!
this
->
q_
.
full
();
});
pop_cv_
.
wait
(
lock
,
[
this
]
{
return
!
this
->
q_
.
full
();
});
q_
.
push_back
(
std
::
move
(
item
));
q_
.
push_back
(
std
::
move
(
item
));
}
push_cv_
.
notify_one
();
push_cv_
.
notify_one
();
}
}
// enqueue immediately. overrun oldest message in the queue if no room left.
// enqueue immediately. overrun oldest message in the queue if no room left.
void
enqueue_nowait
(
T
&&
item
)
void
enqueue_nowait
(
T
&&
item
)
{
{
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
queue_mutex_
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
queue_mutex_
);
q_
.
push_back
(
std
::
move
(
item
));
q_
.
push_back
(
std
::
move
(
item
));
}
push_cv_
.
notify_one
();
push_cv_
.
notify_one
();
}
}
// try to dequeue item. if no item found. wait upto timeout and try again
// try to dequeue item. if no item found. wait upto timeout and try again
// Return true, if succeeded dequeue item, false otherwise
// Return true, if succeeded dequeue item, false otherwise
bool
dequeue_for
(
T
&
popped_item
,
std
::
chrono
::
milliseconds
wait_duration
)
bool
dequeue_for
(
T
&
popped_item
,
std
::
chrono
::
milliseconds
wait_duration
)
{
{
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
queue_mutex_
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
queue_mutex_
);
if
(
!
push_cv_
.
wait_for
(
lock
,
wait_duration
,
[
this
]
{
return
!
this
->
q_
.
empty
();
}))
if
(
!
push_cv_
.
wait_for
(
lock
,
wait_duration
,
[
this
]
{
return
!
this
->
q_
.
empty
();
}))
...
@@ -57,10 +63,48 @@ public:
...
@@ -57,10 +63,48 @@ public:
return
false
;
return
false
;
}
}
q_
.
pop_front
(
popped_item
);
q_
.
pop_front
(
popped_item
);
}
pop_cv_
.
notify_one
();
pop_cv_
.
notify_one
();
return
true
;
return
true
;
}
}
#else
// apparently mingw deadlocks if the mutex is released before cv.notify_one(),
// so release the mutex at the very end each function.
// try to enqueue and block if no room left
void
enqueue
(
T
&&
item
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
queue_mutex_
);
pop_cv_
.
wait
(
lock
,
[
this
]
{
return
!
this
->
q_
.
full
();
});
q_
.
push_back
(
std
::
move
(
item
));
push_cv_
.
notify_one
();
}
// enqueue immediately. overrun oldest message in the queue if no room left.
void
enqueue_nowait
(
T
&&
item
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
queue_mutex_
);
q_
.
push_back
(
std
::
move
(
item
));
push_cv_
.
notify_one
();
}
// try to dequeue item. if no item found. wait upto timeout and try again
// Return true, if succeeded dequeue item, false otherwise
bool
dequeue_for
(
T
&
popped_item
,
std
::
chrono
::
milliseconds
wait_duration
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
queue_mutex_
);
if
(
!
push_cv_
.
wait_for
(
lock
,
wait_duration
,
[
this
]
{
return
!
this
->
q_
.
empty
();
}))
{
return
false
;
}
q_
.
pop_front
(
popped_item
);
pop_cv_
.
notify_one
();
return
true
;
}
#endif
private:
private:
std
::
mutex
queue_mutex_
;
std
::
mutex
queue_mutex_
;
std
::
condition_variable
push_cv_
;
std
::
condition_variable
push_cv_
;
...
...
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