source: rtems/cpukit/posix/src/keydelete.c @ 5eaf0e7

5
Last change on this file since 5eaf0e7 was 5eaf0e7, checked in by Sebastian Huber <sebastian.huber@…>, on 03/17/16 at 06:56:31

posix: Use per-thread lookup tree for POSIX Keys

Yields higher performance on SMP systems.

Close #2625.

  • 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 ( true ) {
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_Get_unprotected( &the_key->Key_value_pairs );
37    if ( key_value_pair == NULL ) {
38      break;
39    }
40
41    the_thread = key_value_pair->thread;
42    _POSIX_Keys_Key_value_acquire( the_thread, &lock_context );
43    _RBTree_Extract(
44      &the_thread->Keys.Key_value_pairs,
45      &key_value_pair->Lookup_node
46    );
47    _POSIX_Keys_Key_value_release( the_thread, &lock_context );
48
49    _POSIX_Keys_Key_value_free( key_value_pair );
50  }
51
52  _Objects_Free( &_POSIX_Keys_Information, &the_key->Object );
53}
54
55/*
56 *  17.1.3 Thread-Specific Data Key Deletion, P1003.1c/Draft 10, p. 167
57 */
58int pthread_key_delete(
59  pthread_key_t  key
60)
61{
62  POSIX_Keys_Control *the_key;
63  int                 eno;
64
65  _Objects_Allocator_lock();
66
67  the_key = _POSIX_Keys_Get( key );
68  if ( the_key != NULL ) {
69    _POSIX_Keys_Destroy( the_key );
70    eno = 0;
71  } else {
72    eno = EINVAL;
73  }
74
75  _Objects_Allocator_unlock();
76
77  return eno;
78}
Note: See TracBrowser for help on using the repository browser.