source: rtems/cpukit/posix/src/pspinlock.c @ 0e16fa45

5
Last change on this file since 0e16fa45 was 4a03e752, checked in by Sebastian Huber <sebastian.huber@…>, on 01/13/17 at 08:45:59

configure: Remove SIZEOF_PTHREAD_SPINLOCK_T

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Wait at a Spinlock
5 *  @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Copyright (c) 2016 embedded brains GmbH
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 <rtems/posix/spinlockimpl.h>
24
25RTEMS_STATIC_ASSERT(
26#if defined(RTEMS_SMP)
27  offsetof( POSIX_Spinlock_Control, Lock.next_ticket )
28#else
29  offsetof( POSIX_Spinlock_Control, reserved[ 0 ] )
30#endif
31    == offsetof( pthread_spinlock_t, _Lock._next_ticket ),
32  POSIX_SPINLOCK_T_LOCK_NEXT_TICKET
33);
34
35RTEMS_STATIC_ASSERT(
36#if defined(RTEMS_SMP)
37  offsetof( POSIX_Spinlock_Control, Lock.now_serving )
38#else
39  offsetof( POSIX_Spinlock_Control, reserved[ 1 ] )
40#endif
41    == offsetof( pthread_spinlock_t, _Lock._now_serving ),
42  POSIX_SPINLOCK_T_LOCK_NOW_SERVING
43);
44
45RTEMS_STATIC_ASSERT(
46  offsetof( POSIX_Spinlock_Control, interrupt_state )
47    == offsetof( pthread_spinlock_t, _interrupt_state ),
48  POSIX_SPINLOCK_T_INTERRUPT_STATE
49);
50
51RTEMS_STATIC_ASSERT(
52  sizeof( POSIX_Spinlock_Control ) == sizeof( pthread_spinlock_t ),
53  POSIX_SPINLOCK_T_SIZE
54);
55
56int pthread_spin_lock( pthread_spinlock_t *spinlock )
57{
58  POSIX_Spinlock_Control *the_spinlock;
59  ISR_Level               level;
60#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
61  Per_CPU_Control        *cpu_self;
62#endif
63
64  the_spinlock = _POSIX_Spinlock_Get( spinlock );
65  _ISR_Local_disable( level );
66#if defined(RTEMS_SMP)
67#if defined(RTEMS_PROFILING)
68  /* The lock statistics are incorrect in case of nested pthread spinlocks */
69  cpu_self = _Per_CPU_Get();
70#endif
71  _SMP_ticket_lock_Acquire(
72    &the_spinlock->Lock,
73    &cpu_self->Lock_stats,
74    &cpu_self->Lock_stats_context
75  );
76#endif
77  the_spinlock->interrupt_state = level;
78  return 0;
79}
80
81int pthread_spin_trylock( pthread_spinlock_t *spinlock )
82  RTEMS_ALIAS( pthread_spin_lock );
Note: See TracBrowser for help on using the repository browser.