| 197 | } |
| 198 | |
| 199 | forceinline HeapChunk* |
| 200 | SharedMemory::alloc(size_t s, size_t l) { |
| 201 | // To protect from exceptions from heap.ralloc() |
| 202 | Support::Lock guard(m()); |
| 203 | while ((heap.hc != nullptr) && (heap.hc->size < l)) { |
| 204 | heap.n_hc--; |
| 205 | HeapChunk* hc = heap.hc; |
| 206 | heap.hc = static_cast<HeapChunk*>(hc->next); |
| 207 | Gecode::heap.rfree(hc); |
| 208 | } |
| 209 | HeapChunk* hc; |
| 210 | if (heap.hc == nullptr) { |
| 211 | assert(heap.n_hc == 0); |
| 212 | hc = static_cast<HeapChunk*>(Gecode::heap.ralloc(s)); |
| 213 | hc->size = s; |
| 214 | } else { |
| 215 | heap.n_hc--; |
| 216 | hc = heap.hc; |
| 217 | heap.hc = static_cast<HeapChunk*>(hc->next); |
| 218 | } |
| 219 | return hc; |
| 220 | } |
| 221 | forceinline void |
| 222 | SharedMemory::free(HeapChunk* hc) { |
| 223 | Support::Lock guard(m()); |
no test coverage detected