summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/once.c
blob: d77c3c12e3d948b1e5561fbc1665504d3a7616e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * @file
 *
 * @brief POSIX Once Manager Initialization
 * @ingroup POSIX_ONCE POSIX Once Support
 */

/*
 *  COPYRIGHT (c) 2013
 *  Chris Johns <chrisj@rtems.org>
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <pthread.h>
#include <errno.h>

#include <rtems.h>
#include <rtems/posix/onceimpl.h>

pthread_mutex_t _POSIX_Once_Lock;

void _POSIX_Once_Manager_initialization(void)
{
  pthread_mutexattr_t mattr;
  int r;

  _POSIX_Once_Lock = PTHREAD_MUTEX_INITIALIZER;

  r = pthread_mutexattr_init( &mattr );
  if ( r != 0 )
    rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, 0x80aa0000 | r );

  r = pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_RECURSIVE );
   if ( r != 0 )
    rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, 0x80aa1000 | r );

  r = pthread_mutex_init( &_POSIX_Once_Lock, &mattr );
  if ( r != 0 )
    rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, 0x80aa2000 | r );

  pthread_mutexattr_destroy( &mattr );
}