RTP Audio System  2.0.0
synchronizable.h
Go to the documentation of this file.
00001 /*
00002  *  $Id: synchronizable.h 1259 2011-12-17 13:26:09Z dreibh $
00003  *
00004  * SocketAPI implementation for the sctplib.
00005  * Copyright (C) 1999-2012 by Thomas Dreibholz
00006  *
00007  * Realized in co-operation between
00008  * - Siemens AG
00009  * - University of Essen, Institute of Computer Networking Technology
00010  * - University of Applied Sciences, Muenster
00011  *
00012  * Acknowledgement
00013  * This work was partially funded by the Bundesministerium fuer Bildung und
00014  * Forschung (BMBF) of the Federal Republic of Germany (Foerderkennzeichen 01AK045).
00015  * The authors alone are responsible for the contents.
00016  *
00017  * This program is free software: you can redistribute it and/or modify
00018  * it under the terms of the GNU General Public License as published by
00019  * the Free Software Foundation, either version 3 of the License, or
00020  * (at your option) any later version.
00021 
00022  * This program is distributed in the hope that it will be useful,
00023  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025  * GNU General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00029  *
00030  * Contact: discussion@sctp.de
00031  *          dreibh@iem.uni-due.de
00032  *          tuexen@fh-muenster.de
00033  *
00034  * Purpose: Synchronizable Implementation
00035  *
00036  */
00037 
00038 
00039 #ifndef SYNCHRONIZABLE_H
00040 #define SYNCHRONIZABLE_H
00041 
00042 
00043 #include "tdsystem.h"
00044 
00045 
00046 #include <sys/types.h>
00047 #include <pthread.h>
00048 #include <set>
00049 
00050 
00051 // System does not support recursive mutex.
00052 // #define NO_RECURSIVE_MUTEX
00053 
00054 
00055 #ifdef NO_RECURSIVE_MUTEX
00056 #warning Usage of recursive pthread mutexes disabled!
00057 #endif
00058 
00059 #if (SYSTEM == OS_Darwin)
00060 #ifndef NO_RECURSIVE_MUTEX
00061 #define NO_RECURSIVE_MUTEX
00062 #endif
00063 #endif
00064 
00065 
00080 class Synchronizable
00081 {
00082    // ====== Constructor/Destructor =========================================
00083    public:
00090    Synchronizable(const char* name      = "Synchronizable",
00091                   const bool  recursive = true);
00092 
00096    ~Synchronizable();
00097 
00098 
00099    // ====== Synchronization ================================================
00108    inline void synchronized();
00109 
00118    inline bool synchronizedTry();
00119 
00126    inline void unsynchronized();
00127 
00128 
00132    void resynchronize();
00133 
00134 
00135    // ====== Disable/enable cancelability of current thread =================
00141    inline static bool setCancelState(const bool enabled);
00142 
00143 
00144    // ====== Synchronizable naming for debugging ============================
00150    inline const char* getName() const;
00151 
00157    inline void setName(const char* name);
00158 
00159 
00160    // ====== Protected data =================================================
00161    protected:
00162    pthread_mutex_t Mutex;
00163 #ifdef NO_RECURSIVE_MUTEX
00164    cardinal        RecursionLevel;
00165    pthread_t       Owner;
00166 #endif
00167    bool            Recursive;
00168    char            MutexName[64];
00169 };
00170 
00171 
00172 #include "synchronizable.icc"
00173 
00174 
00175 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines