4.115
Last change
on this file since 25f5730f was
a5385b1,
checked in by Christian Mauderer <Christian.Mauderer@…>, on 03/20/14 at 08:22:00
|
score: Unify pthread and gxx_wrapper once and move to score.
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | /* |
---|
2 | * COPYRIGHT (c) 1989-1999. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <rtems/score/onceimpl.h> |
---|
15 | #include <rtems/score/apimutex.h> |
---|
16 | |
---|
17 | #include <errno.h> |
---|
18 | |
---|
19 | #define ONCE_STATE_NOT_RUN 0 |
---|
20 | #define ONCE_STATE_RUNNING 1 |
---|
21 | #define ONCE_STATE_COMPLETE 2 |
---|
22 | |
---|
23 | int _Once( int *once_state, void ( *init_routine )( void ) ) |
---|
24 | { |
---|
25 | int eno = 0; |
---|
26 | |
---|
27 | if ( *once_state != ONCE_STATE_COMPLETE ) { |
---|
28 | _Once_Lock(); |
---|
29 | |
---|
30 | /* |
---|
31 | * Getting to here means the once_control is locked so we have: |
---|
32 | * 1. The init has not run and the state is ONCE_STATE_NOT_RUN. |
---|
33 | * 2. The init has finished and the state is ONCE_STATE_COMPLETE (already |
---|
34 | * caught by the previous if). |
---|
35 | * 3. The init is being run by this thread and the state |
---|
36 | * ONCE_STATE_RUNNING so we are nesting. This is an error. |
---|
37 | */ |
---|
38 | |
---|
39 | switch ( *once_state ) { |
---|
40 | case ONCE_STATE_NOT_RUN: |
---|
41 | *once_state = ONCE_STATE_RUNNING; |
---|
42 | ( *init_routine )(); |
---|
43 | *once_state = ONCE_STATE_COMPLETE; |
---|
44 | break; |
---|
45 | case ONCE_STATE_RUNNING: |
---|
46 | eno = EINVAL; |
---|
47 | break; |
---|
48 | default: |
---|
49 | break; |
---|
50 | } |
---|
51 | |
---|
52 | _Once_Unlock(); |
---|
53 | } |
---|
54 | |
---|
55 | return eno; |
---|
56 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.