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