initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / loadbalance.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #ifndef LOADBALANCE_H
23 #define LOADBALANCE_H
24
25 #include "condition.inc"
26 #include "mutex.inc"
27 #include "thread.h"
28
29
30
31
32 // Load balancing utils
33 // There is no guarantee that all the load clients will be run in a 
34 // processing operation.
35
36
37 class LoadServer;
38
39
40
41 class LoadPackage
42 {
43 public:
44         LoadPackage();
45         virtual ~LoadPackage();
46         
47         Condition *completion_lock;
48 // Range to search in the total scan area
49 //      int pixel1, pixel2;
50 };
51
52
53 class LoadClient : public Thread
54 {
55 public:
56         LoadClient(LoadServer *server);
57         LoadClient();
58         virtual ~LoadClient();
59
60 // Called when run as distributed client
61         void run();
62 // Called when run as a single_client
63         void run_single();
64         virtual void process_package(LoadPackage *package);
65         int get_package_number();
66         LoadServer* get_server();
67
68         int done;
69         int package_number;
70         Condition *input_lock;
71         Condition *completion_lock;
72         LoadServer *server;
73 };
74
75
76
77
78 class LoadServer
79 {
80 public:
81         LoadServer(int total_clients, int total_packages);
82         virtual ~LoadServer();
83
84         friend class LoadClient;
85
86 // Called first in process_packages.  Should also initialize clients.
87         virtual void init_packages() {};
88         virtual LoadClient* new_client() { return 0; };
89         virtual LoadPackage* new_package() { return 0; };
90
91 // User calls this to do an iteration with the distributed clients
92         void process_packages();
93
94 // Use this to do an iteration with one client, in the current thread.
95 // The single client is created specifically for this call and deleted in 
96 // delete_clients.  This simplifies the porting to OpenGL.
97 // total_packages must be > 0.
98         void process_single();
99
100 // These values are computed from the value of is_single.
101         int get_total_packages();
102         int get_total_clients();
103         LoadPackage* get_package(int number);
104         LoadClient* get_client(int number);
105         void set_package_count(int total_packages);
106
107
108
109         void delete_clients();
110         void create_clients();
111         void delete_packages();
112         void create_packages();
113
114
115
116
117 private:
118         int current_package;
119         LoadPackage **packages;
120         int total_packages;
121         LoadClient **clients;
122         LoadClient *single_client;
123         int total_clients;
124         int is_single;
125         Mutex *client_lock;
126 };
127
128
129
130 #endif
131
132