thread_cancellation.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2023 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef THREAD_CANCELLATION_HPP
#define THREAD_CANCELLATION_HPP
#include "../my_config.h"
extern "C"
{
#if MUTEX_WORKS
#if HAVE_PTHREAD_H
#include <pthread.h>
#endif
#endif
}
#include <list>
#include <map>
#include "integers.hpp"
#include "erreurs.hpp"
namespace libdar
{
class thread_cancellation
{
public:
thread_cancellation();
thread_cancellation(const thread_cancellation & ref) = default;
thread_cancellation(thread_cancellation && ref) noexcept = default;
thread_cancellation & operator = (const thread_cancellation & ref) = default;
thread_cancellation & operator = (thread_cancellation && ref) noexcept = default;
virtual ~thread_cancellation() noexcept(false);
void check_self_cancellation() const;
void block_delayed_cancellation(bool mode);
#if MUTEX_WORKS
static void cancel(pthread_t tid, bool x_immediate, U_64 x_flag);
static bool cancel_status(pthread_t tid);
static bool clear_pending_request(pthread_t tid);
static void associate_tid_to_tid(pthread_t src, pthread_t dst);
static void remove_association_for_tid(pthread_t src);
static void remove_association_targeted_at(pthread_t dst);
static void dead_thread(pthread_t tid);
#endif
static U_I count()
{
#if MUTEX_WORKS
return info.size();
#else
return 0;
#endif
};
#if MUTEX_WORKS
private:
// class types
struct fields
{
pthread_t tid;
bool block_delayed;
bool immediate;
bool cancellation;
U_64 flag;
};
// object information
fields status;
// class's static variables and types
static pthread_mutex_t access;
static std::list<thread_cancellation *> info;
static std::list<fields> preborn;
static std::multimap<pthread_t, pthread_t> thread_asso;
// helper class routing
static void set_cancellation_in_info_for(pthread_t tid,
bool cancel_status,
bool x_immediate,
U_64 x_flag,
bool & found,
bool & previous_val,
bool & bug);
static void add_to_preborn(pthread_t tid, bool x_immediate, U_64 x_flag);
static void remove_from_preborn(pthread_t tid, bool & found, bool & prev);
static void find_asso_tid_with(pthread_t tid,
std::multimap<pthread_t, pthread_t>::iterator & begin,
std::multimap<pthread_t, pthread_t>::iterator & end);
#endif
};
} // end of namespace
#endif
libdar::thread_cancellation
class to be used as parent to provide checkpoints to inherited classes
Definition: thread_cancellation.hpp:69
libdar::thread_cancellation::count
static U_I count()
method for debugging/control purposes
Definition: thread_cancellation.hpp:152
libdar::thread_cancellation::thread_cancellation
thread_cancellation(thread_cancellation &&ref) noexcept=default
move constructor
libdar::thread_cancellation::~thread_cancellation
virtual ~thread_cancellation() noexcept(false)
the destructor
libdar::thread_cancellation::thread_cancellation
thread_cancellation(const thread_cancellation &ref)=default
copy constructor
libdar::thread_cancellation::block_delayed_cancellation
void block_delayed_cancellation(bool mode)
libdar::thread_cancellation::operator=
thread_cancellation & operator=(const thread_cancellation &ref)=default
assignment operator
libdar::thread_cancellation::thread_cancellation
thread_cancellation()
the constructor
libdar::thread_cancellation::check_self_cancellation
void check_self_cancellation() const
Checkpoint test : whether the current libdar call must abort or not.
erreurs.hpp
contains all the excetion class thrown by libdar
integers.hpp
are defined here basic integer types that tend to be portable
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47