Skip to content

Commit

Permalink
condition_variable: move exception factory functions out of line
Browse files Browse the repository at this point in the history
Error path need not be implemented in the header file.
Also mark them noexcept as broken_condition_variable
and condition_variable_timed_out are nothrow default constructible.

Signed-off-by: Benny Halevy <[email protected]>
  • Loading branch information
bhalevy committed Oct 25, 2020
1 parent d4fcfc4 commit 6cf6700
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ add_library (seastar STATIC
src/core/vla.hh
src/core/io_queue.cc
src/core/semaphore.cc
src/core/condition-variable.cc
src/http/api_docs.cc
src/http/common.cc
src/http/file_handler.cc
Expand Down
16 changes: 4 additions & 12 deletions include/seastar/core/condition-variable.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,15 @@ namespace seastar {
class broken_condition_variable : public std::exception {
public:
/// Reports the exception reason.
virtual const char* what() const noexcept {
return "Condition variable is broken";
}
virtual const char* what() const noexcept;
};

/// Exception thrown when wait() operation times out
/// \ref condition_variable::wait(time_point timeout).
class condition_variable_timed_out : public std::exception {
public:
/// Reports the exception reason.
virtual const char* what() const noexcept {
return "Condition variable timed out";
}
virtual const char* what() const noexcept;
};

/// \brief Conditional variable.
Expand All @@ -67,12 +63,8 @@ class condition_variable {
using clock = semaphore::clock;
using time_point = semaphore::time_point;
struct condition_variable_exception_factory {
static condition_variable_timed_out timeout() {
return condition_variable_timed_out();
}
static broken_condition_variable broken() {
return broken_condition_variable();
}
static condition_variable_timed_out timeout() noexcept;
static broken_condition_variable broken() noexcept;
};
basic_semaphore<condition_variable_exception_factory> _sem;
public:
Expand Down
44 changes: 44 additions & 0 deletions src/core/condition-variable.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is open source software, licensed to you under the terms
* of the Apache License, Version 2.0 (the "License"). See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. You may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Copyright (C) 2020 ScyllaDB, Ltd.
*/

#include <seastar/core/condition-variable.hh>

namespace seastar {

const char* broken_condition_variable::what() const noexcept {
return "Condition variable is broken";
}

const char* condition_variable_timed_out::what() const noexcept {
return "Condition variable timed out";
}

condition_variable_timed_out condition_variable::condition_variable_exception_factory::timeout() noexcept {
static_assert(std::is_nothrow_default_constructible_v<condition_variable_timed_out>);
return condition_variable_timed_out();
}

broken_condition_variable condition_variable::condition_variable_exception_factory::broken() noexcept {
static_assert(std::is_nothrow_default_constructible_v<broken_condition_variable>);
return broken_condition_variable();
}

} // namespace seastar

0 comments on commit 6cf6700

Please sign in to comment.