source: rtems/testsuites/psxtmtests/psxtmmutex05/init.c @ c632c5f2

4.115
Last change on this file since c632c5f2 was c632c5f2, checked in by Joel Sherrill <joel.sherrill@…>, on 07/20/11 at 20:46:48

2011-07-20 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac: Add benchmark of pthread_mutex_unlock where it is unblocking threads without preemption.
  • psxtmmutex05/.cvsignore, psxtmmutex05/Makefile.am, psxtmmutex05/init.c, psxtmmutex05/psxtmmutex05.doc: New files.
  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <coverhd.h>
17#include <tmacros.h>
18#include <timesys.h>
19#include "test_support.h"
20#include <pthread.h>
21#include <sched.h>
22#include <rtems/timerdrv.h>
23
24pthread_mutex_t MutexId;
25
26void *Blockers(
27  void *argument
28)
29{
30  int status;
31
32  /*
33   * Now we have finished the thread startup overhead,
34   * so let other threads run.  When we return, we can
35   * finish the benchmark.
36   */
37  sched_yield();
38    /* let other threads run */
39
40  status = pthread_mutex_lock( &MutexId );
41  rtems_test_assert( status == 0 );
42
43  return NULL;
44}
45
46void *POSIX_Init(
47  void *argument
48)
49{
50  int        i;
51  int        status;
52  pthread_t  threadId;
53  long       end_time;
54
55  puts( "\n\n*** POSIX TIME TEST MUTEX 05 ***" );
56
57  for ( i=0 ; i < OPERATION_COUNT ; i++ ) {
58    status = pthread_create( &threadId, NULL, Blockers, NULL );
59    rtems_test_assert( status == 0 );
60  }
61 
62  /*
63   * Deliberately create the mutex after the threads.  This way if the
64   * threads do run before we intend, they will get an error.
65   */
66  status = pthread_mutex_init( &MutexId, NULL );
67  rtems_test_assert( status == 0 );
68
69  /*
70   * Ensure the mutex is unavailable so the other threads block.
71   */
72  status = pthread_mutex_lock( &MutexId );
73  rtems_test_assert( status == 0 );
74
75  /*
76   * Let the other threads start so the thread startup overhead,
77   * is accounted for.  When we return, we can start the benchmark.
78   */
79  sched_yield();
80    /* let other threads run */
81
82  benchmark_timer_initialize();
83    status = pthread_mutex_unlock( &MutexId );
84  end_time = benchmark_timer_read();
85  rtems_test_assert( status == 0 );
86
87  put_time(
88    "pthread_mutex_unlock (no preemption)",
89    end_time,
90    OPERATION_COUNT,
91    0,
92    0
93  );
94
95  puts( "*** END OF POSIX TIME TEST MUTEX 05 ***" );
96  rtems_test_exit( 0 );
97
98  return NULL;
99}
100
101/* configuration information */
102
103#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
104#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
105
106#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 1
107#define CONFIGURE_MAXIMUM_POSIX_MUTEXES     1
108#define CONFIGURE_POSIX_INIT_THREAD_TABLE
109
110#define CONFIGURE_INIT
111
112#include <rtems/confdefs.h>
113  /* end of file */
Note: See TracBrowser for help on using the repository browser.