Returns true iff the instance was newly initialized with `options`
| 3480 | |
| 3481 | // Returns true iff the instance was newly initialized with `options` |
| 3482 | Result<bool> EnsureInitialized(const S3GlobalOptions& options) { |
| 3483 | // NOTE: The individual accesses are atomic but the entire sequence below is not. |
| 3484 | // The application should serialize calls to InitializeS3() and FinalizeS3() |
| 3485 | // (see docstrings). |
| 3486 | if (is_finalized_.load()) { |
| 3487 | return Status::Invalid("Attempt to initialize S3 after it has been finalized"); |
| 3488 | } |
| 3489 | bool newly_initialized = false; |
| 3490 | // EnsureInitialized() can be called concurrently by FileSystemFromUri, |
| 3491 | // therefore we need to serialize initialization (GH-39897). |
| 3492 | std::call_once(initialize_flag_, [&]() { |
| 3493 | bool was_initialized = is_initialized_.exchange(true); |
| 3494 | DCHECK(!was_initialized); |
| 3495 | DoInitialize(options); |
| 3496 | newly_initialized = true; |
| 3497 | }); |
| 3498 | return newly_initialized; |
| 3499 | } |
| 3500 | |
| 3501 | bool IsInitialized() { return !is_finalized_ && is_initialized_; } |
| 3502 |
no test coverage detected