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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [compat/] [posix/] [current/] [tests/] [pthread2.c] - Blame information for rev 810

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        pthread2.cxx
4
//
5
//        POSIX pthread test 2 - per-thread data
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     nickg
43
// Contributors:  nickg
44
// Date:          2000-04-10
45
// Description:   Tests POSIX per-thread data.
46
//
47
//####DESCRIPTIONEND####
48
//==========================================================================
49
 
50
#include <cyg/infra/testcase.h>
51
#include <pkgconf/posix.h>
52
 
53
#ifndef CYGPKG_POSIX_PTHREAD
54
#define NA_MSG "POSIX threads not enabled"
55
#endif
56
 
57
#ifdef NA_MSG
58
void
59
cyg_start(void)
60
{
61
    CYG_TEST_INIT();
62
    CYG_TEST_NA(NA_MSG);
63
}
64
#else
65
 
66
#include <sys/types.h>
67
#include <pthread.h>
68
 
69
//--------------------------------------------------------------------------
70
// Thread stack.
71
 
72
char thread_stack[2][PTHREAD_STACK_MIN*2];
73
 
74
pthread_t thread[2];
75
 
76
pthread_key_t key;
77
 
78
//--------------------------------------------------------------------------
79
 
80
void key_destructor( void *val )
81
{
82
    int ret;
83
 
84
    CYG_TEST_INFO( "key destructor called" );
85
 
86
    if( (long)val == 0xAAAAAAAA )
87
    {
88
        ret = pthread_setspecific( key, NULL );
89
        CYG_TEST_CHECK( ret == 0, "pthread_setspecific() returned error");
90
    }
91
    else
92
    {
93
        ret = pthread_setspecific( key, (void *)0xAAAAAAAA );
94
        CYG_TEST_CHECK( ret == 0, "pthread_setspecific() returned error");
95
    }
96
}
97
 
98
//--------------------------------------------------------------------------
99
 
100
void *pthread_entry( void *arg)
101
{
102
    int ret;
103
    int retval = 1;
104
    void *val;
105
 
106
    CYG_TEST_INFO( "Thread running" );
107
 
108
    ret = pthread_setspecific( key, arg );
109
    CYG_TEST_CHECK( ret == 0, "pthread_setspecific() returned error");
110
 
111
    val = pthread_getspecific( key );
112
    CYG_TEST_CHECK( val == arg, "pthread_getspecific() did not return expected value");
113
    if( val != arg ) retval = 0;
114
 
115
    sched_yield();
116
 
117
    val = pthread_getspecific( key );
118
    CYG_TEST_CHECK( val == arg, "pthread_getspecific() did not return expected value");
119
    if( val != arg ) retval = 0;
120
 
121
    pthread_exit( (void *)retval );
122
}
123
 
124
//--------------------------------------------------------------------------
125
 
126
int main(int argc, char **argv)
127
{
128
    int i;
129
    int ret;
130
    void *retval[2];
131
 
132
    CYG_TEST_INIT();
133
 
134
    // allocate data key
135
    ret = pthread_key_create( &key, key_destructor );
136
    CYG_TEST_CHECK( ret == 0, "pthread_key_create() returned error");
137
 
138
    // Create test threads
139
    for( i = 0; i < 2; i++ )
140
    {
141
        pthread_attr_t attr;
142
        pthread_attr_init( &attr );
143
 
144
        pthread_attr_setstackaddr( &attr, (void *)&thread_stack[i][sizeof(thread_stack[i])] );
145
        pthread_attr_setstacksize( &attr, sizeof(thread_stack[i]) );
146
 
147
        ret = pthread_create( &thread[i],
148
                              &attr,
149
                              pthread_entry,
150
                              (void *)(0x12340000+i));
151
        CYG_TEST_CHECK( ret == 0, "pthread_create() returned error");
152
    }
153
 
154
    // Now join with threads
155
    for( i = 0; i < 2; i++ )
156
        pthread_join( thread[i], &retval[i] );
157
 
158
 
159
    ret = pthread_key_delete( key );
160
    CYG_TEST_CHECK( ret == 0, "pthread_key_delete() returned error");
161
 
162
    // check retvals
163
 
164
    for( i = 0; i < 2; i++ )
165
        if( !(long)retval[0] )
166
            CYG_TEST_FAIL_FINISH( "pthread2" );
167
 
168
    CYG_TEST_PASS_FINISH( "pthread2" );
169
 
170
}
171
 
172
#endif
173
 
174
//--------------------------------------------------------------------------
175
// end of pthread2.c

powered by: WebSVN 2.1.0

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