source: rtems/testsuites/psxtests/psxcancel/init.c @ 0fdaca2

4.104.114.84.9
Last change on this file since 0fdaca2 was 0fdaca2, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 1, 2004 at 10:14:37 AM

2004-04-01 Ralf Corsepius <ralf_corsepius@…>

  • psxcancel/init.c: Include <rtems/console.h> instead of <console.h>.
  • psxmount/test.c: Include <rtems/imfs.h> instead of <imfs.h>.
  • psxreaddir/test.c: Include <rtems/imfs.h> instead of <imfs.h>.
  • psxstat/test.c: Include <rtems/imfs.h> instead of <imfs.h>.
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Thread Test Program
3 *
4 *  - test of POSIX's pthread_init() function from rtemstask Init()
5 *
6 *     ott@linux.thai.net
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <pthread.h>
19#include <sys/time.h>
20
21#ifdef __rtems__
22#include <rtems.h>
23/* configuration information */
24
25#define CONFIGURE_INIT
26
27#include <unistd.h>
28#include <errno.h>
29#include <sched.h>
30
31#include <bsp.h> /* for device driver prototypes */
32#include <pmacros.h>
33
34rtems_task Init( rtems_task_argument argument);
35
36/* configuration information */
37
38#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
39#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
40
41#define CONFIGURE_MAXIMUM_TASKS             3
42#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
43#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)
44
45#define CONFIGURE_MAXIMUM_POSIX_THREADS 5
46#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 5
47#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 5
48
49#include <rtems/console.h>
50#include <confdefs.h>
51
52#endif /* __rtems__ */
53
54void countTaskDeferred() {
55  int i=0;
56  int type,state;
57
58  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &type);
59  pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &state);
60  while (1) {
61    printf("countTaskDeferred: elapsed time (second): %2d\n", i++ );
62    sleep(1);
63    pthread_testcancel();
64    }
65}
66
67void countTaskAsync() {
68  int i=0;
69  int type,state;
70
71  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &type);
72  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &state);
73  while (1) {
74    printf("countTaskAsync: elapsed time (second): %2d\n", i++ );
75    sleep(1);
76    }
77}
78
79#ifdef __linux__
80int main(){
81#else
82  rtems_task Init( rtems_task_argument ignored ) {
83#endif
84
85  pthread_t count;
86  int taskparameter = 0;
87
88  puts( "\n\n*** POSIX CANCEL TEST ***" );
89
90  /* Start countTask deferred */
91  {
92    int task_ret;
93    task_ret = pthread_create(&count, NULL, (void *) countTaskDeferred, (void *) &taskparameter);
94    if (task_ret) {
95      perror("pthread_create: countTask");
96      rtems_test_exit(EXIT_FAILURE);
97    }
98    /* sleep for 5 seconds, then cancel it */
99    sleep(5);
100    pthread_cancel(count);
101    pthread_join(count,NULL);
102  }
103
104  /* Start countTask asynchronous */
105  {
106    int task_ret;
107    task_ret = pthread_create(&count, NULL, (void *) countTaskAsync, (void *) &taskparameter);
108    if (task_ret) {
109      perror("pthread_create: countTask");
110      rtems_test_exit(EXIT_FAILURE);
111    }
112    /* sleep for 5 seconds, then cancel it */
113    sleep(5);
114    pthread_cancel(count);
115    pthread_join(count,NULL);
116  }
117
118
119  puts( "*** END OF POSIX CANCEL TEST ***" );
120
121#ifdef __linux__
122  return 0;
123#else
124  rtems_test_exit(EXIT_SUCCESS);
125#endif
126}
127
Note: See TracBrowser for help on using the repository browser.