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

4.115
Last change on this file since be1b8a7 was eb08acf, checked in by Mathew Kallada <matkallada@…>, on 12/15/12 at 20:41:05

posix: Doxygen Enhancement Task #8

http://www.google-melange.com/gci/task/view/google/gci2012/8003213

  • Property mode set to 100644
File size: 1.9 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/object.h>
25#include <rtems/score/thread.h>
26#include <rtems/posix/key.h>
27
28/*
29 *  _POSIX_Keys_Run_destructors
30 *
31 *  17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163
32 *
33 *  NOTE:  This is the routine executed when a thread exits to
34 *         run through all the keys and do the destructor action.
35 */
36
37void _POSIX_Keys_Run_destructors(
38  Thread_Control *thread
39)
40{
41  Objects_Maximum thread_index = _Objects_Get_index( thread->Object.id );
42  Objects_APIs thread_api = _Objects_Get_API( thread->Object.id );
43  bool done = false;
44
45  /*
46   *  The standard allows one to avoid a potential infinite loop and limit the
47   *  number of iterations.  An infinite loop may happen if destructors set
48   *  thread specific data.  This can be considered dubious.
49   *
50   *  Reference: 17.1.1.2 P1003.1c/Draft 10, p. 163, line 99.
51   */
52  while ( !done ) {
53    Objects_Maximum index = 0;
54    Objects_Maximum max = _POSIX_Keys_Information.maximum;
55
56    done = true;
57
58    for ( index = 1 ; index <= max ; ++index ) {
59      POSIX_Keys_Control *key = (POSIX_Keys_Control *)
60        _POSIX_Keys_Information.local_table [ index ];
61
62      if ( key != NULL && key->destructor != NULL ) {
63        void *value = key->Values [ thread_api ][ thread_index ];
64
65        if ( value != NULL ) {
66          key->Values [ thread_api ][ thread_index ] = NULL;
67          (*key->destructor)( value );
68          done = false;
69        }
70      }
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.