-
Notifications
You must be signed in to change notification settings - Fork 1
/
threads.h
121 lines (110 loc) · 3.1 KB
/
threads.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
119
120
121
/******************************************************/
/* */
/* threads.h - multithreading */
/* */
/******************************************************/
/* Copyright 2020-2022 Pierre Abbat.
* This file is part of Wolkenbase.
*
* Wolkenbase is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wolkenbase is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wolkenbase. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef THREADS_H
#define THREADS_H
class Flowsnake;
#ifdef __MINGW64__
#define MINGW_STDTHREAD_REDUNDANCY_WARNING
#include <../mingw-std-threads/mingw.thread.h>
#include <../mingw-std-threads/mingw.mutex.h>
#include <../mingw-std-threads/mingw.shared_mutex.h>
#else
#include <thread>
#include <mutex>
#include <shared_mutex>
#endif
#include <chrono>
#include <vector>
#include <array>
#include <map>
#include "las.h"
#include "eisenstein.h"
#include "flowsnake.h"
#include "shape.h"
#ifdef GUI
#include "cloudoutput.h"
#endif
// These are used as both commands to the threads and status from the threads.
#define TH_WAIT 1
#define TH_READ 2
#define TH_SCAN 3
#define TH_POSTSCAN 4
#define TH_SPLIT 5
#define TH_PAUSE 6
#define TH_STOP 7
#define TH_ASLEEP 256
// These are used to tell threads to do things, mostly file-related.
#define ACT_READ 1
#define ACT_COUNT 2
#define ACT_WRITE 3
#define ACT_LOAD 4
#define RES_LOAD_PLY 1
#define RES_LOAD_XYZ 2
struct ThreadAction
{
int opcode;
int param0;
double param1;
double param2;
LasHeader *hdr;
std::string filename;
int flags;
int result;
};
extern std::map<int,std::mutex> cubeMutex;
extern std::map<int,std::map<int,Cube> > lockedCubes,readLockedCubes;
extern std::vector<Cube> heldCubes;
extern int currentAction;
extern std::chrono::steady_clock clk;
extern Flowsnake snake;
extern std::map<int,size_t> classTotals;
#ifdef GUI
extern CloudOutput cloudOutput;
#endif
double busyFraction();
void startThreads(int n);
void joinThreads();
void enqueueAction(ThreadAction a);
ThreadAction dequeueResult();
bool actionQueueEmpty();
Eisenstein dequeueTileDone();
bool tileDoneQueueEmpty();
bool resultQueueEmpty();
void embufferPoint(LasPoint point,bool fromFile);
void embufferPoints(std::vector<LasPoint> points,int thread);
LasPoint debufferPoint(int thread);
size_t pointBufferSize();
bool pointBufferEmpty();
void sleepDead(int thread);
void setThreadCommand(int newStatus);
int getThreadCommand();
int getThreadStatus();
void waitForThreads(int newStatus);
void waitForQueueEmpty();
int thisThread();
int nThreads();
class WolkenThread
{
public:
void operator()(int thread);
};
#endif