gif rework, C41 booby fix, add ext+s for list seq, features5
[goodguy/cinelerra.git] / cinelerra-5.1 / 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 };
49
50
51 class LoadClient : public Thread
52 {
53 public:
54         LoadClient(LoadServer *server);
55         LoadClient();
56         virtual ~LoadClient();
57
58 // Called when run as distributed client
59         void run();
60 // Called when run as a single_client
61         void run_single();
62         virtual void process_package(LoadPackage *package);
63         int get_package_number();
64         LoadServer* get_server();
65
66         int done;
67         int package_number;
68         Condition *input_lock;
69         Condition *completion_lock;
70         LoadServer *server;
71 };
72
73
74
75
76 class LoadServer
77 {
78 public:
79         LoadServer(int total_clients, int total_packages);
80         virtual ~LoadServer();
81
82         friend class LoadClient;
83
84 // Called first in process_packages.  Should also initialize clients.
85         virtual void init_packages() {};
86         virtual LoadClient* new_client() { return 0; };
87         virtual LoadPackage* new_package() { return 0; };
88
89 // User calls this to do an iteration with the distributed clients
90         void process_packages();
91
92 // Use this to do an iteration with one client, in the current thread.
93 // The single client is created specifically for this call and deleted in
94 // delete_clients.  This simplifies the porting to OpenGL.
95 // total_packages must be > 0.
96         void process_single();
97
98 // These values are computed from the value of is_single.
99         int get_total_packages();
100         int get_total_clients();
101         LoadPackage* get_package(int number);
102         LoadClient* get_client(int number);
103         void set_package_count(int total_packages);
104
105
106
107         void delete_clients();
108         void create_clients();
109         void delete_packages();
110         void create_packages();
111
112
113
114
115 private:
116         int current_package;
117         LoadPackage **packages;
118         int total_packages;
119         LoadClient **clients;
120         LoadClient *single_client;
121         int total_clients;
122         int is_single;
123         Mutex *client_lock;
124 };
125
126
127
128 #endif
129
130