src/share/vm/utilities/taskqueue.hpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 548
ba764ed4b6f2
permissions
-rw-r--r--

Initial load

duke@435 1 /*
duke@435 2 * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 class TaskQueueSuper: public CHeapObj {
duke@435 26 protected:
duke@435 27 // The first free element after the last one pushed (mod _n).
duke@435 28 // (For now we'll assume only 32-bit CAS).
duke@435 29 volatile juint _bottom;
duke@435 30
duke@435 31 // log2 of the size of the queue.
duke@435 32 enum SomeProtectedConstants {
duke@435 33 Log_n = 14
duke@435 34 };
duke@435 35
duke@435 36 // Size of the queue.
duke@435 37 juint n() { return (1 << Log_n); }
duke@435 38 // For computing "x mod n" efficiently.
duke@435 39 juint n_mod_mask() { return n() - 1; }
duke@435 40
duke@435 41 struct Age {
duke@435 42 jushort _top;
duke@435 43 jushort _tag;
duke@435 44
duke@435 45 jushort tag() const { return _tag; }
duke@435 46 jushort top() const { return _top; }
duke@435 47
duke@435 48 Age() { _tag = 0; _top = 0; }
duke@435 49
duke@435 50 friend bool operator ==(const Age& a1, const Age& a2) {
duke@435 51 return a1.tag() == a2.tag() && a1.top() == a2.top();
duke@435 52 }
duke@435 53
duke@435 54 };
duke@435 55 Age _age;
duke@435 56 // These make sure we do single atomic reads and writes.
duke@435 57 Age get_age() {
duke@435 58 jint res = *(volatile jint*)(&_age);
duke@435 59 return *(Age*)(&res);
duke@435 60 }
duke@435 61 void set_age(Age a) {
duke@435 62 *(volatile jint*)(&_age) = *(int*)(&a);
duke@435 63 }
duke@435 64
duke@435 65 jushort get_top() {
duke@435 66 return get_age().top();
duke@435 67 }
duke@435 68
duke@435 69 // These both operate mod _n.
duke@435 70 juint increment_index(juint ind) {
duke@435 71 return (ind + 1) & n_mod_mask();
duke@435 72 }
duke@435 73 juint decrement_index(juint ind) {
duke@435 74 return (ind - 1) & n_mod_mask();
duke@435 75 }
duke@435 76
duke@435 77 // Returns a number in the range [0.._n). If the result is "n-1", it
duke@435 78 // should be interpreted as 0.
duke@435 79 juint dirty_size(juint bot, juint top) {
duke@435 80 return ((jint)bot - (jint)top) & n_mod_mask();
duke@435 81 }
duke@435 82
duke@435 83 // Returns the size corresponding to the given "bot" and "top".
duke@435 84 juint size(juint bot, juint top) {
duke@435 85 juint sz = dirty_size(bot, top);
duke@435 86 // Has the queue "wrapped", so that bottom is less than top?
duke@435 87 // There's a complicated special case here. A pair of threads could
duke@435 88 // perform pop_local and pop_global operations concurrently, starting
duke@435 89 // from a state in which _bottom == _top+1. The pop_local could
duke@435 90 // succeed in decrementing _bottom, and the pop_global in incrementing
duke@435 91 // _top (in which case the pop_global will be awarded the contested
duke@435 92 // queue element.) The resulting state must be interpreted as an empty
duke@435 93 // queue. (We only need to worry about one such event: only the queue
duke@435 94 // owner performs pop_local's, and several concurrent threads
duke@435 95 // attempting to perform the pop_global will all perform the same CAS,
duke@435 96 // and only one can succeed. Any stealing thread that reads after
duke@435 97 // either the increment or decrement will seen an empty queue, and will
duke@435 98 // not join the competitors. The "sz == -1 || sz == _n-1" state will
duke@435 99 // not be modified by concurrent queues, so the owner thread can reset
duke@435 100 // the state to _bottom == top so subsequent pushes will be performed
duke@435 101 // normally.
duke@435 102 if (sz == (n()-1)) return 0;
duke@435 103 else return sz;
duke@435 104 }
duke@435 105
duke@435 106 public:
duke@435 107 TaskQueueSuper() : _bottom(0), _age() {}
duke@435 108
duke@435 109 // Return "true" if the TaskQueue contains any tasks.
duke@435 110 bool peek();
duke@435 111
duke@435 112 // Return an estimate of the number of elements in the queue.
duke@435 113 // The "careful" version admits the possibility of pop_local/pop_global
duke@435 114 // races.
duke@435 115 juint size() {
duke@435 116 return size(_bottom, get_top());
duke@435 117 }
duke@435 118
duke@435 119 juint dirty_size() {
duke@435 120 return dirty_size(_bottom, get_top());
duke@435 121 }
duke@435 122
duke@435 123 // Maximum number of elements allowed in the queue. This is two less
duke@435 124 // than the actual queue size, for somewhat complicated reasons.
duke@435 125 juint max_elems() { return n() - 2; }
duke@435 126
duke@435 127 };
duke@435 128
duke@435 129 template<class E> class GenericTaskQueue: public TaskQueueSuper {
duke@435 130 private:
duke@435 131 // Slow paths for push, pop_local. (pop_global has no fast path.)
duke@435 132 bool push_slow(E t, juint dirty_n_elems);
duke@435 133 bool pop_local_slow(juint localBot, Age oldAge);
duke@435 134
duke@435 135 public:
duke@435 136 // Initializes the queue to empty.
duke@435 137 GenericTaskQueue();
duke@435 138
duke@435 139 void initialize();
duke@435 140
duke@435 141 // Push the task "t" on the queue. Returns "false" iff the queue is
duke@435 142 // full.
duke@435 143 inline bool push(E t);
duke@435 144
duke@435 145 // If succeeds in claiming a task (from the 'local' end, that is, the
duke@435 146 // most recently pushed task), returns "true" and sets "t" to that task.
duke@435 147 // Otherwise, the queue is empty and returns false.
duke@435 148 inline bool pop_local(E& t);
duke@435 149
duke@435 150 // If succeeds in claiming a task (from the 'global' end, that is, the
duke@435 151 // least recently pushed task), returns "true" and sets "t" to that task.
duke@435 152 // Otherwise, the queue is empty and returns false.
duke@435 153 bool pop_global(E& t);
duke@435 154
duke@435 155 // Delete any resource associated with the queue.
duke@435 156 ~GenericTaskQueue();
duke@435 157
duke@435 158 private:
duke@435 159 // Element array.
duke@435 160 volatile E* _elems;
duke@435 161 };
duke@435 162
duke@435 163 template<class E>
duke@435 164 GenericTaskQueue<E>::GenericTaskQueue():TaskQueueSuper() {
duke@435 165 assert(sizeof(Age) == sizeof(jint), "Depends on this.");
duke@435 166 }
duke@435 167
duke@435 168 template<class E>
duke@435 169 void GenericTaskQueue<E>::initialize() {
duke@435 170 _elems = NEW_C_HEAP_ARRAY(E, n());
duke@435 171 guarantee(_elems != NULL, "Allocation failed.");
duke@435 172 }
duke@435 173
duke@435 174 template<class E>
duke@435 175 bool GenericTaskQueue<E>::push_slow(E t, juint dirty_n_elems) {
duke@435 176 if (dirty_n_elems == n() - 1) {
duke@435 177 // Actually means 0, so do the push.
duke@435 178 juint localBot = _bottom;
duke@435 179 _elems[localBot] = t;
duke@435 180 _bottom = increment_index(localBot);
duke@435 181 return true;
duke@435 182 } else
duke@435 183 return false;
duke@435 184 }
duke@435 185
duke@435 186 template<class E>
duke@435 187 bool GenericTaskQueue<E>::
duke@435 188 pop_local_slow(juint localBot, Age oldAge) {
duke@435 189 // This queue was observed to contain exactly one element; either this
duke@435 190 // thread will claim it, or a competing "pop_global". In either case,
duke@435 191 // the queue will be logically empty afterwards. Create a new Age value
duke@435 192 // that represents the empty queue for the given value of "_bottom". (We
duke@435 193 // must also increment "tag" because of the case where "bottom == 1",
duke@435 194 // "top == 0". A pop_global could read the queue element in that case,
duke@435 195 // then have the owner thread do a pop followed by another push. Without
duke@435 196 // the incrementing of "tag", the pop_global's CAS could succeed,
duke@435 197 // allowing it to believe it has claimed the stale element.)
duke@435 198 Age newAge;
duke@435 199 newAge._top = localBot;
duke@435 200 newAge._tag = oldAge.tag() + 1;
duke@435 201 // Perhaps a competing pop_global has already incremented "top", in which
duke@435 202 // case it wins the element.
duke@435 203 if (localBot == oldAge.top()) {
duke@435 204 Age tempAge;
duke@435 205 // No competing pop_global has yet incremented "top"; we'll try to
duke@435 206 // install new_age, thus claiming the element.
duke@435 207 assert(sizeof(Age) == sizeof(jint) && sizeof(jint) == sizeof(juint),
duke@435 208 "Assumption about CAS unit.");
duke@435 209 *(jint*)&tempAge = Atomic::cmpxchg(*(jint*)&newAge, (volatile jint*)&_age, *(jint*)&oldAge);
duke@435 210 if (tempAge == oldAge) {
duke@435 211 // We win.
duke@435 212 assert(dirty_size(localBot, get_top()) != n() - 1,
duke@435 213 "Shouldn't be possible...");
duke@435 214 return true;
duke@435 215 }
duke@435 216 }
duke@435 217 // We fail; a completing pop_global gets the element. But the queue is
duke@435 218 // empty (and top is greater than bottom.) Fix this representation of
duke@435 219 // the empty queue to become the canonical one.
duke@435 220 set_age(newAge);
duke@435 221 assert(dirty_size(localBot, get_top()) != n() - 1,
duke@435 222 "Shouldn't be possible...");
duke@435 223 return false;
duke@435 224 }
duke@435 225
duke@435 226 template<class E>
duke@435 227 bool GenericTaskQueue<E>::pop_global(E& t) {
duke@435 228 Age newAge;
duke@435 229 Age oldAge = get_age();
duke@435 230 juint localBot = _bottom;
duke@435 231 juint n_elems = size(localBot, oldAge.top());
duke@435 232 if (n_elems == 0) {
duke@435 233 return false;
duke@435 234 }
duke@435 235 t = _elems[oldAge.top()];
duke@435 236 newAge = oldAge;
duke@435 237 newAge._top = increment_index(newAge.top());
duke@435 238 if ( newAge._top == 0 ) newAge._tag++;
duke@435 239 Age resAge;
duke@435 240 *(jint*)&resAge = Atomic::cmpxchg(*(jint*)&newAge, (volatile jint*)&_age, *(jint*)&oldAge);
duke@435 241 // Note that using "_bottom" here might fail, since a pop_local might
duke@435 242 // have decremented it.
duke@435 243 assert(dirty_size(localBot, newAge._top) != n() - 1,
duke@435 244 "Shouldn't be possible...");
duke@435 245 return (resAge == oldAge);
duke@435 246 }
duke@435 247
duke@435 248 template<class E>
duke@435 249 GenericTaskQueue<E>::~GenericTaskQueue() {
duke@435 250 FREE_C_HEAP_ARRAY(E, _elems);
duke@435 251 }
duke@435 252
duke@435 253 // Inherits the typedef of "Task" from above.
duke@435 254 class TaskQueueSetSuper: public CHeapObj {
duke@435 255 protected:
duke@435 256 static int randomParkAndMiller(int* seed0);
duke@435 257 public:
duke@435 258 // Returns "true" if some TaskQueue in the set contains a task.
duke@435 259 virtual bool peek() = 0;
duke@435 260 };
duke@435 261
duke@435 262 template<class E> class GenericTaskQueueSet: public TaskQueueSetSuper {
duke@435 263 private:
duke@435 264 int _n;
duke@435 265 GenericTaskQueue<E>** _queues;
duke@435 266
duke@435 267 public:
duke@435 268 GenericTaskQueueSet(int n) : _n(n) {
duke@435 269 typedef GenericTaskQueue<E>* GenericTaskQueuePtr;
duke@435 270 _queues = NEW_C_HEAP_ARRAY(GenericTaskQueuePtr, n);
duke@435 271 guarantee(_queues != NULL, "Allocation failure.");
duke@435 272 for (int i = 0; i < n; i++) {
duke@435 273 _queues[i] = NULL;
duke@435 274 }
duke@435 275 }
duke@435 276
duke@435 277 bool steal_1_random(int queue_num, int* seed, E& t);
duke@435 278 bool steal_best_of_2(int queue_num, int* seed, E& t);
duke@435 279 bool steal_best_of_all(int queue_num, int* seed, E& t);
duke@435 280
duke@435 281 void register_queue(int i, GenericTaskQueue<E>* q);
duke@435 282
duke@435 283 GenericTaskQueue<E>* queue(int n);
duke@435 284
duke@435 285 // The thread with queue number "queue_num" (and whose random number seed
duke@435 286 // is at "seed") is trying to steal a task from some other queue. (It
duke@435 287 // may try several queues, according to some configuration parameter.)
duke@435 288 // If some steal succeeds, returns "true" and sets "t" the stolen task,
duke@435 289 // otherwise returns false.
duke@435 290 bool steal(int queue_num, int* seed, E& t);
duke@435 291
duke@435 292 bool peek();
duke@435 293 };
duke@435 294
duke@435 295 template<class E>
duke@435 296 void GenericTaskQueueSet<E>::register_queue(int i, GenericTaskQueue<E>* q) {
duke@435 297 assert(0 <= i && i < _n, "index out of range.");
duke@435 298 _queues[i] = q;
duke@435 299 }
duke@435 300
duke@435 301 template<class E>
duke@435 302 GenericTaskQueue<E>* GenericTaskQueueSet<E>::queue(int i) {
duke@435 303 return _queues[i];
duke@435 304 }
duke@435 305
duke@435 306 template<class E>
duke@435 307 bool GenericTaskQueueSet<E>::steal(int queue_num, int* seed, E& t) {
duke@435 308 for (int i = 0; i < 2 * _n; i++)
duke@435 309 if (steal_best_of_2(queue_num, seed, t))
duke@435 310 return true;
duke@435 311 return false;
duke@435 312 }
duke@435 313
duke@435 314 template<class E>
duke@435 315 bool GenericTaskQueueSet<E>::steal_best_of_all(int queue_num, int* seed, E& t) {
duke@435 316 if (_n > 2) {
duke@435 317 int best_k;
duke@435 318 jint best_sz = 0;
duke@435 319 for (int k = 0; k < _n; k++) {
duke@435 320 if (k == queue_num) continue;
duke@435 321 jint sz = _queues[k]->size();
duke@435 322 if (sz > best_sz) {
duke@435 323 best_sz = sz;
duke@435 324 best_k = k;
duke@435 325 }
duke@435 326 }
duke@435 327 return best_sz > 0 && _queues[best_k]->pop_global(t);
duke@435 328 } else if (_n == 2) {
duke@435 329 // Just try the other one.
duke@435 330 int k = (queue_num + 1) % 2;
duke@435 331 return _queues[k]->pop_global(t);
duke@435 332 } else {
duke@435 333 assert(_n == 1, "can't be zero.");
duke@435 334 return false;
duke@435 335 }
duke@435 336 }
duke@435 337
duke@435 338 template<class E>
duke@435 339 bool GenericTaskQueueSet<E>::steal_1_random(int queue_num, int* seed, E& t) {
duke@435 340 if (_n > 2) {
duke@435 341 int k = queue_num;
duke@435 342 while (k == queue_num) k = randomParkAndMiller(seed) % _n;
duke@435 343 return _queues[2]->pop_global(t);
duke@435 344 } else if (_n == 2) {
duke@435 345 // Just try the other one.
duke@435 346 int k = (queue_num + 1) % 2;
duke@435 347 return _queues[k]->pop_global(t);
duke@435 348 } else {
duke@435 349 assert(_n == 1, "can't be zero.");
duke@435 350 return false;
duke@435 351 }
duke@435 352 }
duke@435 353
duke@435 354 template<class E>
duke@435 355 bool GenericTaskQueueSet<E>::steal_best_of_2(int queue_num, int* seed, E& t) {
duke@435 356 if (_n > 2) {
duke@435 357 int k1 = queue_num;
duke@435 358 while (k1 == queue_num) k1 = randomParkAndMiller(seed) % _n;
duke@435 359 int k2 = queue_num;
duke@435 360 while (k2 == queue_num || k2 == k1) k2 = randomParkAndMiller(seed) % _n;
duke@435 361 // Sample both and try the larger.
duke@435 362 juint sz1 = _queues[k1]->size();
duke@435 363 juint sz2 = _queues[k2]->size();
duke@435 364 if (sz2 > sz1) return _queues[k2]->pop_global(t);
duke@435 365 else return _queues[k1]->pop_global(t);
duke@435 366 } else if (_n == 2) {
duke@435 367 // Just try the other one.
duke@435 368 int k = (queue_num + 1) % 2;
duke@435 369 return _queues[k]->pop_global(t);
duke@435 370 } else {
duke@435 371 assert(_n == 1, "can't be zero.");
duke@435 372 return false;
duke@435 373 }
duke@435 374 }
duke@435 375
duke@435 376 template<class E>
duke@435 377 bool GenericTaskQueueSet<E>::peek() {
duke@435 378 // Try all the queues.
duke@435 379 for (int j = 0; j < _n; j++) {
duke@435 380 if (_queues[j]->peek())
duke@435 381 return true;
duke@435 382 }
duke@435 383 return false;
duke@435 384 }
duke@435 385
duke@435 386 // A class to aid in the termination of a set of parallel tasks using
duke@435 387 // TaskQueueSet's for work stealing.
duke@435 388
duke@435 389 class ParallelTaskTerminator: public StackObj {
duke@435 390 private:
duke@435 391 int _n_threads;
duke@435 392 TaskQueueSetSuper* _queue_set;
duke@435 393 jint _offered_termination;
duke@435 394
duke@435 395 bool peek_in_queue_set();
duke@435 396 protected:
duke@435 397 virtual void yield();
duke@435 398 void sleep(uint millis);
duke@435 399
duke@435 400 public:
duke@435 401
duke@435 402 // "n_threads" is the number of threads to be terminated. "queue_set" is a
duke@435 403 // queue sets of work queues of other threads.
duke@435 404 ParallelTaskTerminator(int n_threads, TaskQueueSetSuper* queue_set);
duke@435 405
duke@435 406 // The current thread has no work, and is ready to terminate if everyone
duke@435 407 // else is. If returns "true", all threads are terminated. If returns
duke@435 408 // "false", available work has been observed in one of the task queues,
duke@435 409 // so the global task is not complete.
duke@435 410 bool offer_termination();
duke@435 411
duke@435 412 // Reset the terminator, so that it may be reused again.
duke@435 413 // The caller is responsible for ensuring that this is done
duke@435 414 // in an MT-safe manner, once the previous round of use of
duke@435 415 // the terminator is finished.
duke@435 416 void reset_for_reuse();
duke@435 417
duke@435 418 };
duke@435 419
duke@435 420 #define SIMPLE_STACK 0
duke@435 421
duke@435 422 template<class E> inline bool GenericTaskQueue<E>::push(E t) {
duke@435 423 #if SIMPLE_STACK
duke@435 424 juint localBot = _bottom;
duke@435 425 if (_bottom < max_elems()) {
duke@435 426 _elems[localBot] = t;
duke@435 427 _bottom = localBot + 1;
duke@435 428 return true;
duke@435 429 } else {
duke@435 430 return false;
duke@435 431 }
duke@435 432 #else
duke@435 433 juint localBot = _bottom;
duke@435 434 assert((localBot >= 0) && (localBot < n()), "_bottom out of range.");
duke@435 435 jushort top = get_top();
duke@435 436 juint dirty_n_elems = dirty_size(localBot, top);
duke@435 437 assert((dirty_n_elems >= 0) && (dirty_n_elems < n()),
duke@435 438 "n_elems out of range.");
duke@435 439 if (dirty_n_elems < max_elems()) {
duke@435 440 _elems[localBot] = t;
duke@435 441 _bottom = increment_index(localBot);
duke@435 442 return true;
duke@435 443 } else {
duke@435 444 return push_slow(t, dirty_n_elems);
duke@435 445 }
duke@435 446 #endif
duke@435 447 }
duke@435 448
duke@435 449 template<class E> inline bool GenericTaskQueue<E>::pop_local(E& t) {
duke@435 450 #if SIMPLE_STACK
duke@435 451 juint localBot = _bottom;
duke@435 452 assert(localBot > 0, "precondition.");
duke@435 453 localBot--;
duke@435 454 t = _elems[localBot];
duke@435 455 _bottom = localBot;
duke@435 456 return true;
duke@435 457 #else
duke@435 458 juint localBot = _bottom;
duke@435 459 // This value cannot be n-1. That can only occur as a result of
duke@435 460 // the assignment to bottom in this method. If it does, this method
duke@435 461 // resets the size( to 0 before the next call (which is sequential,
duke@435 462 // since this is pop_local.)
duke@435 463 juint dirty_n_elems = dirty_size(localBot, get_top());
duke@435 464 assert(dirty_n_elems != n() - 1, "Shouldn't be possible...");
duke@435 465 if (dirty_n_elems == 0) return false;
duke@435 466 localBot = decrement_index(localBot);
duke@435 467 _bottom = localBot;
duke@435 468 // This is necessary to prevent any read below from being reordered
duke@435 469 // before the store just above.
duke@435 470 OrderAccess::fence();
duke@435 471 t = _elems[localBot];
duke@435 472 // This is a second read of "age"; the "size()" above is the first.
duke@435 473 // If there's still at least one element in the queue, based on the
duke@435 474 // "_bottom" and "age" we've read, then there can be no interference with
duke@435 475 // a "pop_global" operation, and we're done.
duke@435 476 juint tp = get_top();
duke@435 477 if (size(localBot, tp) > 0) {
duke@435 478 assert(dirty_size(localBot, tp) != n() - 1,
duke@435 479 "Shouldn't be possible...");
duke@435 480 return true;
duke@435 481 } else {
duke@435 482 // Otherwise, the queue contained exactly one element; we take the slow
duke@435 483 // path.
duke@435 484 return pop_local_slow(localBot, get_age());
duke@435 485 }
duke@435 486 #endif
duke@435 487 }
duke@435 488
duke@435 489 typedef oop Task;
duke@435 490 typedef GenericTaskQueue<Task> OopTaskQueue;
duke@435 491 typedef GenericTaskQueueSet<Task> OopTaskQueueSet;
duke@435 492
duke@435 493 typedef oop* StarTask;
duke@435 494 typedef GenericTaskQueue<StarTask> OopStarTaskQueue;
duke@435 495 typedef GenericTaskQueueSet<StarTask> OopStarTaskQueueSet;
duke@435 496
duke@435 497 typedef size_t ChunkTask; // index for chunk
duke@435 498 typedef GenericTaskQueue<ChunkTask> ChunkTaskQueue;
duke@435 499 typedef GenericTaskQueueSet<ChunkTask> ChunkTaskQueueSet;
duke@435 500
duke@435 501 class ChunkTaskQueueWithOverflow: public CHeapObj {
duke@435 502 protected:
duke@435 503 ChunkTaskQueue _chunk_queue;
duke@435 504 GrowableArray<ChunkTask>* _overflow_stack;
duke@435 505
duke@435 506 public:
duke@435 507 ChunkTaskQueueWithOverflow() : _overflow_stack(NULL) {}
duke@435 508 // Initialize both stealable queue and overflow
duke@435 509 void initialize();
duke@435 510 // Save first to stealable queue and then to overflow
duke@435 511 void save(ChunkTask t);
duke@435 512 // Retrieve first from overflow and then from stealable queue
duke@435 513 bool retrieve(ChunkTask& chunk_index);
duke@435 514 // Retrieve from stealable queue
duke@435 515 bool retrieve_from_stealable_queue(ChunkTask& chunk_index);
duke@435 516 // Retrieve from overflow
duke@435 517 bool retrieve_from_overflow(ChunkTask& chunk_index);
duke@435 518 bool is_empty();
duke@435 519 bool stealable_is_empty();
duke@435 520 bool overflow_is_empty();
duke@435 521 juint stealable_size() { return _chunk_queue.size(); }
duke@435 522 ChunkTaskQueue* task_queue() { return &_chunk_queue; }
duke@435 523 };
duke@435 524
duke@435 525 #define USE_ChunkTaskQueueWithOverflow

mercurial