| 126 | // the cache entry may be evicted by another thread. |
| 127 | |
| 128 | Value operator()(const Key& key) { |
| 129 | std::unique_lock<std::mutex> lock(mutex_); |
| 130 | const Value* value_ptr; |
| 131 | value_ptr = cache_.Find(key); |
| 132 | if (ARROW_PREDICT_TRUE(value_ptr != nullptr)) { |
| 133 | return *value_ptr; |
| 134 | } |
| 135 | lock.unlock(); |
| 136 | Value v = func_(key); |
| 137 | lock.lock(); |
| 138 | return *cache_.Replace(key, std::move(v)).second; |
| 139 | } |
| 140 | |
| 141 | private: |
| 142 | std::mutex mutex_; |