File tree Expand file tree Collapse file tree 4 files changed +8
-17
lines changed
Expand file tree Collapse file tree 4 files changed +8
-17
lines changed Original file line number Diff line number Diff line change 11#include "analyzer.h"
2+ #include "cputracker.h"
23
34void * analyzer () {
45 while (1 ) {
56 sem_wait (& g_filledSpaceSemaphore );
67 pthread_mutex_lock (& g_bufferMutex );
78
8- struct proc_stat * stats = remove_item ();
9+ struct proc_stat * stats = get_item ();
910
1011 pthread_mutex_unlock (& g_bufferMutex );
1112 sem_post (& g_leftSpaceSemaphore );
Original file line number Diff line number Diff line change @@ -25,28 +25,19 @@ int get_semaphore_value(sem_t *sem) {
2525
2626struct proc_stat * get_item () {
2727 int index = get_semaphore_value (& g_filledSpaceSemaphore );
28- if (index > BUFFER_SIZE ) {
29- return NULL ;
30- }
28+ // if (index > BUFFER_SIZE) {
29+ // return NULL;
30+ // }
3131 return g_buffer [index ];
3232}
3333
34- struct proc_stat * remove_item () {
35- int indexToRemove = get_semaphore_value (& g_filledSpaceSemaphore );
36- if (indexToRemove < 0 ) {
37- return NULL ;
38- }
39- struct proc_stat * stats = g_buffer [indexToRemove ];
40- return stats ;
41- }
42-
4334int main () {
4435 if (get_nproc (& g_nproc ) == -1 ) {
4536 exit (EXIT_FAILURE );
4637 }
47- for (int i = 0 ; i < BUFFER_SIZE ; i ++ ){
38+ for (int i = 0 ; i < BUFFER_SIZE ; i ++ ) {
4839 g_buffer [i ] = malloc (g_nproc * sizeof (struct proc_stat ));
49- if (g_buffer [i ] == NULL ){
40+ if (g_buffer [i ] == NULL ) {
5041 exit (EXIT_FAILURE );
5142 }
5243 }
Original file line number Diff line number Diff line change @@ -42,5 +42,4 @@ extern sem_t g_leftSpaceSemaphore;
4242int get_nproc (int * nproc );
4343int get_semaphore_value (sem_t * sem );
4444struct proc_stat * get_item ();
45- struct proc_stat * remove_item ();
4645#endif
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ void *reader() {
2929 pthread_mutex_lock (& g_bufferMutex );
3030
3131 struct proc_stat * stats = get_item ();
32- if (stats == NULL ){
32+ if (stats == NULL ) {
3333 continue ;
3434 }
3535 if (get_proc_stats (stats ) == -1 ) {
You can’t perform that action at this time.
0 commit comments