//  Copyright (c) 2018 Hartmut Kaiser
//
//  SPDX-License-Identifier: BSL-1.0
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <pika/config.hpp>
#include <pika/threading_base/callback_notifier.hpp>

namespace pika {
    /// Retrieve the currently installed start handler function. This is a
    /// function that will be called by pika for each newly created thread that
    /// is made known to the runtime. pika stores exactly one such function
    /// reference, thus the caller needs to make sure any newly registered
    /// start function chains into the previous one (see
    /// \a register_thread_on_start_func).
    ///
    /// \returns The currently installed error handler function.
    ///
    /// \note This function can be called before the pika runtime is initialized.
    ///
    PIKA_EXPORT threads::callback_notifier::on_startstop_type get_thread_on_start_func();

    /// Retrieve the currently installed stop handler function. This is a
    /// function that will be called by pika for each newly created thread that
    /// is made known to the runtime. pika stores exactly one such function
    /// reference, thus the caller needs to make sure any newly registered
    /// stop function chains into the previous one (see
    /// \a register_thread_on_stop_func).
    ///
    /// \returns The currently installed error handler function.
    ///
    /// \note This function can be called before the pika runtime is initialized.
    ///
    PIKA_EXPORT threads::callback_notifier::on_startstop_type get_thread_on_stop_func();

    /// Retrieve the currently installed error handler function. This is a
    /// function that will be called by pika for each newly created thread that
    /// is made known to the runtime. pika stores exactly one such function
    /// reference, thus the caller needs to make sure any newly registered
    /// error function chains into the previous one (see
    /// \a register_thread_on_error_func).
    ///
    /// \returns The currently installed error handler function.
    ///
    /// \note This function can be called before the pika runtime is initialized.
    ///
    PIKA_EXPORT threads::callback_notifier::on_error_type get_thread_on_error_func();

    /// Set the currently installed start handler function. This is a
    /// function that will be called by pika for each newly created thread that
    /// is made known to the runtime. pika stores exactly one such function
    /// reference, thus the caller needs to make sure any newly registered
    /// start function chains into the previous one (see
    /// \a get_thread_on_start_func).
    ///
    /// \param f The function to install as the new start handler.
    ///
    /// \returns The previously registered function of this category. It is
    ///          the user's responsibility to call that function if the
    ///          callback is invoked by pika.
    ///
    /// \note This function can be called before the pika runtime is initialized.
    ///
    PIKA_EXPORT threads::callback_notifier::on_startstop_type register_thread_on_start_func(
        threads::callback_notifier::on_startstop_type&& f);

    /// Set the currently installed stop handler function. This is a
    /// function that will be called by pika for each newly created thread that
    /// is made known to the runtime. pika stores exactly one such function
    /// reference, thus the caller needs to make sure any newly registered
    /// stop function chains into the previous one (see
    /// \a get_thread_on_stop_func).
    ///
    /// \param f The function to install as the new stop handler.
    ///
    /// \returns The previously registered function of this category. It is
    ///          the user's responsibility to call that function if the
    ///          callback is invoked by pika.
    ///
    /// \note This function can be called before the pika runtime is initialized.
    ///
    PIKA_EXPORT threads::callback_notifier::on_startstop_type register_thread_on_stop_func(
        threads::callback_notifier::on_startstop_type&& f);

    /// Set the currently installed error handler function. This is a
    /// function that will be called by pika for each newly created thread that
    /// is made known to the runtime. pika stores exactly one such function
    /// reference, thus the caller needs to make sure any newly registered
    /// error function chains into the previous one (see
    /// \a get_thread_on_error_func).
    ///
    /// \param f The function to install as the new error handler.
    ///
    /// \returns The previously registered function of this category. It is
    ///          the user's responsibility to call that function if the
    ///          callback is invoked by pika.
    ///
    /// \note This function can be called before the pika runtime is initialized.
    ///
    PIKA_EXPORT threads::callback_notifier::on_error_type register_thread_on_error_func(
        threads::callback_notifier::on_error_type&& f);
}    // namespace pika
