Imported Upstream version 3.2.2
[debian/gnuradio] / gcell / lib / runtime / gc_client_thread_info.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 #ifndef INCLUDED_GC_CLIENT_THREAD_INFO_H
22 #define INCLUDED_GC_CLIENT_THREAD_INFO_H
23
24 #include <gnuradio/omnithread.h>
25 #include <boost/utility.hpp>
26
27 enum gc_ct_state {
28   CT_NOT_WAITING,
29   CT_WAIT_ALL,
30   CT_WAIT_ANY,
31 };
32
33 /*
34  * \brief per client-thread data used by gc_job_manager
35  *
36  * "Client threads" are any threads that invoke methods on
37  * gc_job_manager.  We use pthread_set_specific to store a pointer to
38  * one of these for each thread that comes our way.
39  */
40 class gc_client_thread_info : boost::noncopyable {
41 public:
42   gc_client_thread_info() :
43     d_free(1), d_cond(&d_mutex), d_state(CT_NOT_WAITING),
44     d_jobs_done(0), d_njobs_waiting_for(0),
45     d_jobs_waiting_for(0){ }
46
47   ~gc_client_thread_info() {
48     d_free = 1;
49     d_state = CT_NOT_WAITING;
50     d_jobs_done = 0;
51     d_njobs_waiting_for = 0;
52     d_jobs_waiting_for = 0;
53   }
54
55   //! is this cti free? (1->free, 0->in use)
56   uint32_t        d_free;
57
58   //! which client info are we?
59   uint16_t        d_client_id;
60
61   //! hold this mutex to manipulate anything below here
62   omni_mutex      d_mutex;
63
64   //! signaled by event handler to wake client thread up
65   omni_condition  d_cond;
66
67   //! Is this client waiting?
68   gc_ct_state     d_state;
69   
70   //! Jobs that have finished and not yet been waited for (bitvector)
71   unsigned long  *d_jobs_done;
72
73   //! # of jobs we're waiting for
74   unsigned int    d_njobs_waiting_for;
75
76   //! Jobs that client thread is waiting for
77   gc_job_desc    **d_jobs_waiting_for;
78
79 };
80
81 #endif /* INCLUDED_GC_CLIENT_THREAD_INFO_H */