00001 /* This file is part of Raul. 00002 * Copyright (C) 2007-2009 David Robillard <http://drobilla.net> 00003 * 00004 * Raul is free software; you can redistribute it and/or modify it under the 00005 * terms of the GNU General Public License as published by the Free Software 00006 * Foundation; either version 2 of the License, or (at your option) any later 00007 * version. 00008 * 00009 * Raul is distributed in the hope that it will be useful, but WITHOUT ANY 00010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. 00012 * 00013 * You should have received a copy of the GNU General Public License along 00014 * with this program; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00016 */ 00017 00018 #ifndef RAUL_SLAVE_HPP 00019 #define RAUL_SLAVE_HPP 00020 00021 #include <pthread.h> 00022 #include "raul/Semaphore.hpp" 00023 #include "raul/Thread.hpp" 00024 00025 namespace Raul { 00026 00027 00035 class Slave : public Thread 00036 { 00037 public: 00038 Slave() : _whip(0) {} 00039 00041 inline void whip() { _whip.post(); } 00042 00043 protected: 00050 virtual void _whipped() = 0; 00051 00052 Semaphore _whip; 00053 00054 private: 00055 inline void _run() { 00056 while (true) { 00057 _whip.wait(); 00058 _whipped(); 00059 } 00060 } 00061 }; 00062 00063 00064 } // namespace Raul 00065 00066 #endif // RAUL_SLAVE_HPP