comparison packages/services/objloader/current/tests/library/hello.c @ 2243:6fd46febe457

Warnings, cosmetic fixes from Anthony Tonizzo
author gthomas
date Wed, 28 Jun 2006 12:48:46 +0000
parents 8bf90d16b837
children 74dbf4c3f2e1
comparison
equal deleted inserted replaced
2242:ccc0f40c3371 2243:6fd46febe457
40 * ------------------------------------------- 40 * -------------------------------------------
41 * ####ECOSGPLCOPYRIGHTEND#### 41 * ####ECOSGPLCOPYRIGHTEND####
42 * ================================================================= 42 * =================================================================
43 * #####DESCRIPTIONBEGIN#### 43 * #####DESCRIPTIONBEGIN####
44 * 44 *
45 * Author(s): atonizzo@lycos.com 45 * Author(s): Anthony Tonizzo (atonizzo@gmail.com)
46 * Date: 2005-05-13 46 * Date: 2005-05-13
47 * Purpose: 47 * Purpose:
48 * Description: 48 * Description:
49 * 49 *
50 * ####DESCRIPTIONEND#### 50 * ####DESCRIPTIONEND####
59 cyg_sem_t sem_signal_thread; 59 cyg_sem_t sem_signal_thread;
60 int thread_a_count; 60 int thread_a_count;
61 61
62 extern int weak_fn_called; 62 extern int weak_fn_called;
63 63
64 void weak_function( void ) CYGBLD_ATTRIB_WEAK; 64 void weak_function(void) CYGBLD_ATTRIB_WEAK;
65 void weak_function( void ) 65 void weak_function(void)
66 { 66 {
67 // Store the data value passed in for this thread. 67 // Store the data value passed in for this thread.
68 diag_printf( "INFO:< This is the library weak function>" ); 68 diag_printf("INFO:< This is the library weak function>");
69 CYG_TEST_FAIL ( "Libraries weak function called when apps should be called" ); 69 CYG_TEST_FAIL ("Libraries weak function called when apps should be called");
70 } 70 }
71 71
72 void library_open( void ) 72 void library_open(void)
73 { 73 {
74 // Initialize the count for thread a. 74 // Initialize the count for thread a.
75 thread_a_count = 0; 75 thread_a_count = 0;
76 76
77 // Initialize the semaphore with a count of zero, 77 // Initialize the semaphore with a count of zero,
78 // prior to creating the threads. 78 // prior to creating the threads.
79 cyg_semaphore_init( &sem_signal_thread, 0 ); 79 cyg_semaphore_init(&sem_signal_thread, 0);
80 CYG_TEST_INFO( "Library initialized" ); 80 CYG_TEST_INFO("Library initialized");
81 } 81 }
82 82
83 void library_close( void ) 83 void library_close(void)
84 { 84 {
85 CYG_TEST_INFO( "Library closed" ); 85 CYG_TEST_INFO("Library closed");
86 } 86 }
87 87
88 void print_message( void ) 88 void print_message(void)
89 { 89 {
90 diag_printf( "INFO:<Printing a silly message...>\n" ); 90 diag_printf("INFO:<Printing a silly message...>\n");
91 } 91 }
92 92
93 // Thread A - signals thread B via semaphore. 93 // Thread A - signals thread B via semaphore.
94 void thread_a( cyg_addrword_t data ) 94 void thread_a(cyg_addrword_t data)
95 { 95 {
96 // Store the data value passed in for this thread. 96 // Store the data value passed in for this thread.
97 int msg = (int)data; 97 int msg = (int)data;
98 98
99 weak_function (); 99 weak_function ();
100 100
101 while( thread_a_count < 5 ) 101 while(thread_a_count < 5)
102 { 102 {
103 // Increment the thread a count. 103 // Increment the thread a count.
104 thread_a_count++; 104 thread_a_count++;
105 105
106 106
107 // Send out a message to the diagnostic port. 107 // Send out a message to the diagnostic port.
108 diag_printf( "INFO:<Thread A, count: %d message: %d>\n", thread_a_count, msg ); 108 diag_printf("INFO:<Thread A, count: %d message: %d>\n", thread_a_count, msg);
109 109
110 // Delay for 1 second. 110 // Delay for 1 second.
111 cyg_thread_delay( 100 ); 111 cyg_thread_delay(100);
112 112
113 // Signal thread B using the semaphore. 113 // Signal thread B using the semaphore.
114 cyg_semaphore_post( &sem_signal_thread ); 114 cyg_semaphore_post(&sem_signal_thread);
115 } 115 }
116 116
117 CYG_TEST_CHECK( weak_fn_called == 2 , "Application week function not called" ); 117 CYG_TEST_CHECK(weak_fn_called == 2 , "Application week function not called");
118 CYG_TEST_FINISH( "Object loader test finished" ); 118 CYG_TEST_FINISH("Object loader test finished");
119 } 119 }
120 120
121 // Thread B - waits for semaphore signal from thread A. 121 // Thread B - waits for semaphore signal from thread A.
122 void thread_b( cyg_addrword_t data ) 122 void thread_b(cyg_addrword_t data)
123 { 123 {
124 // Store the data value passed in for this thread. 124 // Store the data value passed in for this thread.
125 int msg = (int)data; 125 int msg = (int)data;
126 126
127 while( 1 ) 127 while(1)
128 { 128 {
129 129
130 // Signal thread B using the semaphore. 130 // Signal thread B using the semaphore.
131 cyg_semaphore_wait( &sem_signal_thread ); 131 cyg_semaphore_wait(&sem_signal_thread);
132 132
133 // Send out a message to the diagnostic port. 133 // Send out a message to the diagnostic port.
134 diag_printf( "INFO:< Thread B, message: %d>\n", msg ); 134 diag_printf("INFO:< Thread B, message: %d>\n", msg);
135 } 135 }
136 } 136 }