1 #ifndef __HEATING_H__
2 #define __HEATING_H__
3 /* heating scheme using a thread pool if available
4 
5 Peter Beerli 2000
6 
7 
8 Copyright 1996-2002 Peter Beerli and Joseph Felsenstein, Seattle WA
9 Copyright 2003-2004 Peter Beerli, Tallahassee FL
10 
11  Permission is hereby granted, free of charge, to any person obtaining
12  a copy of this software and associated documentation files (the
13  "Software"), to deal in the Software without restriction, including
14  without limitation the rights to use, copy, modify, merge, publish,
15  distribute, sublicense, and/or sell copies of the Software, and to
16  permit persons to whom the Software is furnished to do so, subject
17  to the following conditions:
18 
19  The above copyright notice and this permission notice shall be
20  included in all copies or substantial portions of the Software.
21 
22  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
26  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 
30 $Id: heating.h 2157 2013-04-16 22:27:40Z beerli $
31 
32 */
33 
34 #ifdef PTHREADS
35 #include <stdio.h>
36 #include <pthread.h>
37 
38 typedef struct tpool_work
39 {
40     void (*routine) ();
41     void *arg;
42     struct tpool_work *next;
43 }
44 tpool_work_t;
45 
46 typedef struct _tpool_t
47 {
48     int num_threads;
49     int max_queue_size;
50     int do_not_block_when_full;
51     pthread_t *threads;
52     int cur_queue_size;
53     tpool_work_t *queue_head;
54     tpool_work_t *queue_tail;
55     pthread_mutex_t random_lock;
56     pthread_mutex_t queue_lock;
57     pthread_cond_t queue_done;
58     pthread_cond_t queue_not_empty;
59     pthread_cond_t queue_not_full;
60     pthread_cond_t queue_empty;
61     int queue_closed;
62     int shutdown;
63     int done;
64 }
65 _tpool_t;
66 
67 typedef _tpool_t *tpool_t;
68 
69 extern void tpool_init (tpool_t * tpoolp, int num_worker_threads,
70                             int max_queue_size, int do_not_block_when_full);
71 extern void fill_tpool (tpool_t tpool, world_fmt ** universe,
72                             int universe_size);
73 extern void wait_tpool (tpool_t tpoolp, int usize);
74 extern int tpool_destroy (tpool_t tpool, int finish);
75 extern int tpool_synchronize (tpool_t tpool, int finish);
76 extern int tpool_add_work (tpool_t tpool, void *routine, void *arg, long z);
77 #else
78 
79 
80 
81 #endif /*PTHREADS*/
82 
83 
84 extern void adjust_temperatures(world_fmt ** universe, long hchains, long step, long steps);
85 extern void adjust_temperatures_bounded(world_fmt ** universe, long hchains, long step, long steps);
86 #endif
87