summaryrefslogtreecommitdiff
path: root/mthread.hpp
blob: f59732c887d0b64879ac68473c7a316ce47282bc (plain)
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
#ifndef MTHREAD_H
#define MTHREAD_H

#include <mutex>
#include <atomic>
#include <thread>
#include <complex>
#include <condition_variable>
#include "libpng_wrapper.hpp"

struct mthread_status {
  std::mutex status_lock;
  unsigned int row_load;
  bool share_finished;
  bool searching;

  bool div_syn;
  std::mutex ack_lk;
  std::mutex syn_ack_lk;
  bool div_error;

  std::condition_variable msg_notify;
};

struct mthread_divinfo {
  uint32_t x_min, x_max;
  uint32_t y_min, y_max;
};

class mthread {
  public:
    mthread(unsigned int x_mn, unsigned int x_mx, 
        std::complex<double> c_min, std::complex<double> c_max, 
         unsigned int inf_cutoff, unsigned int max_iter, png& image, double *g_vmap, unsigned int *g_histogram, 
        mthread **worker_list, unsigned int id, unsigned int jobs, std::atomic<uint32_t>& progress);
    ~mthread();
    void join();
    void dispatch();


    struct mthread_status status;
    unsigned int *histogram;
  protected:
    const unsigned int min_lines = 4;
    const unsigned int x_min_orig, x_max_orig;
    const std::complex<double> c_min;
    const std::complex<double> c_max;
    const unsigned int inf_cutoff;
    const unsigned int max_iter;
    png& image;
    double *vmap;
    const unsigned int id;
    mthread **workers;
    std::complex<double> c_current_min;
    std::complex<double> c_current_max;
    std::complex<double> step;
    std::thread *my_thread;
    const unsigned int worker_cnt;
    std::atomic<uint32_t>& progress;

    uint32_t x_min, x_max, y_min, y_max;
    uint32_t on_x, on_y;
    unsigned int divisions;
    int state;
    struct mthread_divinfo divide();
    
    void render(); //TODO 
    void render_area();
    void run();


};

#endif