File indexing completed on 2025-05-11 08:24:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifdef HAVE_CONFIG_H
0036 #include "config.h"
0037 #endif
0038
0039 #include "tmacros.h"
0040 #include <stdio.h>
0041 #include <errno.h>
0042 #include <stdlib.h>
0043
0044 #include <pthread.h>
0045
0046 #include <rtems.h> /* for task creation */
0047
0048 const char rtems_test_name[] = "PSXSPIN 1";
0049
0050
0051 int test_main(void);
0052
0053
0054
0055
0056
0057 #if defined(__rtems__)
0058 int test_main(void)
0059 #else
0060 int main(
0061 int argc,
0062 char **argv
0063 )
0064 #endif
0065 {
0066 pthread_spinlock_t spinlock;
0067 pthread_spinlock_t spinlock2;
0068 int status;
0069
0070 TEST_BEGIN();
0071
0072 puts( "pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE ) -- OK" );
0073 status = pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE );
0074 rtems_test_assert( status == 0 );
0075
0076 puts( "pthread_spin_destroy( &spinlock ) -- OK" );
0077 status = pthread_spin_destroy( &spinlock );
0078 rtems_test_assert( status == 0 );
0079
0080 puts( "pthread_spin_init( &spinlock, PTHREAD_PROCESS_SHARED ) -- OK" );
0081 status = pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE );
0082 rtems_test_assert( status == 0 );
0083
0084 puts( "pthread_spin_destroy( &spinlock ) -- OK" );
0085 status = pthread_spin_destroy( &spinlock );
0086 rtems_test_assert( status == 0 );
0087
0088 puts( "pthread_spin_init( &spinlock, 0x1234 ) -- OK" );
0089 status = pthread_spin_init( &spinlock, 0x1234 );
0090 rtems_test_assert( status == 0 );
0091
0092 puts( "pthread_spin_init( &spinlock2, 0 ) -- OK" );
0093 status = pthread_spin_init( &spinlock2, 0 );
0094 rtems_test_assert( status == 0 );
0095
0096 rtems_test_assert( _ISR_Get_level() == 0 );
0097
0098 puts( "pthread_spin_lock( &spinlock ) -- OK" );
0099 status = pthread_spin_lock( &spinlock );
0100 rtems_test_assert( status == 0 );
0101
0102 rtems_test_assert( _ISR_Get_level() != 0 );
0103
0104 puts( "pthread_spin_lock( &spinlock2 ) -- OK" );
0105 status = pthread_spin_lock( &spinlock2 );
0106 rtems_test_assert( status == 0 );
0107
0108 rtems_test_assert( _ISR_Get_level() != 0 );
0109
0110 puts( "pthread_spin_unlock( &spinlock2 ) -- OK" );
0111 status = pthread_spin_unlock( &spinlock2 );
0112 rtems_test_assert( status == 0 );
0113
0114 rtems_test_assert( _ISR_Get_level() != 0 );
0115
0116 puts( "pthread_spin_unlock( &spinlock ) -- OK" );
0117 status = pthread_spin_unlock( &spinlock );
0118 rtems_test_assert( status == 0 );
0119
0120 rtems_test_assert( _ISR_Get_level() == 0 );
0121
0122 puts( "pthread_spin_trylock( &spinlock ) -- OK" );
0123 status = pthread_spin_trylock( &spinlock );
0124 rtems_test_assert( status == 0 );
0125
0126 rtems_test_assert( _ISR_Get_level() != 0 );
0127
0128 puts( "pthread_spin_trylock( &spinlock2 ) -- OK" );
0129 status = pthread_spin_trylock( &spinlock2 );
0130 rtems_test_assert( status == 0 );
0131
0132 rtems_test_assert( _ISR_Get_level() != 0 );
0133
0134 puts( "pthread_spin_unlock( &spinlock2 ) -- OK" );
0135 status = pthread_spin_unlock( &spinlock2 );
0136 rtems_test_assert( status == 0 );
0137
0138 rtems_test_assert( _ISR_Get_level() != 0 );
0139
0140 puts( "pthread_spin_unlock( &spinlock ) -- OK" );
0141 status = pthread_spin_unlock( &spinlock );
0142 rtems_test_assert( status == 0 );
0143
0144 rtems_test_assert( _ISR_Get_level() == 0 );
0145
0146 puts( "pthread_spin_destroy( &spinlock2 ) -- OK" );
0147 status = pthread_spin_destroy( &spinlock2 );
0148 rtems_test_assert( status == 0 );
0149
0150 puts( "pthread_spin_destroy( &spinlock ) -- OK" );
0151 status = pthread_spin_destroy( &spinlock );
0152 rtems_test_assert( status == 0 );
0153
0154 TEST_END();
0155 exit(0);
0156 }