Subversion Repositories HelenOS-historic

Rev

Rev 1129 | Rev 1175 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1129 Rev 1152
1
/*
1
/*
2
 * Copyright (C) 2005 Martin Decky
2
 * Copyright (C) 2005 Martin Decky
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
#include "version.h"
29
#include "version.h"
30
#include <ipc.h>
30
#include <ipc.h>
31
#include <stdio.h>
31
#include <stdio.h>
32
#include <unistd.h>
32
#include <unistd.h>
33
#include <stdlib.h>
33
#include <stdlib.h>
34
#include <ns.h>
34
#include <ns.h>
35
#include <thread.h>
35
#include <thread.h>
36
#include <psthread.h>
36
#include <psthread.h>
37
#include <futex.h>
37
#include <futex.h>
38
 
38
 
39
int a;
39
int a;
40
atomic_t ftx;
40
atomic_t ftx;
41
 
41
 
42
int __thread tls_prom;
42
int __thread stage;
43
 
43
 
44
extern void utest(void *arg);
44
extern void utest(void *arg);
45
void utest(void *arg)
45
void utest(void *arg)
46
{
46
{
47
    printf("Uspace thread started.\n");
47
    printf("Uspace thread started.\n");
48
    if (futex_down(&ftx) < 0)
48
    if (futex_down(&ftx) < 0)
49
        printf("Futex failed.\n");
49
        printf("Futex failed.\n");
50
    if (futex_up(&ftx) < 0)
50
    if (futex_up(&ftx) < 0)
51
        printf("Futex failed.\n");
51
        printf("Futex failed.\n");
52
       
52
       
53
    printf("%s in good condition.\n", __FUNCTION__);
53
    printf("%s in good condition.\n", __FUNCTION__);
54
   
54
   
55
    for (;;)
55
    for (;;)
56
        ;
56
        ;
57
}
57
}
58
 
58
 
59
static void test_printf(void)
59
static void test_printf(void)
60
{
60
{
61
    printf("Simple text.\n");
61
    printf("Simple text.\n");
62
    printf("Now insert '%s' string.\n","this");
62
    printf("Now insert '%s' string.\n","this");
63
    printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321);
63
    printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321);
64
    printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321);
64
    printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321);
65
    printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll);
65
    printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll);
66
    printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111);
66
    printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111);
67
    printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123);
67
    printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123);
68
    printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123);
68
    printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123);
69
    printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll);
69
    printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll);
70
    printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
70
    printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
71
    printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );
71
    printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );
72
   
72
   
73
    printf("Thats all, folks!\n");
73
    printf("Thats all, folks!\n");
74
}
74
}
75
 
75
 
76
 
76
 
77
extern char _heap;
77
extern char _heap;
78
static void test_mremap(void)
78
static void test_mremap(void)
79
{
79
{
80
    printf("Writing to good memory\n");
80
    printf("Writing to good memory\n");
81
    mremap(&_heap, 120000, 0);
81
    mremap(&_heap, 120000, 0);
82
    printf("%P\n", ((char *)&_heap));
82
    printf("%P\n", ((char *)&_heap));
83
    printf("%P\n", ((char *)&_heap) + 80000);
83
    printf("%P\n", ((char *)&_heap) + 80000);
84
    *(((char *)&_heap) + 80000) = 10;
84
    *(((char *)&_heap) + 80000) = 10;
85
    printf("Making small\n");
85
    printf("Making small\n");
86
    mremap(&_heap, 16000, 0);
86
    mremap(&_heap, 16000, 0);
87
    printf("Failing..\n");
87
    printf("Failing..\n");
88
    *((&_heap) + 80000) = 10;
88
    *((&_heap) + 80000) = 10;
89
 
89
 
90
    printf("memory done\n");
90
    printf("memory done\n");
91
}
91
}
92
/*
92
/*
93
static void test_sbrk(void)
93
static void test_sbrk(void)
94
{
94
{
95
    printf("Writing to good memory\n");
95
    printf("Writing to good memory\n");
96
    printf("Got: %P\n", sbrk(120000));
96
    printf("Got: %P\n", sbrk(120000));
97
    printf("%P\n", ((char *)&_heap));
97
    printf("%P\n", ((char *)&_heap));
98
    printf("%P\n", ((char *)&_heap) + 80000);
98
    printf("%P\n", ((char *)&_heap) + 80000);
99
    *(((char *)&_heap) + 80000) = 10;
99
    *(((char *)&_heap) + 80000) = 10;
100
    printf("Making small, got: %P\n",sbrk(-120000));
100
    printf("Making small, got: %P\n",sbrk(-120000));
101
    printf("Testing access to heap\n");
101
    printf("Testing access to heap\n");
102
    _heap = 10;
102
    _heap = 10;
103
    printf("Failing..\n");
103
    printf("Failing..\n");
104
    *((&_heap) + 80000) = 10;
104
    *((&_heap) + 80000) = 10;
105
 
105
 
106
    printf("memory done\n");
106
    printf("memory done\n");
107
}
107
}
108
*/
108
*/
109
/*
109
/*
110
static void test_malloc(void)
110
static void test_malloc(void)
111
{
111
{
112
    char *data;
112
    char *data;
113
 
113
 
114
    data = malloc(10);
114
    data = malloc(10);
115
    printf("Heap: %P, data: %P\n", &_heap, data);
115
    printf("Heap: %P, data: %P\n", &_heap, data);
116
    data[0] = 'a';
116
    data[0] = 'a';
117
    free(data);
117
    free(data);
118
}
118
}
119
*/
119
*/
120
 
