-
Notifications
You must be signed in to change notification settings - Fork 1
/
count.c
40 lines (35 loc) · 817 Bytes
/
count.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "constants.h"
#include <pthread.h>
#include <stdio.h>
pthread_mutex_t io_time;
pthread_mutex_t m_call;
pthread_mutex_t m_time;
float io_total_time;
unsigned int m_call_cnt;
float m_time_cnt;
void init_count_mutex(){
pthread_mutex_init(&io_time, NULL);
pthread_mutex_init(&m_call, NULL);
pthread_mutex_init(&m_time, NULL);
io_total_time = 0;
m_call_cnt = 0;
m_time_cnt = 0;
}
void add_io_time(float t){
pthread_mutex_lock(&io_time);
io_total_time += t;
pthread_mutex_unlock(&io_time);
}
void add_mutex_time(float t){
pthread_mutex_lock(&m_time);
m_time_cnt += t;
pthread_mutex_unlock(&m_time);
};
void add_mutex_call(){
pthread_mutex_lock(&m_call);
m_call_cnt++;
pthread_mutex_unlock(&m_call);
};
void output(){
printf("%f, %d, %f\n", io_total_time, m_call_cnt, m_time_cnt/m_call_cnt);
}