33#include "printer.h"
44#include "reader.h"
55
6+ volatile sig_atomic_t done = 0 ;
7+
68int g_nproc = 0 ;
7- struct proc_stat * g_dataBuffer [BUFFER_SIZE ];
9+ static struct proc_stat * g_dataBuffer [BUFFER_SIZE ];
810pthread_mutex_t g_dataBufferMutex = PTHREAD_MUTEX_INITIALIZER ;
911sem_t g_dataFilledSpaceSemaphore ;
1012sem_t g_dataLeftSpaceSemaphore ;
1113
12- unsigned long * g_printBuffer [BUFFER_SIZE ];
14+ static unsigned long * g_printBuffer [BUFFER_SIZE ];
1315pthread_mutex_t g_printBufferMutex = PTHREAD_MUTEX_INITIALIZER ;
1416sem_t g_printFilledSpaceSemaphore ;
1517sem_t g_printLeftSpaceSemaphore ;
1618
17- pthread_t readerThreadId ;
18- pthread_t analyzerThreadId ;
19- pthread_t printerThreadId ;
19+ static pthread_t readerThreadId ;
20+ static pthread_t analyzerThreadId ;
21+ static pthread_t printerThreadId ;
2022
21- int get_nproc (int * nproc ) {
22- * nproc = sysconf (_SC_NPROCESSORS_ONLN );
23+ static int get_nproc (int * nproc ) {
24+ * nproc = ( int ) sysconf (_SC_NPROCESSORS_ONLN );
2325 if (* nproc == -1 ) {
2426 return -1 ;
2527 }
2628 return 0 ;
2729}
2830
29- int get_semaphore_value (sem_t * sem ) {
31+ static int get_semaphore_value (sem_t * sem ) {
3032 int sval ;
3133 sem_getvalue (sem , & sval );
3234 return sval ;
3335}
3436
35- struct proc_stat * get_item_from_data_buffer () {
37+ struct proc_stat * get_item_from_data_buffer (void ) {
3638 int index = get_semaphore_value (& g_dataFilledSpaceSemaphore );
3739 return g_dataBuffer [index ];
3840}
3941
40- unsigned long * get_item_from_print_buffer () {
42+ unsigned long * get_item_from_print_buffer (void ) {
4143 int index = get_semaphore_value (& g_printFilledSpaceSemaphore );
4244 return g_printBuffer [index ];
4345}
4446
45- int main () {
47+ int main (void ) {
4648 if (get_nproc (& g_nproc ) == -1 ) {
4749 exit (EXIT_FAILURE );
4850 }
4951 g_nproc ++ ;
5052
5153 for (int i = 0 ; i < BUFFER_SIZE ; i ++ ) {
52- g_dataBuffer [i ] = malloc (g_nproc * sizeof (struct proc_stat ));
53- g_printBuffer [i ] = malloc (g_nproc * sizeof (unsigned long ));
54+ g_dataBuffer [i ] = malloc (( unsigned long ) g_nproc * sizeof (struct proc_stat ));
55+ g_printBuffer [i ] = malloc (( unsigned long ) g_nproc * sizeof (unsigned long ));
5456 if (g_dataBuffer [i ] == NULL || g_printBuffer [i ] == NULL ) {
5557 exit (EXIT_FAILURE );
5658 }
@@ -86,4 +88,4 @@ int main() {
8688 free (g_printBuffer [i ]);
8789 }
8890 return 0 ;
89- }
91+ }
0 commit comments