120
 
121
 
121
 
122
static void test_ping(void)
122
static void test_ping(void)
123
{
123
{
124
    ipcarg_t result;
124
    ipcarg_t result;
125
    int retval;
125
    int retval;
126
 
126
 
127
    printf("Pinging\n");
127
    printf("Pinging\n");
128
    retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
128
    retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
129
    printf("Retval: %d - received: %P\n", retval, result);
129
    printf("Retval: %d - received: %P\n", retval, result);
130
}
130
}
131
 
131
 
132
static void got_answer(void *private, int retval, ipc_call_t *data)
132
static void got_answer(void *private, int retval, ipc_call_t *data)
133
{
133
{
134
    printf("Retval: %d...%s...%zX, %zX\n", retval, private,
134
    printf("Retval: %d...%s...%zX, %zX\n", retval, private,
135
           IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
135
           IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
136
}
136
}
137
static void test_async_ipc(void)
137
static void test_async_ipc(void)
138
{
138
{
139
    ipc_call_t data;
139
    ipc_call_t data;
140
    int i;
140
    int i;
141
 
141
 
142
    printf("Sending ping\n");
142
    printf("Sending ping\n");
143
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
143
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
144
             "Pong1", got_answer);
144
             "Pong1", got_answer);
145
    ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
145
    ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
146
             "Pong2", got_answer);
146
             "Pong2", got_answer);
147
    ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
147
    ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
148
             "Pong3", got_answer);
148
             "Pong3", got_answer);
149
    ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
149
    ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
150
             "Pong4", got_answer);
150
             "Pong4", got_answer);
151
    ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
151
    ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
152
             "Pong5", got_answer);
152
             "Pong5", got_answer);
153
    ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
153
    ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
154
             "Pong6", got_answer);
154
             "Pong6", got_answer);
155
    printf("Waiting forever...\n");
155
    printf("Waiting forever...\n");
156
    for (i=0; i<100;i++)
156
    for (i=0; i<100;i++)
157
        printf(".");
157
        printf(".");
158
    printf("\n");
158
    printf("\n");
159
    ipc_wait_for_call(&data, NULL);
159
    ipc_wait_for_call(&data, NULL);
160
    printf("Received call???\n");
160
    printf("Received call???\n");
161
}
161
}
162
 
162
 
163
 
163
 
164
static void got_answer_2(void *private, int retval, ipc_call_t *data)
164
static void got_answer_2(void *private, int retval, ipc_call_t *data)
165
{
165
{
166
    printf("Pong\n");
166
    printf("Pong\n");
167
}
167
}
168
static void test_advanced_ipc(void)
168
static void test_advanced_ipc(void)
169
{
169
{
170
    int res;
170
    int res;
171
    ipcarg_t phonead;
171
    ipcarg_t phonead;
172
    ipc_callid_t callid;
172
    ipc_callid_t callid;
173
    ipc_call_t data;
173
    ipc_call_t data;
174
    int i;
174
    int i;
175
 
175
 
176
    printf("Asking 0 to connect to me...\n");
176
    printf("Asking 0 to connect to me...\n");
177
    res = ipc_connect_to_me(0, 1, 2, &phonead);
177
    res = ipc_connect_to_me(0, 1, 2, &phonead);
178
    printf("Result: %d - phonead: %llu\n", res, phonead);
178
    printf("Result: %d - phonead: %llu\n", res, phonead);
179
    for (i=0; i < 100; i++) {
179
    for (i=0; i < 100; i++) {
180
        printf("----------------\n");
180
        printf("----------------\n");
181
        ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
181
        ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
182
                   got_answer_2);
182
                   got_answer_2);
183
        callid = ipc_wait_for_call(&data, NULL);
183
        callid = ipc_wait_for_call(&data, NULL);
184
        printf("Received ping\n");
184
        printf("Received ping\n");
185
        ipc_answer(callid, 0, 0, 0);
185
        ipc_answer(callid, 0, 0, 0);
186
    }
186
    }
