source: rtems/cpukit/posix/src/keydelete.c @ 3cdda03

5
Last change on this file since 3cdda03 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
RevLine 
[65f6d3c]1/**
2 * @file
3 *
4 * @brief Deletes Thread-specific Data Key Previously Returned by keycreate.c
[5cb175bb]5 * @ingroup POSIXAPI
[65f6d3c]6 */
7
[63edcf24]8/*
[b5c9064]9 * COPYRIGHT (c) 1989-2007.
10 * On-Line Applications Research Corporation (OAR).
[5eaf0e7]11 * Copyright (c) 2016 embedded brains GmbH.
[feaa007]12 *
[b5c9064]13 * The license and distribution terms for this file may be
14 * found in the file LICENSE in this distribution or at
[c499856]15 * http://www.rtems.org/license/LICENSE.
[63edcf24]16 */
17
[f42b726]18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
[5eaf0e7]22#include <rtems/posix/keyimpl.h>
23
[63edcf24]24#include <errno.h>
25
[5eaf0e7]26static void _POSIX_Keys_Destroy( POSIX_Keys_Control *the_key )
27{
28  _Objects_Close( &_POSIX_Keys_Information, &the_key->Object );
29
[3cdda03]30  while ( !_Chain_Is_empty( &the_key->Key_value_pairs ) ) {
[5eaf0e7]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 *)
[3cdda03]36      _Chain_First( &the_key->Key_value_pairs );
[5eaf0e7]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}
[63edcf24]51
[77c330ce]52/*
[63edcf24]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{
[77c330ce]59  POSIX_Keys_Control *the_key;
[5eaf0e7]60  int                 eno;
[874297f3]61
[23fec9f0]62  _Objects_Allocator_lock();
[860c34e]63
[5eaf0e7]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;
[63edcf24]70  }
[860c34e]71
[23fec9f0]72  _Objects_Allocator_unlock();
73
[5eaf0e7]74  return eno;
[63edcf24]75}
Note: See TracBrowser for help on using the repository browser.