source: rtems/cpukit/posix/src/keyrundestructors.c @ a2e3f33

4.115
Last change on this file since a2e3f33 was a2e3f33, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 24, 2013 at 11:50:54 AM

score: Create object implementation header

Move implementation specific parts of object.h and object.inl into new
header file objectimpl.h. The object.h contains now only the
application visible API.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief Thread-Specific Data Key Create
5 * @ingroup POSIX_KEY Key
6 */
7
8/*
9 *  Copyright (c) 2010 embedded brains GmbH.
10 *
11 *  COPYRIGHT (c) 1989-2007.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <rtems/system.h>
24#include <rtems/score/thread.h>
25#include <rtems/posix/key.h>
26
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
36void _POSIX_Keys_Run_destructors(
37  Thread_Control *thread
38)
39{
40  Objects_Maximum thread_index = _Objects_Get_index( thread->Object.id );
41  Objects_APIs thread_api = _Objects_Get_API( thread->Object.id );
42  bool done = false;
43
44  /*
45   *  The standard allows one to avoid a potential infinite loop and limit the
46   *  number of iterations.  An infinite loop may happen if destructors set
47   *  thread specific data.  This can be considered dubious.
48   *
49   *  Reference: 17.1.1.2 P1003.1c/Draft 10, p. 163, line 99.
50   */
51  while ( !done ) {
52    Objects_Maximum index = 0;
53    Objects_Maximum max = _POSIX_Keys_Information.maximum;
54
55    done = true;
56
57    for ( index = 1 ; index <= max ; ++index ) {
58      POSIX_Keys_Control *key = (POSIX_Keys_Control *)
59        _POSIX_Keys_Information.local_table [ index ];
60
61      if ( key != NULL && key->destructor != NULL ) {
62        void *value = key->Values [ thread_api ][ thread_index ];
63
64        if ( value != NULL ) {
65          key->Values [ thread_api ][ thread_index ] = NULL;
66          (*key->destructor)( value );
67          done = false;
68        }
69      }
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.