5
Last change
on this file since 0e16fa45 was
a1f7d7d,
checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/18 at 07:00:18
|
score: RTEMS_PREDICT_TRUE(), RTEMS_PREDICT_FALSE()
Add RTEMS_PREDICT_TRUE() and RTEMS_PREDICT_FALSE() for static branch
prediction hints.
Close #3475.
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Lock a Semaphore |
---|
5 | * @ingroup POSIX_SEMAPHORE |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/posix/semaphoreimpl.h> |
---|
22 | |
---|
23 | int sem_trywait( sem_t *_sem ) |
---|
24 | { |
---|
25 | Sem_Control *sem; |
---|
26 | Thread_queue_Context queue_context; |
---|
27 | ISR_Level level; |
---|
28 | unsigned int count; |
---|
29 | |
---|
30 | POSIX_SEMAPHORE_VALIDATE_OBJECT( _sem ); |
---|
31 | |
---|
32 | sem = _Sem_Get( &_sem->_Semaphore ); |
---|
33 | _Thread_queue_Context_initialize( &queue_context ); |
---|
34 | _Thread_queue_Context_ISR_disable( &queue_context, level ); |
---|
35 | _Sem_Queue_acquire_critical( sem, &queue_context ); |
---|
36 | |
---|
37 | count = sem->count; |
---|
38 | if ( RTEMS_PREDICT_TRUE( count > 0 ) ) { |
---|
39 | sem->count = count - 1; |
---|
40 | _Sem_Queue_release( sem, level, &queue_context ); |
---|
41 | return 0; |
---|
42 | } else { |
---|
43 | _Sem_Queue_release( sem, level, &queue_context ); |
---|
44 | rtems_set_errno_and_return_minus_one( EAGAIN ); |
---|
45 | } |
---|
46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.