source: rtems/cpukit/posix/src/keydelete.c @ dbb30e26

5
Last change on this file since dbb30e26 was 3cdda03, checked in by Sebastian Huber <sebastian.huber@…>, on 07/21/16 at 10:02:17

posix: Fix double chain extract

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Deletes Thread-specific Data Key Previously Returned by keycreate.c
5 * @ingroup POSIXAPI
6 */
7
8/*
9 * COPYRIGHT (c) 1989-2007.
10 * On-Line Applications Research Corporation (OAR).
11 * Copyright (c) 2016 embedded brains GmbH.
12 *
13 * The license and distribution terms for this file may be
14 * found in the file LICENSE in this distribution or at
15 * http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/posix/keyimpl.h>
23
24#include <errno.h>
25
26static void _POSIX_Keys_Destroy( POSIX_Keys_Control *the_key )
27{
28  _Objects_Close( &_POSIX_Keys_Information, &the_key->Object );
29
30  while ( !_Chain_Is_empty( &the_key->Key_value_pairs ) ) {
31    POSIX_Keys_Key_value_pair *key_value_pair;
32    ISR_lock_Context           lock_context;
33    Thread_Control            *the_thread;
34
35    key_value_pair = (POSIX_Keys_Key_value_pair *)
36      _Chain_First( &the_key->Key_value_pairs );
37
38    the_thread = key_value_pair->thread;
39    _POSIX_Keys_Key_value_acquire( the_thread, &lock_context );
40    _RBTree_Extract(
41      &the_thread->Keys.Key_value_pairs,
42      &key_value_pair->Lookup_node
43    );
44    _POSIX_Keys_Key_value_release( the_thread, &lock_context );
45
46    _POSIX_Keys_Key_value_free( key_value_pair );
47  }
48
49  _Objects_Free( &_POSIX_Keys_Information, &the_key->Object );
50}
51
52/*
53 *  17.1.3 Thread-Specific Data Key Deletion, P1003.1c/Draft 10, p. 167
54 */
55int pthread_key_delete(
56  pthread_key_t  key
57)
58{
59  POSIX_Keys_Control *the_key;
60  int                 eno;
61
62  _Objects_Allocator_lock();
63
64  the_key = _POSIX_Keys_Get( key );
65  if ( the_key != NULL ) {
66    _POSIX_Keys_Destroy( the_key );
67    eno = 0;
68  } else {
69    eno = EINVAL;
70  }
71
72  _Objects_Allocator_unlock();
73
74  return eno;
75}
Note: See TracBrowser for help on using the repository browser.