main page
modules
namespaces
classes
files
Gecode home
Generated on Wed Jan 1 2020 10:37:59 for Gecode by
doxygen
1.8.16
gecode
support
thread
thread.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2009
8
*
9
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
namespace
Gecode
{
namespace
Support {
35
36
/*
37
* Runnable objects
38
*/
39
forceinline
40
Runnable::Runnable
(
bool
d0)
41
:
d
(d0) {}
42
forceinline
void
43
Runnable::todelete
(
bool
d0) {
44
d=d0;
45
}
46
forceinline
bool
47
Runnable::todelete
(
void
)
const
{
48
return
d;
49
}
50
forceinline
void
51
Runnable::operator
delete
(
void
*
p
) {
52
heap
.
rfree
(
p
);
53
}
54
forceinline
void
*
55
Runnable::operator
new
(
size_t
s) {
56
return
heap
.
ralloc
(s);
57
}
58
59
/*
60
* Mutexes
61
*
62
*/
63
forceinline
void
*
64
Mutex::operator
new
(
size_t
s) {
65
return
Gecode::heap
.
ralloc
(s);
66
}
67
68
forceinline
void
69
Mutex::operator
delete
(
void
*
p
) {
70
Gecode::heap
.
rfree
(
p
);
71
}
72
73
#if ! ( defined(GECODE_THREADS_WINDOWS) || defined(GECODE_THREADS_OSX_UNFAIR) || !defined(GECODE_THREADS_PTHREADS_SPINLOCK) )
74
75
/*
76
* Fast mutexes
77
*
78
*/
79
forceinline
void
*
80
FastMutex::operator
new
(
size_t
s) {
81
return
Gecode::heap
.
ralloc
(s);
82
}
83
84
forceinline
void
85
FastMutex::operator
delete
(
void
*
p
) {
86
Gecode::heap
.
rfree
(
p
);
87
}
88
89
#endif
90
91
/*
92
* Locks
93
*/
94
forceinline
95
Lock::Lock
(
Mutex
& m0) : m(m0) {
96
m.
acquire
();
97
}
98
forceinline
99
Lock::~Lock
(
void
) {
100
m.
release
();
101
}
102
103
104
/*
105
* Threads
106
*/
107
inline
void
108
Thread::Run::run
(
Runnable
* r0) {
109
m
.
acquire
();
110
r
= r0;
111
m
.
release
();
112
e
.
signal
();
113
}
114
inline
void
115
Thread::run
(
Runnable
*
r
) {
116
m
()->
acquire
();
117
if
(
idle
!= NULL) {
118
Run
*
i
=
idle
;
119
idle
=
idle
->
n
;
120
m
()->
release
();
121
i
->run(
r
);
122
}
else
{
123
m
()->
release
();
124
(void)
new
Run
(
r
);
125
}
126
}
127
forceinline
void
128
Thread::Run::operator
delete
(
void
*
p
) {
129
heap
.
rfree
(
p
);
130
}
131
forceinline
void
*
132
Thread::Run::operator
new
(
size_t
s) {
133
return
heap
.
ralloc
(s);
134
}
135
136
}}
137
138
// STATISTICS: support-any
Gecode::Support::Runnable::todelete
bool todelete(void) const
Return whether to be deleted upon termination.
Definition:
thread.hpp:47
Gecode::Support::Thread::m
static Mutex * m(void)
Mutex for synchronization.
Definition:
thread.cpp:42
Gecode::Support::Thread::Run::n
Run * n
Next idle thread.
Definition:
thread.hpp:302
Gecode::Support::Mutex::acquire
void acquire(void)
Acquire the mutex and possibly block.
Definition:
none.hpp:42
Gecode::Heap::ralloc
void * ralloc(size_t s)
Allocate s bytes from heap.
Definition:
heap.hpp:357
Gecode::Support::Lock::~Lock
~Lock(void)
Leave lock.
Definition:
thread.hpp:99
Gecode::Support::Thread::Run::e
Event e
Event to wait for next runnable object to execute.
Definition:
thread.hpp:306
Gecode::Support::Thread::Run
A real thread.
Definition:
thread.hpp:299
Gecode
Gecode toplevel namespace
Gecode::Support::Thread::run
static void run(Runnable *r)
Construct a new thread and run r.
Definition:
thread.hpp:115
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Gecode::Support::Runnable::Runnable
Runnable(bool d=true)
Initialize, d defines whether object is deleted when terminated.
Definition:
thread.hpp:40
Gecode::Support::Thread::Run::m
Mutex m
Mutex for synchronization.
Definition:
thread.hpp:308
Gecode::heap
Heap heap
The single global heap.
Definition:
heap.cpp:44
Gecode::Support::Event::signal
void signal(void)
Signal the event.
Definition:
none.hpp:59
Gecode::Support::Thread::idle
static Run * idle
Idle runners.
Definition:
thread.hpp:323
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
Gecode::Support::Thread::Run::r
Runnable * r
Runnable object to execute.
Definition:
thread.hpp:304
Gecode::Support::Lock::Lock
Lock(Mutex &m0)
Enter lock.
Definition:
thread.hpp:95
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Support::Runnable
An interface for objects that can be run by a thread.
Definition:
thread.hpp:264
Gecode::Support::Mutex::release
void release(void)
Release the mutex.
Definition:
none.hpp:48
Gecode::Support::Mutex
A mutex for mutual exclausion among several threads.
Definition:
thread.hpp:96
Gecode::Heap::rfree
void rfree(void *p)
Free memory block starting at p.
Definition:
heap.hpp:371
Gecode::Support::Thread::Run::run
void run(Runnable *r)
Run a runnable object.
Definition:
thread.hpp:108
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:232