source: rtems/cpukit/posix/src/pspininit.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Function Initializes a Spinlock Instance
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  POSIX Spinlock Manager -- Initialize a Spinlock Instance
10 *
11 *  COPYRIGHT (c) 1989-2006.
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.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <pthread.h>
24#include <errno.h>
25
26#include <rtems/system.h>
27#include <rtems/posix/spinlockimpl.h>
28
29/*
30 *  pthread_spinlock_init
31 *
32 *  This directive creates a spinlock.  A spinlock id is returned.
33 *
34 *  Input parameters:
35 *    spinlock         - pointer to spinlock id
36 *    pshared          - is this spinlock shared between processes
37 *
38 *  Output parameters:
39 *    spinlock     - spinlock id
40 *    0           - if successful
41 *    error code  - if unsuccessful
42 */
43
44int pthread_spin_init(
45  pthread_spinlock_t  *spinlock,
46  int                  pshared
47)
48{
49  POSIX_Spinlock_Control   *the_spinlock;
50  CORE_spinlock_Attributes  attributes;
51
52
53  if ( !spinlock )
54    return EINVAL;
55
56  switch ( pshared ) {
57    case PTHREAD_PROCESS_PRIVATE:    /* only supported values */
58      break;
59    case PTHREAD_PROCESS_SHARED:
60    default:
61      return EINVAL;
62  }
63
64  _Thread_Disable_dispatch();             /* prevents deletion */
65
66  the_spinlock = _POSIX_Spinlock_Allocate();
67
68  if ( !the_spinlock ) {
69    _Thread_Enable_dispatch();
70    return EAGAIN;
71  }
72
73  _CORE_spinlock_Initialize_attributes( &attributes );
74
75  _CORE_spinlock_Initialize( &the_spinlock->Spinlock, &attributes );
76
77  _Objects_Open_u32( &_POSIX_Spinlock_Information, &the_spinlock->Object, 0 );
78
79  *spinlock = the_spinlock->Object.id;
80
81  _Thread_Enable_dispatch();
82  return 0;
83}
Note: See TracBrowser for help on using the repository browser.