Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
KOS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Karsten
KOS
Commits
09ad928f
Commit
09ad928f
authored
6 years ago
by
Martin Karsten
Browse files
Options
Downloads
Patches
Plain Diff
- rename BargingMutex to SpinMutex and add proper barging mutex without atomic spinning
parent
768cec27
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/runtime/BlockingSync.h
+41
-4
41 additions, 4 deletions
src/runtime/BlockingSync.h
src/testoptions.h
+1
-0
1 addition, 0 deletions
src/testoptions.h
with
42 additions
and
4 deletions
src/runtime/BlockingSync.h
+
41
−
4
View file @
09ad928f
...
...
@@ -410,8 +410,43 @@ public:
}
};
template
<
typename
Semaphore
,
bool
OwnerLock
,
size_t
SpinStart
,
size_t
SpinEnd
>
template
<
typename
Lock
,
bool
OwnerLock
=
false
,
typename
BQ
=
BlockingQueue
<
Lock
>
>
class
BargingMutex
{
Lock
lock
;
StackContext
*
owner
;
BQ
bq
;
protected:
bool
internalAcquire
(
bool
wait
,
const
Time
&
timeout
=
Time
::
zero
())
{
StackContext
*
cs
=
CurrStack
();
for
(;;)
{
lock
.
acquire
();
if
(
!
owner
)
break
;
if
(
owner
==
cs
)
{
GENASSERT1
(
OwnerLock
,
FmtHex
(
owner
));
break
;
}
if
(
!
bq
.
block
(
lock
,
wait
,
timeout
))
return
false
;
}
owner
=
cs
;
lock
.
release
();
return
true
;
}
public
:
BargingMutex
()
:
owner
(
nullptr
)
{}
bool
test
()
{
return
owner
!=
nullptr
;
}
bool
tryAcquire
()
{
return
internalAcquire
(
false
);
}
bool
acquire
(
const
Time
&
timeout
=
Time
::
zero
())
{
return
internalAcquire
(
true
,
timeout
);
}
void
release
()
{
ScopedLock
<
Lock
>
al
(
lock
);
GENASSERT1
(
owner
==
CurrStack
(),
FmtHex
(
owner
));
owner
=
nullptr
;
bq
.
unblock
();
}
};
template
<
typename
Semaphore
,
bool
OwnerLock
,
size_t
SpinStart
,
size_t
SpinEnd
>
class
SpinMutex
{
StackContext
*
owner
;
Semaphore
sem
;
...
...
@@ -442,7 +477,7 @@ protected:
}
public
:
Barg
in
g
Mutex
()
:
owner
(
nullptr
),
sem
(
1
)
{}
Sp
inMutex
()
:
owner
(
nullptr
),
sem
(
1
)
{}
bool
test
()
{
return
__atomic_load_n
(
&
owner
,
__ATOMIC_RELAXED
)
!=
nullptr
;
}
bool
tryAcquire
()
{
return
internalAcquire
(
false
);
}
...
...
@@ -480,10 +515,12 @@ public:
template
<
typename
Lock
>
#if TESTING_MUTEX_FIFO
class
Mutex
:
public
FifoMutex
<
Lock
>
{};
#elif TESTING_MUTEX_BARGING
class
Mutex
:
public
BargingMutex
<
Lock
>
{};
#elif TESTING_MUTEX_SPIN
class
Mutex
:
public
Barg
in
g
Mutex
<
Benaphore
<
BargingSemaphore
<
Lock
>>
,
false
,
4
,
1024
>
{};
class
Mutex
:
public
Sp
inMutex
<
Benaphore
<
BargingSemaphore
<
Lock
>>
,
false
,
4
,
1024
>
{};
#else
class
Mutex
:
public
Barg
in
g
Mutex
<
Benaphore
<
BargingSemaphore
<
Lock
>>
,
false
,
1
,
0
>
{};
class
Mutex
:
public
Sp
inMutex
<
Benaphore
<
BargingSemaphore
<
Lock
>>
,
false
,
1
,
0
>
{};
#endif
// simple blocking RW lock: release alternates; new readers block when writer waits -> no starvation
...
...
This diff is collapsed.
Click to expand it.
src/testoptions.h
+
1
−
0
View file @
09ad928f
...
...
@@ -20,6 +20,7 @@
//#define TESTING_BLOCKING_CONCURRENT 1 // using MPSC blocking semantics (no prio levels)
//#define TESTING_IDLE_SPIN 128 // spin before idle/halt threshold
//#define TESTING_MUTEX_FIFO 1 // use fifo/baton mutex
//#define TESTING_MUTEX_BARGING 1 // use blocking/barging mutex
//#define TESTING_MUTEX_SPIN 1 // spin before block in non-fifo mutex
//#define TESTING_PLACEMENT_RR 1 // RR placement, instead of load-based staging
#define TESTING_WAKE_CLUSTER 1 // try waking idle processor on cluster backlog
...
...
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