Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
05256a76
authored
9 years ago
by
Marcus Winter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
base_c: embb_spin_lock yields every 1024 spins
parent
d14778ae
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
0 deletions
+6
-0
base_c/src/mutex.c
+6
-0
No files found.
base_c/src/mutex.c
View file @
05256a76
...
...
@@ -25,6 +25,7 @@
*/
#include <embb/base/c/mutex.h>
#include <embb/base/c/thread.h>
#include <assert.h>
#include <embb/base/c/internal/unused.h>
...
...
@@ -125,10 +126,15 @@ int embb_spin_init(embb_spinlock_t* spinlock) {
int
embb_spin_lock
(
embb_spinlock_t
*
spinlock
)
{
int
expected
=
0
;
int
spins
=
1
;
// try to swap the
while
(
0
==
embb_atomic_compare_and_swap_int
(
&
spinlock
->
atomic_spin_variable_
,
&
expected
,
1
))
{
if
(
0
==
(
spins
&
1023
))
{
embb_thread_yield
();
}
spins
++
;
// reset expected, as CAS might change it...
expected
=
0
;
}
...
...
This diff is collapsed.
Click to expand it.
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