4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
25 #include "condition.inc"
32 // Load balancing utils
33 // There is no guarantee that all the load clients will be run in a
34 // processing operation.
45 virtual ~LoadPackage();
47 Condition *completion_lock;
48 // Range to search in the total scan area
49 // int pixel1, pixel2;
53 class LoadClient : public Thread
56 LoadClient(LoadServer *server);
58 virtual ~LoadClient();
60 // Called when run as distributed client
62 // Called when run as a single_client
64 virtual void process_package(LoadPackage *package);
65 int get_package_number();
66 LoadServer* get_server();
70 Condition *input_lock;
71 Condition *completion_lock;
81 LoadServer(int total_clients, int total_packages);
82 virtual ~LoadServer();
84 friend class LoadClient;
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; };
91 // User calls this to do an iteration with the distributed clients
92 void process_packages();
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();
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);
109 void delete_clients();
110 void create_clients();
111 void delete_packages();
112 void create_packages();
119 LoadPackage **packages;
121 LoadClient **clients;
122 LoadClient *single_client;