1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2007. |
---|
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.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <errno.h> |
---|
17 | #include <limits.h> |
---|
18 | #include <pthread.h> |
---|
19 | #include <string.h> |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/score/thread.h> |
---|
23 | #include <rtems/score/wkspace.h> |
---|
24 | #include <rtems/posix/key.h> |
---|
25 | |
---|
26 | /*PAGE |
---|
27 | * |
---|
28 | * _POSIX_Keys_Run_destructors |
---|
29 | * |
---|
30 | * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 |
---|
31 | * |
---|
32 | * NOTE: This is the routine executed when a thread exits to |
---|
33 | * run through all the keys and do the destructor action. |
---|
34 | */ |
---|
35 | |
---|
36 | void _POSIX_Keys_Run_destructors( |
---|
37 | Thread_Control *thread |
---|
38 | ) |
---|
39 | { |
---|
40 | uint32_t index; |
---|
41 | uint32_t thread_index; |
---|
42 | uint32_t thread_api; |
---|
43 | uint32_t iterations; |
---|
44 | bool are_all_null; |
---|
45 | POSIX_Keys_Control *the_key; |
---|
46 | void *value; |
---|
47 | |
---|
48 | thread_index = _Objects_Get_index( thread->Object.id ); |
---|
49 | thread_api = _Objects_Get_API( thread->Object.id ); |
---|
50 | |
---|
51 | iterations = 0; |
---|
52 | |
---|
53 | for ( ; ; ) { |
---|
54 | |
---|
55 | are_all_null = TRUE; |
---|
56 | |
---|
57 | for ( index=1 ; index <= _POSIX_Keys_Information.maximum ; index++ ) { |
---|
58 | |
---|
59 | the_key = (POSIX_Keys_Control *) |
---|
60 | _POSIX_Keys_Information.local_table[ index ]; |
---|
61 | |
---|
62 | if ( the_key && the_key->is_active && the_key->destructor ) { |
---|
63 | value = the_key->Values[ thread_api ][ thread_index ]; |
---|
64 | if ( value ) { |
---|
65 | (*the_key->destructor)( value ); |
---|
66 | if ( the_key->Values[ thread_api ][ thread_index ] ) |
---|
67 | are_all_null = FALSE; |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | if ( are_all_null == TRUE ) |
---|
73 | return; |
---|
74 | |
---|
75 | iterations++; |
---|
76 | |
---|
77 | /* |
---|
78 | * The standard allows one to not do this and thus go into an infinite |
---|
79 | * loop. It seems rude to unnecessarily lock up a system. |
---|
80 | * |
---|
81 | * Reference: 17.1.1.2 P1003.1c/Draft 10, p. 163, line 99. |
---|
82 | */ |
---|
83 | |
---|
84 | if ( iterations >= PTHREAD_DESTRUCTOR_ITERATIONS ) |
---|
85 | return; |
---|
86 | } |
---|
87 | } |
---|