Skip to content

Commit 9015f48

Browse files
committed
Remove remove_item() func
1 parent e40e888 commit 9015f48

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

analyzer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include "analyzer.h"
2+
#include "cputracker.h"
23

34
void *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);

cputracker.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,19 @@ int get_semaphore_value(sem_t *sem) {
2525

2626
struct 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-
4334
int 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
}

cputracker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,4 @@ extern sem_t g_leftSpaceSemaphore;
4242
int get_nproc(int *nproc);
4343
int get_semaphore_value(sem_t *sem);
4444
struct proc_stat *get_item();
45-
struct proc_stat *remove_item();
4645
#endif

reader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)