OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [psxtests/] [psxcancel/] [init.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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.OARcorp.com/rtems/license.html.
11
 *
12
 *  init.c,v 1.4 2002/08/02 00:53:21 joel Exp
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
 
34
rtems_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 <console.h>
50
#include <confdefs.h>
51
 
52
#endif /* __rtems__ */
53
 
54
void 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
 
67
void 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__
80
int 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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.