00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */ 00002 00003 /* 00004 * Copyright (c) 2007, 2008 Ciaran McCreesh 00005 * 00006 * This file is part of the Paludis package manager. Paludis is free software; 00007 * you can redistribute it and/or modify it under the terms of the GNU General 00008 * Public License version 2, as published by the Free Software Foundation. 00009 * 00010 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY 00011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00013 * details. 00014 * 00015 * You should have received a copy of the GNU General Public License along with 00016 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00017 * Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_THREAD_HH 00021 #define PALUDIS_GUARD_PALUDIS_UTIL_THREAD_HH 1 00022 00023 #include <paludis/util/attributes.hh> 00024 #include <tr1/functional> 00025 #include <string> 00026 #include <pthread.h> 00027 00028 /** \file 00029 * Declarations for the Thread class. 00030 * 00031 * \ingroup g_threads 00032 * 00033 * \section Examples 00034 * 00035 * - None at this time. 00036 */ 00037 00038 namespace paludis 00039 { 00040 /** 00041 * A basic thread class. 00042 * 00043 * If threading is disabled, the threaded function is executed immediately 00044 * in the current context. 00045 * 00046 * \ingroup g_threads 00047 * \since 0.26 00048 * \nosubgrouping 00049 */ 00050 class PALUDIS_VISIBLE Thread 00051 { 00052 private: 00053 pthread_t * const _thread; 00054 const std::tr1::function<void () throw ()> _func; 00055 std::string _exception; 00056 00057 static void * thread_func(void *); 00058 00059 public: 00060 ///\name Basic operations 00061 ///\{ 00062 00063 Thread(const std::tr1::function<void () throw ()> &); 00064 ~Thread(); 00065 00066 ///\} 00067 00068 /** 00069 * Adapt a function for use in IdleActionPool. 00070 */ 00071 static void idle_adapter(const std::tr1::function<void () throw ()> &); 00072 }; 00073 } 00074 00075 #endif