1 /*---------------------------------------------------------------------------*
2 Project: Thread Demo -- No. 3
3 File: threaddemo3.c
4
5 Copyright 1998, 1999 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: threaddemo3.c,v $
14 Revision 1.2 02/20/2006 04:13:11 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1 01/13/2006 11:24:13 hiratsu
18 Initial check in.
19
20
21 2 6/07/00 6:12p Tian
22 Updated OSCreateThread and idle function APIs
23
24 1 2/16/00 2:23p Tian
25 Cleaned up and moved to demos
26
27 1 2/08/00 5:11p Shiki
28 Initial check-in.
29 $NoKeywords: $
30 *---------------------------------------------------------------------------*/
31
32 #include <revolution.h>
33
34 OSMessageQueue MessageQueue;
35 OSMessage MessageArray[16];
36
37 OSThread Thread;
38 u8 ThreadStack[4096];
39
40 //
41 // Print server thread function
42 //
Printer(void * param)43 static void* Printer(void* param)
44 {
45 #pragma unused (param)
46 OSMessage msg;
47
48 for (;;)
49 {
50 OSReceiveMessage(&MessageQueue, &msg, OS_MESSAGE_BLOCK);
51 OSReport("%s\n", msg);
52 }
53
54 return 0;
55 }
56
main(void)57 void main(void)
58 {
59 int i;
60
61 OSInit();
62 VIInit();
63
64 OSReport("Thread Demo 2: Synchronizing with messages\n");
65
66 //
67 // Initializes the message queue
68 //
69 OSInitMessageQueue(
70 &MessageQueue, // pointer to message queue
71 MessageArray, // pointer to message boxes
72 sizeof MessageArray / sizeof MessageArray[0]); // # of message boxes
73
74 //
75 // Creates a new thread. The thread is suspended by default.
76 //
77 OSCreateThread(
78 &Thread, // ptr to the thread to init
79 Printer, // ptr to the start routine
80 0, // param passed to start routine
81 ThreadStack + sizeof ThreadStack, // initial stack address
82 sizeof ThreadStack, // stack size
83 8, // scheduling priority
84 OS_THREAD_ATTR_DETACH); // detached since it will
85 // never return
86
87
88 //
89 // Starts the thread
90 //
91 OSResumeThread(&Thread);
92
93 //
94 // Main loop
95 //
96 for (i = 0; i < 16; i++)
97 {
98 OSSendMessage(&MessageQueue, "Hello!", OS_MESSAGE_NOBLOCK);
99 VIWaitForRetrace(); // Sleep till next V-sync
100 }
101
102 OSHalt("Demo complete");
103 }
104