-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
118 lines (96 loc) · 2.4 KB
/
main.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef MAIN_H
#define MAIN_H
#include "constants.h"
#include "vector.h"
#include "matrixd.h"
#include "complex.h"
#include "mandel.h"
#include "lib/write_screen/drawlib.h"
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
#include <assert.h>
#include <curses.h>
// for writing to a file
#include <sys/stat.h>
#include <fcntl.h>
#define LOG_MUTEXES
#define MUTEX_FNAME "mutex_logfile"
typedef struct mandle_controls {
char is_running;
int depth;
long double zoom;
long double R;
long double I;
} MANDLE_CONTROLS;
#define MIN_JOB_SIZE 256
#define T_WORKING (char)0
#define T_LOOKING (char)1
#define T_IDLE (char)2
struct tdraw_data {
pthread_t tid;
int idx;
int num_threads;
MANDLE_CONTROLS *cont;
pthread_mutex_t state_mutex;
char state;
pthread_mutex_t bounds_mutex;
// tells each thread to interrupt mid-draw
char frame_update;
int TLx;
int TLy;
int BRx;
int BRy;
};
void display(MANDLE_CONTROLS *cont);
//threads:
// 1: mark as idle
// 2: wait to be told to work
// (loop):
// 3: take a job slot
// or break to go back to 1 if no jobs
// 4: set as working
// == do the work ==
// 5: set as finished
#ifdef LOG_MUTEXES
int logfile_fd;
pthread_mutex_t logfile_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
/* signals to the controller that the thread is waiting */
pthread_mutex_t currently_idle_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t currently_idle_cond = PTHREAD_COND_INITIALIZER;
int currently_idle;
/* signals to the thread they can take a job */
pthread_mutex_t stay_idle_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t stay_idle_cond = PTHREAD_COND_INITIALIZER;
char stay_idle;
// tells the drawer controller to interrupt all threads and restart
pthread_mutex_t frame_update_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t frame_update_cond = PTHREAD_COND_INITIALIZER;
char frame_update;
pthread_mutex_t currently_working_mutex= PTHREAD_MUTEX_INITIALIZER;
int currently_working;
/**
* makes a RGBT value out of a number (0-255)
*/
void make_colour(double val, RGBT *ret);
void make_smooth_colour(int val, RGBT *ret, com *z);
#ifndef PI
#define PI 3.14159f
#endif
#ifndef MIN
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#endif
#ifndef MAX
#define MAX(X,Y) ((X) < (Y) ? (Y) : (X))
#endif
#ifndef ABS
#define ABS(X) ((X) < 0 ? -1 * (X) : (X))
#endif
//entrypoint, init and start opengl
extern int main();
#endif