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
a6c4506a
authored
Feb 22, 2016
by
Marcus Winter
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'embb540_spinlock_yield' into development
parents
d2c1f41d
f33bf0f8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
0 deletions
+12
-0
base_c/include/embb/base/c/mutex.h
+3
-0
base_c/src/mutex.c
+6
-0
base_cpp/include/embb/base/mutex.h
+3
-0
No files found.
base_c/include/embb/base/c/mutex.h
View file @
a6c4506a
...
...
@@ -179,6 +179,9 @@ int embb_spin_init(
/**
* Spins until the spinlock can be locked and locks it.
*
* \note This method yields the current thread in regular,
* implementation-defined intervals.
*
* \pre \c spinlock is initialized \n
* \post If successful, \c spinlock is locked.
* \return EMBB_SUCCESS if spinlock could be locked. \n
...
...
base_c/src/mutex.c
View file @
a6c4506a
...
...
@@ -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
;
}
...
...
base_cpp/include/embb/base/mutex.h
View file @
a6c4506a
...
...
@@ -192,6 +192,9 @@ class Spinlock {
/**
* Waits until the spinlock can be locked and locks it.
*
* \note This method yields the current thread in regular,
* implementation-defined intervals.
*
* \pre The spinlock is not locked by the current thread.
* \post The spinlock is locked.
* \threadsafe
...
...
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