Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
ErrorHolder.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
8 */
9#pragma once
10
11#include <atomic>
12#include <cassert>
13#include <stdexcept>
14#include <string>
15
16namespace pzstd {
17
18// Coordinates graceful shutdown of the pzstd pipeline
19class ErrorHolder {
20 std::atomic<bool> error_;
21 std::string message_;
22
23 public:
24 ErrorHolder() : error_(false) {}
25
26 bool hasError() noexcept {
27 return error_.load();
28 }
29
30 void setError(std::string message) noexcept {
31 // Given multiple possibly concurrent calls, exactly one will ever succeed.
32 bool expected = false;
33 if (error_.compare_exchange_strong(expected, true)) {
34 message_ = std::move(message);
35 }
36 }
37
38 bool check(bool predicate, std::string message) noexcept {
39 if (!predicate) {
40 setError(std::move(message));
41 }
42 return !hasError();
43 }
44
45 std::string getError() noexcept {
46 error_.store(false);
47 return std::move(message_);
48 }
49
51 assert(!hasError());
52 }
53};
54}
Definition ErrorHolder.h:19
std::string getError() noexcept
Definition ErrorHolder.h:45
void setError(std::string message) noexcept
Definition ErrorHolder.h:30
bool check(bool predicate, std::string message) noexcept
Definition ErrorHolder.h:38
~ErrorHolder()
Definition ErrorHolder.h:50
ErrorHolder()
Definition ErrorHolder.h:24
bool hasError() noexcept
Definition ErrorHolder.h:26
#define assert(condition)
Definition lz4.c:273
Definition ErrorHolder.h:16
#define false
Definition longfile.c:42
void message(enum message_verbosity v, const char *fmt,...)
Definition message.c:737