187
//  callid = ipc_wait_for_call(&data, NULL);
187
//  callid = ipc_wait_for_call(&data, NULL);
188
}
188
}
189
 
189
 
190
static void test_connection_ipc(void)
190
static void test_connection_ipc(void)
191
{
191
{
192
    int res;
192
    int res;
193
    ipcarg_t result;
193
    ipcarg_t result;
194
    int phoneid;
194
    int phoneid;
195
 
195
 
196
    printf("Starting connect...\n");
196
    printf("Starting connect...\n");
197
    res = ipc_connect_me_to(PHONE_NS, 10, 20);
197
    res = ipc_connect_me_to(PHONE_NS, 10, 20);
198
    printf("Connected: %d\n", res);
198
    printf("Connected: %d\n", res);
199
    printf("pinging.\n");
199
    printf("pinging.\n");
200
    res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
200
    res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
201
    printf("Retval: %d - received: %X\n", res, result);
201
    printf("Retval: %d - received: %X\n", res, result);
202
   
202
   
203
}
203
}
204
 
204
 
205
static void test_hangup(void)
205
static void test_hangup(void)
206
{
206
{
207
    int phoneid;
207
    int phoneid;
208
    ipc_call_t data;
208
    ipc_call_t data;
209
    ipc_callid_t callid;
209
    ipc_callid_t callid;
210
    int i;
210
    int i;
211
 
211
 
212
    printf("Starting connect...\n");
212
    printf("Starting connect...\n");
213
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
213
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
214
    printf("Phoneid: %d, pinging\n", phoneid);
214
    printf("Phoneid: %d, pinging\n", phoneid);
215
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
215
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
216
             "Pong1", got_answer);
216
             "Pong1", got_answer);
217
    printf("Hangin up\n");
217
    printf("Hangin up\n");
218
    ipc_hangup(phoneid);
218
    ipc_hangup(phoneid);
219
    printf("Connecting\n");
219
    printf("Connecting\n");
220
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
220
    phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
221
    printf("Newphid: %d\n", phoneid);
221
    printf("Newphid: %d\n", phoneid);
222
    for (i=0; i < 1000; i++) {
222
    for (i=0; i < 1000; i++) {
223
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
223
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
224
            printf("callid: %d\n");
224
            printf("callid: %d\n");
225
    }
225
    }
226
    printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20));
226
    printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20));
227
}
227
}
228
 
228
 
229
static void test_slam(void)
229
static void test_slam(void)
230
{
230
{
231
    int i;
231
    int i;
232
    ipc_call_t data;
232
    ipc_call_t data;
233
    ipc_callid_t callid;
233
    ipc_callid_t callid;
234
 
234
 
235
    printf("ping");
235
    printf("ping");
236
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
236
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
237
             "Pong1", got_answer);
237
             "Pong1", got_answer);
238
    printf("slam");
238
    printf("slam");
239
    ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2,
239
    ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2,
240
             "Hang", got_answer);
240
             "Hang", got_answer);
241
    printf("ping2\n");
241
    printf("ping2\n");
242
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
242
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
243
             "Ping2", got_answer);
243
             "Ping2", got_answer);
244
   
244
   
245
    for (i=0; i < 1000; i++) {
245
    for (i=0; i < 1000; i++) {
246
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
246
        if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
247
            printf("callid: %d\n");
247
            printf("callid: %d\n");
248
    }
248
    }
249
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
249
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
250
             "Pong1", got_answer);
250
             "Pong1", got_answer);
251
    printf("Closing file\n");
251
    printf("Closing file\n");
252
    ipc_hangup(PHONE_NS);
252
    ipc_hangup(PHONE_NS);
253
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
253
    ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
254
             "Pong1", got_answer);
254
             "Pong1", got_answer);
255
    ipc_wait_for_call(&data, 0);
255
    ipc_wait_for_call(&data, 0);
256
}
256
}
257
 
257
 
