Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
1750e1ba
Commit
1750e1ba
authored
9 years ago
by
Martine Lenders
Browse files
Options
Downloads
Patches
Plain Diff
core: mutex: piggy-back some style fixes
parent
ccb45215
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
core/mutex.c
+16
-8
16 additions, 8 deletions
core/mutex.c
with
16 additions
and
8 deletions
core/mutex.c
+
16
−
8
View file @
1750e1ba
...
@@ -40,18 +40,21 @@
...
@@ -40,18 +40,21 @@
int
_mutex_lock
(
mutex_t
*
mutex
,
int
blocking
)
int
_mutex_lock
(
mutex_t
*
mutex
,
int
blocking
)
{
{
unsigned
irqstate
=
irq_disable
();
unsigned
irqstate
=
irq_disable
();
DEBUG
(
"PID[%"
PRIkernel_pid
"]: Mutex in use.
\n
"
,
sched_active_pid
);
DEBUG
(
"PID[%"
PRIkernel_pid
"]: Mutex in use.
\n
"
,
sched_active_pid
);
if
(
mutex
->
queue
.
next
==
NULL
)
{
if
(
mutex
->
queue
.
next
==
NULL
)
{
/* mutex is unlocked. */
/* mutex is unlocked. */
mutex
->
queue
.
next
=
MUTEX_LOCKED
;
mutex
->
queue
.
next
=
MUTEX_LOCKED
;
DEBUG
(
"PID[%"
PRIkernel_pid
"]: mutex_wait early out.
\n
"
,
sched_active_pid
);
DEBUG
(
"PID[%"
PRIkernel_pid
"]: mutex_wait early out.
\n
"
,
sched_active_pid
);
irq_restore
(
irqstate
);
irq_restore
(
irqstate
);
return
1
;
return
1
;
}
}
else
if
(
blocking
)
{
else
if
(
blocking
)
{
thread_t
*
me
=
(
thread_t
*
)
sched_active_thread
;
thread_t
*
me
=
(
thread_t
*
)
sched_active_thread
;
DEBUG
(
"PID[%"
PRIkernel_pid
"]: Adding node to mutex queue: prio: %"
PRIu32
"
\n
"
,
sched_active_pid
,
(
uint32_t
)
me
->
priority
);
DEBUG
(
"PID[%"
PRIkernel_pid
"]: Adding node to mutex queue: prio: %"
PRIu32
"
\n
"
,
sched_active_pid
,
(
uint32_t
)
me
->
priority
);
sched_set_status
(
me
,
STATUS_MUTEX_BLOCKED
);
sched_set_status
(
me
,
STATUS_MUTEX_BLOCKED
);
if
(
mutex
->
queue
.
next
==
MUTEX_LOCKED
)
{
if
(
mutex
->
queue
.
next
==
MUTEX_LOCKED
)
{
mutex
->
queue
.
next
=
(
list_node_t
*
)
&
me
->
rq_entry
;
mutex
->
queue
.
next
=
(
list_node_t
*
)
&
me
->
rq_entry
;
...
@@ -62,7 +65,8 @@ int _mutex_lock(mutex_t *mutex, int blocking)
...
@@ -62,7 +65,8 @@ int _mutex_lock(mutex_t *mutex, int blocking)
}
}
irq_restore
(
irqstate
);
irq_restore
(
irqstate
);
thread_yield_higher
();
thread_yield_higher
();
/* we were woken up by scheduler. waker removed us from queue. we have the mutex now. */
/* We were woken up by scheduler. Waker removed us from queue.
* We have the mutex now. */
return
1
;
return
1
;
}
}
else
{
else
{
...
@@ -74,7 +78,9 @@ int _mutex_lock(mutex_t *mutex, int blocking)
...
@@ -74,7 +78,9 @@ int _mutex_lock(mutex_t *mutex, int blocking)
void
mutex_unlock
(
mutex_t
*
mutex
)
void
mutex_unlock
(
mutex_t
*
mutex
)
{
{
unsigned
irqstate
=
irq_disable
();
unsigned
irqstate
=
irq_disable
();
DEBUG
(
"mutex_unlock(): queue.next: 0x%08x pid: %"
PRIkernel_pid
"
\n
"
,
(
unsigned
)
mutex
->
queue
.
next
,
sched_active_pid
);
DEBUG
(
"mutex_unlock(): queue.next: 0x%08x pid: %"
PRIkernel_pid
"
\n
"
,
(
unsigned
)
mutex
->
queue
.
next
,
sched_active_pid
);
if
(
mutex
->
queue
.
next
==
NULL
)
{
if
(
mutex
->
queue
.
next
==
NULL
)
{
/* the mutex was not locked */
/* the mutex was not locked */
...
@@ -93,7 +99,8 @@ void mutex_unlock(mutex_t *mutex)
...
@@ -93,7 +99,8 @@ void mutex_unlock(mutex_t *mutex)
thread_t
*
process
=
container_of
((
clist_node_t
*
)
next
,
thread_t
,
rq_entry
);
thread_t
*
process
=
container_of
((
clist_node_t
*
)
next
,
thread_t
,
rq_entry
);
DEBUG
(
"mutex_unlock: waking up waiting thread %"
PRIkernel_pid
"
\n
"
,
process
->
pid
);
DEBUG
(
"mutex_unlock: waking up waiting thread %"
PRIkernel_pid
"
\n
"
,
process
->
pid
);
sched_set_status
(
process
,
STATUS_PENDING
);
sched_set_status
(
process
,
STATUS_PENDING
);
if
(
!
mutex
->
queue
.
next
)
{
if
(
!
mutex
->
queue
.
next
)
{
...
@@ -117,7 +124,8 @@ void mutex_unlock_and_sleep(mutex_t *mutex)
...
@@ -117,7 +124,8 @@ void mutex_unlock_and_sleep(mutex_t *mutex)
}
}
else
{
else
{
list_node_t
*
next
=
list_remove_head
(
&
mutex
->
queue
);
list_node_t
*
next
=
list_remove_head
(
&
mutex
->
queue
);
thread_t
*
process
=
container_of
((
clist_node_t
*
)
next
,
thread_t
,
rq_entry
);
thread_t
*
process
=
container_of
((
clist_node_t
*
)
next
,
thread_t
,
rq_entry
);
DEBUG
(
"PID[%"
PRIkernel_pid
"]: waking up waiter.
\n
"
,
process
->
pid
);
DEBUG
(
"PID[%"
PRIkernel_pid
"]: waking up waiter.
\n
"
,
process
->
pid
);
sched_set_status
(
process
,
STATUS_PENDING
);
sched_set_status
(
process
,
STATUS_PENDING
);
if
(
!
mutex
->
queue
.
next
)
{
if
(
!
mutex
->
queue
.
next
)
{
...
@@ -127,7 +135,7 @@ void mutex_unlock_and_sleep(mutex_t *mutex)
...
@@ -127,7 +135,7 @@ void mutex_unlock_and_sleep(mutex_t *mutex)
}
}
DEBUG
(
"PID[%"
PRIkernel_pid
"]: going to sleep.
\n
"
,
sched_active_pid
);
DEBUG
(
"PID[%"
PRIkernel_pid
"]: going to sleep.
\n
"
,
sched_active_pid
);
sched_set_status
((
thread_t
*
)
sched_active_thread
,
STATUS_SLEEPING
);
sched_set_status
((
thread_t
*
)
sched_active_thread
,
STATUS_SLEEPING
);
irq_restore
(
irqstate
);
irq_restore
(
irqstate
);
thread_yield_higher
();
thread_yield_higher
();
}
}
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