-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicc_thread_daten.h
120 lines (104 loc) · 3.41 KB
/
icc_thread_daten.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* ICC Examin ist eine ICC Profil Betrachter
*
* Copyright (C) 2004-2007 Kai-Uwe Behrmann
*
* Autor: Kai-Uwe Behrmann <ku.b@gmx.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* -----------------------------------------------------------------------------
*/
/** @brief a class with thread observer capabilities
*
*/
//! @date 11. 09. 2006
#ifndef ICC_THREAD_DATEN_H
#define ICC_THREAD_DATEN_H
#include "icc_utils.h"
#include "icc_helfer.h"
#include "icc_list.h"
#include "threads.h"
/** @brief * the class with locking
*
* allowes thread save daten handling
*/
namespace icc_examin_ns {
class ThreadDaten
{
bool frei_; //!<@brief is not used from further process
int zahl_; //!<@brief count of waiters
Fl_Thread pth;
iccThreadMutex_m mutex_;
protected:
void init() { frei_ = true; zahl_ = 0; report_owner = 0;
iccThreadMutexInit_m( &mutex_, 0 ); }
ThreadDaten() { init(); }
~ThreadDaten() {;}
ThreadDaten (const ThreadDaten & s) {
copy(s); }
public:
bool frei(); //!<@brief is not locked
void frei(int freigeben); //!<@brief lock with wait/unlock
bool report_owner;
ThreadDaten& copy (const ThreadDaten& s ICC_UNUSED) {
init();
return *this; }
ThreadDaten& operator = (const ThreadDaten& d) {
return copy(d); }
};
/** @brief a thread save list
*
* this safty makes the structure as well expensive
*/
template <typename T>
class ICCThreadList : public ICClist<T>,
public icc_examin_ns::ThreadDaten
{
public:
/** @brief index access operator
*
* no check in this basic class
*/
T & operator [] (size_t i) {
//if(i < n_)
return ICClist<T>::operator[](i);
//return *((ICClist<T>*)this)[i];
/*else
DBG_PROG_S("out of range");
return list_[reserve_ + 1000000000]; // create exception */
}
/** @brief constant index access operator */
const T& operator [] (const size_t i) const {
//if(i < n_)
return ICClist<T>::operator[](i);
/*else
DBG_PROG_S("out of range");
return list_[reserve_ + 1000000000]; // create exception */
}
ICCThreadList ()
: ThreadDaten() {;}
~ICCThreadList () {;}
ICCThreadList (const ICCThreadList & s) {
copy(s); }
ICCThreadList& copy (const ICCThreadList& s) {
ICClist<T>::copy(s);
icc_examin_ns::ThreadDaten::copy(s);
return *this; }
ICCThreadList& operator = (const ICCThreadList& d) {
return copy(d); }
};
}
#endif //ICC_THREAD_DATEN_H