258
static int ptest(void *arg)
258
static int ptest(void *arg)
259
{
259
{
260
    tls_prom = -1;
260
    stage = 1;
261
    printf("Pseudo thread stage%d.\n", -tls_prom);
261
    printf("Pseudo thread stage%d.\n", stage);
262
    tls_prom = -2;
262
    stage++;
263
    psthread_schedule_next();
263
    psthread_schedule_next();
264
    printf("Pseudo thread stage%d.\n", -tls_prom);
264
    printf("Pseudo thread stage%d.\n", stage);
265
    tls_prom = -3;
265
    stage++;
266
    psthread_schedule_next();
266
    psthread_schedule_next();
267
    printf("Pseudo thread stage%d\n", -tls_prom);
267
    printf("Pseudo thread stage%d.\n", stage);
268
    psthread_schedule_next();
268
    psthread_schedule_next();
-
 
269
    stage++;
269
    printf("Pseudo thread stage4.\n");
270
    printf("Pseudo thread stage%d.\n", stage);
270
    psthread_schedule_next();
271
    psthread_schedule_next();
271
    printf("Pseudo thread exiting.\n");
272
    printf("Pseudo thread exiting.\n");
272
    return 0;  
273
    return 0;  
273
}
274
}
274
 
275
 
275
int main(int argc, char *argv[])
276
int main(int argc, char *argv[])
276
{
277
{
277
    pstid_t ptid;
278
    pstid_t ptid;
278
    int tid;
279
    int tid;
279
 
280
 
280
    version_print();
281
    version_print();
281
 
282
 
282
//  test_printf();
283
//  test_printf();
283
//  test_ping();
284
//  test_ping();
284
//  test_async_ipc();
285
//  test_async_ipc();
285
//  test_advanced_ipc();
286
//  test_advanced_ipc();
286
//  test_connection_ipc();
287
//  test_connection_ipc();
287
//  test_hangup();
288
//  test_hangup();
288
//  test_slam();
289
//  test_slam();
289
   
290
   
290
    futex_initialize(&ftx, 1);
291
    futex_initialize(&ftx, 1);
291
    if (futex_down(&ftx) < 0)
292
    if (futex_down(&ftx) < 0)
292
        printf("Futex failed.\n");
293
        printf("Futex failed.\n");
293
    if (futex_up(&ftx) < 0)
294
    if (futex_up(&ftx) < 0)
294
        printf("Futex failed.\n");
295
        printf("Futex failed.\n");
295
 
296
 
296
    if (futex_down(&ftx) < 0)
297
    if (futex_down(&ftx) < 0)
297
        printf("Futex failed.\n");
298
        printf("Futex failed.\n");
298
/*
299
 
299
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
300
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
300
        printf("Created thread tid=%d\n", tid);
301
        printf("Created thread tid=%d\n", tid);
301
    }
302
    }
302
 
303
 
303
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
304
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
304
        printf("Created thread tid=%d\n", tid);
305
        printf("Created thread tid=%d\n", tid);
305
    }
306
    }
306
*/
307
 
307
    int i;
308
    int i;
308
   
309
   
309
    for (i = 0; i < 50000000; i++)
310
    for (i = 0; i < 50000000; i++)
310
        ;
311
        ;
311
       
312
       
312
    if (futex_up(&ftx) < 0)
313
    if (futex_up(&ftx) < 0)
313
        printf("Futex failed.\n");
314
        printf("Futex failed.\n");
314
 
315
 
315
 
316
 
316
    printf("Creating pathread\n");
317
    printf("Creating pseudo thread.\n");
317
    tls_prom = 1;
318
    stage = 1;
318
    ptid = psthread_create(ptest, NULL);
319
    ptid = psthread_create(ptest, NULL);
319
    printf("Main thread stage%d\n",tls_prom);
320
    printf("Main thread stage%d.\n", stage);
320
    tls_prom = 2;
321
    stage++;
321
    psthread_schedule_next();;
322
    psthread_schedule_next();;
322
    printf("Main thread stage%d\n", tls_prom);
323
    printf("Main thread stage%d.\n", stage);
323
    tls_prom = 3;
324
    stage++;
324
    psthread_schedule_next();;
325
    psthread_schedule_next();;
325
    printf("Main thread stage%d\n", tls_prom);
326
    printf("Main thread stage%d.\n", stage);
326
 
327
 
327
    psthread_join(ptid);
328
    psthread_join(ptid);
328
 
329
 
329
    printf("Main thread exiting.\n");
330
    printf("Main thread exiting.\n");
330
    return 0;
331
    return 0;
331
}
332
}
332
 
333