Commit 06abeada authored by Felix Handte's avatar Felix Handte Committed by Facebook GitHub Bot

Support ConcurrentHashMap When Exceptions are Disabled

Summary: Refactory `throw` -> `throw_exception`;

Reviewed By: yfeldblum

Differential Revision: D21773804

fbshipit-source-id: fd59f1579a143db385e05c5e3442fedee243d25f
parent 7a473ac6
...@@ -391,7 +391,7 @@ class ConcurrentHashMap { ...@@ -391,7 +391,7 @@ class ConcurrentHashMap {
const ValueType at(const KeyType& key) const { const ValueType at(const KeyType& key) const {
auto item = find(key); auto item = find(key);
if (item == cend()) { if (item == cend()) {
throw std::out_of_range("at(): value out of range"); throw_exception<std::out_of_range>("at(): value out of range");
} }
return item->second; return item->second;
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#pragma once #pragma once
#include <folly/container/detail/F14Mask.h> #include <folly/container/detail/F14Mask.h>
#include <folly/lang/Exception.h>
#include <folly/lang/Launder.h> #include <folly/lang/Launder.h>
#include <folly/synchronization/Hazptr.h> #include <folly/synchronization/Hazptr.h>
#include <algorithm> #include <algorithm>
...@@ -640,7 +641,7 @@ class alignas(64) BucketTable { ...@@ -640,7 +641,7 @@ class alignas(64) BucketTable {
if (size() >= load_factor_nodes_ && type == InsertType::DOES_NOT_EXIST) { if (size() >= load_factor_nodes_ && type == InsertType::DOES_NOT_EXIST) {
if (max_size_ && size() << 1 > max_size_) { if (max_size_ && size() << 1 > max_size_) {
// Would exceed max size. // Would exceed max size.
throw std::bad_alloc(); throw_exception<std::bad_alloc>();
} }
rehash(bcount << 1, cohort); rehash(bcount << 1, cohort);
buckets = buckets_.load(std::memory_order_relaxed); buckets = buckets_.load(std::memory_order_relaxed);
...@@ -697,7 +698,7 @@ class alignas(64) BucketTable { ...@@ -697,7 +698,7 @@ class alignas(64) BucketTable {
if (size() >= load_factor_nodes_ && type == InsertType::ANY) { if (size() >= load_factor_nodes_ && type == InsertType::ANY) {
if (max_size_ && size() << 1 > max_size_) { if (max_size_ && size() << 1 > max_size_) {
// Would exceed max size. // Would exceed max size.
throw std::bad_alloc(); throw_exception<std::bad_alloc>();
} }
rehash(bcount << 1, cohort); rehash(bcount << 1, cohort);
...@@ -1390,7 +1391,7 @@ class alignas(64) SIMDTable { ...@@ -1390,7 +1391,7 @@ class alignas(64) SIMDTable {
void max_load_factor(float factor) { void max_load_factor(float factor) {
DCHECK(factor > 0.0); DCHECK(factor > 0.0);
if (factor > 1.0) { if (factor > 1.0) {
throw std::invalid_argument("load factor must be <= 1.0"); throw_exception<std::invalid_argument>("load factor must be <= 1.0");
} }
std::lock_guard<Mutex> g(m_); std::lock_guard<Mutex> g(m_);
load_factor_ = factor; load_factor_ = factor;
...@@ -1474,7 +1475,7 @@ class alignas(64) SIMDTable { ...@@ -1474,7 +1475,7 @@ class alignas(64) SIMDTable {
if (size() >= grow_threshold_ && type == InsertType::DOES_NOT_EXIST) { if (size() >= grow_threshold_ && type == InsertType::DOES_NOT_EXIST) {
if (max_size_ && size() << 1 > max_size_) { if (max_size_ && size() << 1 > max_size_) {
// Would exceed max size. // Would exceed max size.
throw std::bad_alloc(); throw_exception<std::bad_alloc>();
} }
rehash_internal(ccount << 1, cohort); rehash_internal(ccount << 1, cohort);
ccount = chunk_count_.load(std::memory_order_relaxed); ccount = chunk_count_.load(std::memory_order_relaxed);
...@@ -1503,7 +1504,7 @@ class alignas(64) SIMDTable { ...@@ -1503,7 +1504,7 @@ class alignas(64) SIMDTable {
if (size() >= grow_threshold_ && type == InsertType::ANY) { if (size() >= grow_threshold_ && type == InsertType::ANY) {
if (max_size_ && size() << 1 > max_size_) { if (max_size_ && size() << 1 > max_size_) {
// Would exceed max size. // Would exceed max size.
throw std::bad_alloc(); throw_exception<std::bad_alloc>();
} }
rehash_internal(ccount << 1, cohort); rehash_internal(ccount << 1, cohort);
ccount = chunk_count_.load(std::memory_order_relaxed); ccount = chunk_count_.load(std::memory_order_relaxed);
......
...@@ -369,7 +369,7 @@ ElementWrapper* StaticMetaBase::reallocate( ...@@ -369,7 +369,7 @@ ElementWrapper* StaticMetaBase::reallocate(
assert(newByteSize / sizeof(ElementWrapper) >= newCapacity); assert(newByteSize / sizeof(ElementWrapper) >= newCapacity);
newCapacity = newByteSize / sizeof(ElementWrapper); newCapacity = newByteSize / sizeof(ElementWrapper);
} else { } else {
throw std::bad_alloc(); throw_exception<std::bad_alloc>();
} }
} else { // no jemalloc } else { // no jemalloc
// calloc() is simpler than malloc() followed by memset(), and // calloc() is simpler than malloc() followed by memset(), and
...@@ -378,7 +378,7 @@ ElementWrapper* StaticMetaBase::reallocate( ...@@ -378,7 +378,7 @@ ElementWrapper* StaticMetaBase::reallocate(
reallocated = static_cast<ElementWrapper*>( reallocated = static_cast<ElementWrapper*>(
calloc(newCapacity, sizeof(ElementWrapper))); calloc(newCapacity, sizeof(ElementWrapper)));
if (!reallocated) { if (!reallocated) {
throw std::bad_alloc(); throw_exception<std::bad_alloc>();
} }
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <folly/SharedMutex.h> #include <folly/SharedMutex.h>
#include <folly/container/Foreach.h> #include <folly/container/Foreach.h>
#include <folly/detail/AtFork.h> #include <folly/detail/AtFork.h>
#include <folly/lang/Exception.h>
#include <folly/memory/Malloc.h> #include <folly/memory/Malloc.h>
#include <folly/portability/PThread.h> #include <folly/portability/PThread.h>
#include <folly/synchronization/MicroSpinLock.h> #include <folly/synchronization/MicroSpinLock.h>
...@@ -293,7 +294,8 @@ class PthreadKeyUnregister { ...@@ -293,7 +294,8 @@ class PthreadKeyUnregister {
void registerKeyImpl(pthread_key_t key) { void registerKeyImpl(pthread_key_t key) {
MSLGuard lg(lock_); MSLGuard lg(lock_);
if (size_ == kMaxKeys) { if (size_ == kMaxKeys) {
throw std::logic_error("pthread_key limit has already been reached"); throw_exception<std::logic_error>(
"pthread_key limit has already been reached");
} }
keys_[size_++] = key; keys_[size_++] = key;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment