RTEMS
pspinlock.c
Go to the documentation of this file.
1 
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 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
24 
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 
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 
46  offsetof( POSIX_Spinlock_Control, interrupt_state )
47  == offsetof( pthread_spinlock_t, _interrupt_state ),
48  POSIX_SPINLOCK_T_INTERRUPT_STATE
49 );
50 
52  sizeof( POSIX_Spinlock_Control ) == sizeof( pthread_spinlock_t ),
53  POSIX_SPINLOCK_T_SIZE
54 );
55 
56 int 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  SMP_lock_Stats unused_stats;
62  SMP_lock_Stats_context unused_context;
63 #endif
64 
65  the_spinlock = _POSIX_Spinlock_Get( spinlock );
66  _ISR_Local_disable( level );
67 #if defined(RTEMS_SMP)
69  &the_spinlock->Lock,
70  &unused_stats,
71  &unused_context
72  );
73 #endif
74  the_spinlock->interrupt_state = level;
75  return 0;
76 }
77 
78 int pthread_spin_trylock( pthread_spinlock_t *spinlock )
79  RTEMS_ALIAS( pthread_spin_lock );
#define _SMP_ticket_lock_Acquire(lock, stats, stats_context)
Acquires an SMP ticket lock.
#define _ISR_Local_disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:57
Inlined Routines from the POSIX Spinlock Manager.
uint32_t ISR_Level
Definition: isrlevel.h:41
#define RTEMS_STATIC_ASSERT(_cond, _msg)
Asserts at compile time that the specified condition is satisfied.
Definition: basedefs.h:838
#define RTEMS_ALIAS(_target)
Instructs the compiler to generate an alias to the specified target function.
Definition: basedefs.h:335