Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:41

0001 /*
0002  *  COPYRIGHT (c) 1989-2013.
0003  *  On-Line Applications Research Corporation (OAR).
0004  *
0005  * Redistribution and use in source and binary forms, with or without
0006  * modification, are permitted provided that the following conditions
0007  * are met:
0008  * 1. Redistributions of source code must retain the above copyright
0009  *    notice, this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright
0011  *    notice, this list of conditions and the following disclaimer in the
0012  *    documentation and/or other materials provided with the distribution.
0013  *
0014  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0015  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0016  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0017  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0018  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0019  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0020  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0021  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0022  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0023  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0024  * POSSIBILITY OF SUCH DAMAGE.
0025  */
0026 
0027 #ifdef HAVE_CONFIG_H
0028 #include "config.h"
0029 #endif
0030 
0031 #include <timesys.h>
0032 #include <rtems/btimer.h>
0033 #include <errno.h>
0034 #include <pthread.h>
0035 #include "test_support.h"
0036 
0037 const char rtems_test_name[] = "PSXTMKEY 02";
0038 
0039 /* forward declarations to avoid warnings */
0040 void *POSIX_Init(void *argument);
0041 void benchmark_pthread_setspecific(void *value_p);
0042 void benchmark_pthread_getspecific( void *expected );
0043 
0044 pthread_key_t Key;
0045 int           Value1;
0046 
0047 void benchmark_pthread_setspecific( void *value_p )
0048 {
0049   benchmark_timer_t end_time;
0050   int  status;
0051 
0052   benchmark_timer_initialize();
0053     status = pthread_setspecific( Key, value_p );
0054   end_time = benchmark_timer_read();
0055   rtems_test_assert( status == 0 );
0056 
0057   put_time(
0058     "pthread_setspecific: only case: only case",
0059     end_time,
0060     1,        /* Only executed once */
0061     0,
0062     0
0063   );
0064 
0065 }
0066 
0067 void benchmark_pthread_getspecific( void *expected )
0068 {
0069   benchmark_timer_t end_time;
0070   void *value_p;
0071 
0072   benchmark_timer_initialize();
0073     value_p = pthread_getspecific( Key );
0074   end_time = benchmark_timer_read();
0075   rtems_test_assert( value_p == expected );
0076 
0077   put_time(
0078     "pthread_getspecific: only case",
0079     end_time,
0080     1,        /* Only executed once */
0081     0,
0082     0
0083   );
0084 }
0085 
0086 void *POSIX_Init(
0087   void *argument
0088 )
0089 {
0090   int  status;
0091 
0092   TEST_BEGIN();
0093 
0094   /* create the key */
0095   status = pthread_key_create( &Key, NULL );
0096   rtems_test_assert( status == 0 );
0097 
0098   benchmark_pthread_getspecific( NULL );
0099   benchmark_pthread_setspecific( &Value1 );
0100   benchmark_pthread_getspecific( &Value1 );
0101 
0102   /* destroy the key */
0103   status = pthread_key_delete( Key );
0104   rtems_test_assert( status == 0 );
0105 
0106   TEST_END();
0107   rtems_test_exit(0);
0108 }
0109 
0110 /* configuration information */
0111 
0112 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0113 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0114 
0115 #define CONFIGURE_MAXIMUM_POSIX_THREADS  2
0116 #define CONFIGURE_MAXIMUM_POSIX_KEYS     1
0117 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0118 
0119 #define CONFIGURE_INIT
0120 #include <rtems/confdefs.h>
0121 /* end of file */