-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.c
75 lines (58 loc) · 1.32 KB
/
calculator.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <assert.h>
#include <error.h>
#include <getopt.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "calculator.h"
#include "dbg.h"
#include "libfractal/fractal.h"
#include "fractal_buffer.h"
#include "main.h"
#include "reader.h"
void *calculator(void *param)
{
fractal_t *tmp = NULL;
int *arg = (int *) param;
while (is_reading != 0) {
tmp = NULL;
sem_wait(&full);
pthread_mutex_lock(&mutex_buffer);
tmp = dequeue();
pthread_mutex_unlock(&mutex_buffer);
sem_post(&empty);
check(!tmp, "erreur avec dequeue.");
int x = 0;
int y = 0;
int width = fractal_get_width(tmp);;
int height = fractal_get_height(tmp);
int value = 0;
double average = 0;
double total = width * height;
log_info("Start calcul de fractales");
for ( y = 0; y < height ; y++) {
for( x = 0; x < width ; x++) {
value = fractal_compute_value(tmp, x, y);
average += value;
}
log_info("Vous etes ici");
}
average /= total;
tmp->average = average;
char n[SIZE_MAX] = "";
char *name = n;
strcpy(name, tmp->name);
strcat(name, ".bmp");
if (print_all) { // option d active
write_bitmap_sdl(tmp, name);
}
log_info("Fin calcul de fractales");
}
return (void *) tmp;
error:
free(tmp);
exit(EXIT_FAILURE);
}