this repo has no description
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 34namespace 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 != nullptr) { 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