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;
51 class LoadClient : public Thread
54 LoadClient(LoadServer *server);
56 virtual ~LoadClient();
58 // Called when run as distributed client
60 // Called when run as a single_client
62 virtual void process_package(LoadPackage *package);
63 int get_package_number();
64 LoadServer* get_server();
68 Condition *input_lock;
69 Condition *completion_lock;
79 LoadServer(int total_clients, int total_packages);
80 virtual ~LoadServer();
82 friend class LoadClient;
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; };
89 // User calls this to do an iteration with the distributed clients
90 void process_packages();
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();
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);
107 void delete_clients();
108 void create_clients();
109 void delete_packages();
110 void create_packages();
117 LoadPackage **packages;
119 LoadClient **clients;
120 LoadClient *single_client;