Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
8c508334
There was an error fetching the commit references. Please try again later.
Commit
8c508334
authored
8 years ago
by
MerryMage
Browse files
Options
Downloads
Patches
Plain Diff
common/thread: Correct code style
parent
db0db6a1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/common/thread.h
+19
-21
19 additions, 21 deletions
src/common/thread.h
with
19 additions
and
21 deletions
src/common/thread.h
+
19
−
21
View file @
8c508334
...
...
@@ -30,8 +30,7 @@
# endif
#endif
namespace
Common
{
namespace
Common
{
int
CurrentThreadId
();
...
...
@@ -43,55 +42,55 @@ public:
Event
()
:
is_set
(
false
)
{}
void
Set
()
{
std
::
lock_guard
<
std
::
mutex
>
lk
(
m_
mutex
);
std
::
lock_guard
<
std
::
mutex
>
lk
(
mutex
);
if
(
!
is_set
)
{
is_set
=
true
;
m_
condvar
.
notify_one
();
condvar
.
notify_one
();
}
}
void
Wait
()
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
m_
mutex
);
m_
condvar
.
wait
(
lk
,
[
&
]{
return
is_set
;
});
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutex
);
condvar
.
wait
(
lk
,
[
&
]{
return
is_set
;
});
is_set
=
false
;
}
void
Reset
()
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
m_
mutex
);
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutex
);
// no other action required, since wait loops on the predicate and any lingering signal will get cleared on the first iteration
is_set
=
false
;
}
private
:
bool
is_set
;
std
::
condition_variable
m_
condvar
;
std
::
mutex
m_
mutex
;
std
::
condition_variable
condvar
;
std
::
mutex
mutex
;
};
class
Barrier
{
public:
Barrier
(
size_t
count
)
:
m_
count
(
count
),
m_
waiting
(
0
)
{}
explicit
Barrier
(
size_t
count
_
)
:
count
(
count
_
),
waiting
(
0
)
{}
/// Blocks until all "count" threads have called Sync()
void
Sync
()
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
m_
mutex
);
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutex
);
// TODO: broken when next round of Sync()s
// is entered before all waiting threads return from the notify_all
if
(
++
m_
waiting
==
m_
count
)
{
m_
waiting
=
0
;
m_
condvar
.
notify_all
();
if
(
++
waiting
==
count
)
{
waiting
=
0
;
condvar
.
notify_all
();
}
else
{
m_
condvar
.
wait
(
lk
,
[
&
]{
return
m_
waiting
==
0
;
});
condvar
.
wait
(
lk
,
[
&
]{
return
waiting
==
0
;
});
}
}
private
:
std
::
condition_variable
m_
condvar
;
std
::
mutex
m_
mutex
;
const
size_t
m_
count
;
size_t
m_
waiting
;
std
::
condition_variable
condvar
;
std
::
mutex
mutex
;
const
size_t
count
;
size_t
waiting
;
};
void
SleepCurrentThread
(
int
ms
);
...
...
@@ -100,8 +99,7 @@ void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms
// Use this function during a spin-wait to make the current thread
// relax while another thread is working. This may be more efficient
// than using events because event functions use kernel calls.
inline
void
YieldCPU
()
{
inline
void
YieldCPU
()
{
std
::
this_thread
::
yield
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment