292 void internal_shrink_range(Thread* thread, size_t start, size_t stop);
293 bool internal_shrink(Thread* thread, size_t size_limit_log2);
294
295 // Methods for growing.
296 bool unzip_bucket(Thread* thread, InternalTable* old_table,
297 InternalTable* new_table, size_t even_index,
298 size_t odd_index);
299 bool internal_grow_prolog(Thread* thread, size_t log2_size);
300 void internal_grow_epilog(Thread* thread);
301 void internal_grow_range(Thread* thread, size_t start, size_t stop);
302 bool internal_grow(Thread* thread, size_t log2_size);
303
304 // Get a value.
305 template <typename LOOKUP_FUNC>
306 VALUE* internal_get(Thread* thread, LOOKUP_FUNC& lookup_f,
307 bool* grow_hint = NULL);
308
309 // Insert which handles a number of cases.
310 template <typename LOOKUP_FUNC, typename VALUE_FUNC, typename CALLBACK_FUNC>
311 bool internal_insert(Thread* thread, LOOKUP_FUNC& lookup_f, VALUE_FUNC& value_f,
312 CALLBACK_FUNC& callback, bool* grow_hint = NULL);
313
314 // Returns true if an item matching LOOKUP_FUNC is removed.
315 // Calls DELETE_FUNC before destroying the node.
316 template <typename LOOKUP_FUNC, typename DELETE_FUNC>
317 bool internal_remove(Thread* thread, LOOKUP_FUNC& lookup_f,
318 DELETE_FUNC& delete_f);
319
320 // Visits nodes with FUNC.
321 template <typename FUNC>
322 static bool visit_nodes(Bucket* bucket, FUNC& visitor_f);
323
324 // During shrink/grow we cannot guarantee that we only visit nodes once, with
325 // current algorithm. To keep it simple caller will have locked
326 // _resize_lock.
327 template <typename FUNC>
328 void do_scan_locked(Thread* thread, FUNC& scan_f);
329
330 // Check for dead items in a bucket.
331 template <typename EVALUATE_FUNC>
332 size_t delete_check_nodes(Bucket* bucket, EVALUATE_FUNC& eval_f,
379 bool is_max_size_reached() { return _size_limit_reached; }
380
381 // This means no paused bucket resize operation is going to resume
382 // on this table.
383 bool is_safepoint_safe() { return _resize_lock_owner == NULL; }
384
385 // Re-size operations.
386 bool shrink(Thread* thread, size_t size_limit_log2 = 0);
387 bool grow(Thread* thread, size_t size_limit_log2 = 0);
388
389 // All callbacks for get are under critical sections. Other callbacks may be
390 // under critical section or may have locked parts of table. Calling any
391 // methods on the table during a callback is not supported.Only MultiGetHandle
392 // supports multiple gets.
393
394 // LOOKUP_FUNC is matching methods, VALUE_FUNC creates value to be inserted
395 // and CALLBACK_FUNC is called with new or old value. Returns true if the
396 // value already exists.
397 template <typename LOOKUP_FUNC, typename VALUE_FUNC, typename CALLBACK_FUNC>
398 bool get_insert_lazy(Thread* thread, LOOKUP_FUNC& lookup_f, VALUE_FUNC& val_f,
399 CALLBACK_FUNC& callback_f, bool* grow_hint = NULL) {
400 return !internal_insert(thread, lookup_f, val_f, callback_f, grow_hint);
401 }
402
403 // Same without CALLBACK_FUNC.
404 template <typename LOOKUP_FUNC, typename VALUE_FUNC>
405 bool get_insert_lazy(Thread* thread, LOOKUP_FUNC& lookup_f, VALUE_FUNC& val_f,
406 bool* grow_hint = NULL) {
407 return get_insert_lazy(thread, lookup_f, val_f, noOp, grow_hint);
408 }
409
410 // Same without VALUE_FUNC.
411 template <typename LOOKUP_FUNC, typename CALLBACK_FUNC>
412 bool get_insert(Thread* thread, LOOKUP_FUNC& lookup_f, const VALUE& value,
413 CALLBACK_FUNC& callback_f, bool* grow_hint = NULL) {
414 LazyValueRetrieve vp(value);
415 return get_insert_lazy(thread, lookup_f, vp, callback_f, grow_hint);
416 }
417
418 // Same without CALLBACK_FUNC and VALUE_FUNC.
419 template <typename LOOKUP_FUNC>
420 bool get_insert(Thread* thread, LOOKUP_FUNC& lookup_f, const VALUE& value,
421 bool* grow_hint = NULL) {
422 return get_insert(thread, lookup_f, value, noOp, grow_hint);
423 }
424
425 // Get methods return true on found item with LOOKUP_FUNC and FOUND_FUNC is
426 // called.
427 template <typename LOOKUP_FUNC, typename FOUND_FUNC>
428 bool get(Thread* thread, LOOKUP_FUNC& lookup_f, FOUND_FUNC& foundf,
429 bool* grow_hint = NULL);
430
431 // Return a copy of an item found with LOOKUP_FUNC.
432 template <typename LOOKUP_FUNC>
433 VALUE get_copy(Thread* thread, LOOKUP_FUNC& lookup_f, bool* grow_hint = NULL);
434
435 // Returns true true if the item was inserted, duplicates are found with
436 // LOOKUP_FUNC.
437 template <typename LOOKUP_FUNC>
438 bool insert(Thread* thread, LOOKUP_FUNC& lookup_f, const VALUE& value,
439 bool* grow_hint = NULL) {
440 LazyValueRetrieve vp(value);
441 return internal_insert(thread, lookup_f, vp, noOp, grow_hint);
442 }
443
444 // This does a fast unsafe insert and can thus only be used when there is no
445 // risk for a duplicates and no other threads uses this table.
446 bool unsafe_insert(const VALUE& value);
447
448 // Returns true if items was deleted matching LOOKUP_FUNC and
449 // prior to destruction DELETE_FUNC is called.
450 template <typename LOOKUP_FUNC, typename DELETE_FUNC>
451 bool remove(Thread* thread, LOOKUP_FUNC& lookup_f, DELETE_FUNC& del_f) {
452 return internal_remove(thread, lookup_f, del_f);
453 }
454
455 // Same without DELETE_FUNC.
456 template <typename LOOKUP_FUNC>
457 bool remove(Thread* thread, LOOKUP_FUNC& lookup_f) {
458 return internal_remove(thread, lookup_f, noOp);
459 }
460
461 // Visit all items with SCAN_FUNC if no concurrent resize. Takes the resize
|
292 void internal_shrink_range(Thread* thread, size_t start, size_t stop);
293 bool internal_shrink(Thread* thread, size_t size_limit_log2);
294
295 // Methods for growing.
296 bool unzip_bucket(Thread* thread, InternalTable* old_table,
297 InternalTable* new_table, size_t even_index,
298 size_t odd_index);
299 bool internal_grow_prolog(Thread* thread, size_t log2_size);
300 void internal_grow_epilog(Thread* thread);
301 void internal_grow_range(Thread* thread, size_t start, size_t stop);
302 bool internal_grow(Thread* thread, size_t log2_size);
303
304 // Get a value.
305 template <typename LOOKUP_FUNC>
306 VALUE* internal_get(Thread* thread, LOOKUP_FUNC& lookup_f,
307 bool* grow_hint = NULL);
308
309 // Insert which handles a number of cases.
310 template <typename LOOKUP_FUNC, typename VALUE_FUNC, typename CALLBACK_FUNC>
311 bool internal_insert(Thread* thread, LOOKUP_FUNC& lookup_f, VALUE_FUNC& value_f,
312 CALLBACK_FUNC& callback, bool* grow_hint = NULL, bool* clean_hint = NULL);
313
314 // Returns true if an item matching LOOKUP_FUNC is removed.
315 // Calls DELETE_FUNC before destroying the node.
316 template <typename LOOKUP_FUNC, typename DELETE_FUNC>
317 bool internal_remove(Thread* thread, LOOKUP_FUNC& lookup_f,
318 DELETE_FUNC& delete_f);
319
320 // Visits nodes with FUNC.
321 template <typename FUNC>
322 static bool visit_nodes(Bucket* bucket, FUNC& visitor_f);
323
324 // During shrink/grow we cannot guarantee that we only visit nodes once, with
325 // current algorithm. To keep it simple caller will have locked
326 // _resize_lock.
327 template <typename FUNC>
328 void do_scan_locked(Thread* thread, FUNC& scan_f);
329
330 // Check for dead items in a bucket.
331 template <typename EVALUATE_FUNC>
332 size_t delete_check_nodes(Bucket* bucket, EVALUATE_FUNC& eval_f,
379 bool is_max_size_reached() { return _size_limit_reached; }
380
381 // This means no paused bucket resize operation is going to resume
382 // on this table.
383 bool is_safepoint_safe() { return _resize_lock_owner == NULL; }
384
385 // Re-size operations.
386 bool shrink(Thread* thread, size_t size_limit_log2 = 0);
387 bool grow(Thread* thread, size_t size_limit_log2 = 0);
388
389 // All callbacks for get are under critical sections. Other callbacks may be
390 // under critical section or may have locked parts of table. Calling any
391 // methods on the table during a callback is not supported.Only MultiGetHandle
392 // supports multiple gets.
393
394 // LOOKUP_FUNC is matching methods, VALUE_FUNC creates value to be inserted
395 // and CALLBACK_FUNC is called with new or old value. Returns true if the
396 // value already exists.
397 template <typename LOOKUP_FUNC, typename VALUE_FUNC, typename CALLBACK_FUNC>
398 bool get_insert_lazy(Thread* thread, LOOKUP_FUNC& lookup_f, VALUE_FUNC& val_f,
399 CALLBACK_FUNC& callback_f, bool* grow_hint = NULL, bool* clean_hint = NULL) {
400 return !internal_insert(thread, lookup_f, val_f, callback_f, grow_hint, clean_hint);
401 }
402
403 // Same without CALLBACK_FUNC.
404 template <typename LOOKUP_FUNC, typename VALUE_FUNC>
405 bool get_insert_lazy(Thread* thread, LOOKUP_FUNC& lookup_f, VALUE_FUNC& val_f,
406 bool* grow_hint = NULL) {
407 return get_insert_lazy(thread, lookup_f, val_f, noOp, grow_hint);
408 }
409
410 // Same without VALUE_FUNC.
411 template <typename LOOKUP_FUNC, typename CALLBACK_FUNC>
412 bool get_insert(Thread* thread, LOOKUP_FUNC& lookup_f, const VALUE& value,
413 CALLBACK_FUNC& callback_f, bool* grow_hint = NULL) {
414 LazyValueRetrieve vp(value);
415 return get_insert_lazy(thread, lookup_f, vp, callback_f, grow_hint);
416 }
417
418 // Same without CALLBACK_FUNC and VALUE_FUNC.
419 template <typename LOOKUP_FUNC>
420 bool get_insert(Thread* thread, LOOKUP_FUNC& lookup_f, const VALUE& value,
421 bool* grow_hint = NULL) {
422 return get_insert(thread, lookup_f, value, noOp, grow_hint);
423 }
424
425 // Get methods return true on found item with LOOKUP_FUNC and FOUND_FUNC is
426 // called.
427 template <typename LOOKUP_FUNC, typename FOUND_FUNC>
428 bool get(Thread* thread, LOOKUP_FUNC& lookup_f, FOUND_FUNC& foundf,
429 bool* grow_hint = NULL);
430
431 // Return a copy of an item found with LOOKUP_FUNC.
432 template <typename LOOKUP_FUNC>
433 VALUE get_copy(Thread* thread, LOOKUP_FUNC& lookup_f, bool* grow_hint = NULL);
434
435 // Returns true true if the item was inserted, duplicates are found with
436 // LOOKUP_FUNC.
437 template <typename LOOKUP_FUNC>
438 bool insert(Thread* thread, LOOKUP_FUNC& lookup_f, const VALUE& value,
439 bool* grow_hint = NULL, bool* clean_hint = NULL) {
440 LazyValueRetrieve vp(value);
441 return internal_insert(thread, lookup_f, vp, noOp, grow_hint, clean_hint);
442 }
443
444 // This does a fast unsafe insert and can thus only be used when there is no
445 // risk for a duplicates and no other threads uses this table.
446 bool unsafe_insert(const VALUE& value);
447
448 // Returns true if items was deleted matching LOOKUP_FUNC and
449 // prior to destruction DELETE_FUNC is called.
450 template <typename LOOKUP_FUNC, typename DELETE_FUNC>
451 bool remove(Thread* thread, LOOKUP_FUNC& lookup_f, DELETE_FUNC& del_f) {
452 return internal_remove(thread, lookup_f, del_f);
453 }
454
455 // Same without DELETE_FUNC.
456 template <typename LOOKUP_FUNC>
457 bool remove(Thread* thread, LOOKUP_FUNC& lookup_f) {
458 return internal_remove(thread, lookup_f, noOp);
459 }
460
461 // Visit all items with SCAN_FUNC if no concurrent resize. Takes the resize
|