Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
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
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
Alberto Ruiz Garcia
Firmware
Commits
1942641f
Commit
1942641f
authored
7 years ago
by
Beat Küng
Committed by
Lorenz Meier
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
semaphore: add px4_sem_trywait
directly mapped to the posix method sem_trywait
parent
ed478f40
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/platforms/posix/px4_layer/px4_sem.cpp
+21
-0
21 additions, 0 deletions
src/platforms/posix/px4_layer/px4_sem.cpp
src/platforms/px4_sem.h
+2
-0
2 additions, 0 deletions
src/platforms/px4_sem.h
with
23 additions
and
0 deletions
src/platforms/posix/px4_layer/px4_sem.cpp
+
21
−
0
View file @
1942641f
...
...
@@ -91,6 +91,27 @@ int px4_sem_wait(px4_sem_t *s)
return
(
ret
)
?
ret
:
mret
;
}
int
px4_sem_trywait
(
px4_sem_t
*
s
)
{
int
ret
=
pthread_mutex_lock
(
&
(
s
->
lock
));
if
(
ret
)
{
return
ret
;
}
if
(
s
->
value
<=
0
)
{
errno
=
EAGAIN
;
ret
=
-
1
;
}
else
{
s
->
value
--
;
}
int
mret
=
pthread_mutex_unlock
(
&
(
s
->
lock
));
return
(
ret
)
?
ret
:
mret
;
}
int
px4_sem_timedwait
(
px4_sem_t
*
s
,
const
struct
timespec
*
abstime
)
{
int
ret
=
pthread_mutex_lock
(
&
(
s
->
lock
));
...
...
This diff is collapsed.
Click to expand it.
src/platforms/px4_sem.h
+
2
−
0
View file @
1942641f
...
...
@@ -63,6 +63,7 @@ typedef struct {
__EXPORT
int
px4_sem_init
(
px4_sem_t
*
s
,
int
pshared
,
unsigned
value
);
__EXPORT
int
px4_sem_setprotocol
(
px4_sem_t
*
s
,
int
protocol
);
__EXPORT
int
px4_sem_wait
(
px4_sem_t
*
s
);
__EXPORT
int
px4_sem_trywait
(
px4_sem_t
*
sem
);
__EXPORT
int
px4_sem_timedwait
(
px4_sem_t
*
sem
,
const
struct
timespec
*
abstime
);
__EXPORT
int
px4_sem_post
(
px4_sem_t
*
s
);
__EXPORT
int
px4_sem_getvalue
(
px4_sem_t
*
s
,
int
*
sval
);
...
...
@@ -79,6 +80,7 @@ typedef sem_t px4_sem_t;
#define px4_sem_init sem_init
#define px4_sem_setprotocol sem_setprotocol
#define px4_sem_wait sem_wait
#define px4_sem_trywait sem_trywait
#define px4_sem_post sem_post
#define px4_sem_getvalue sem_getvalue
#define px4_sem_destroy sem_destroy
...
...
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