latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiReadWriteLock.h 00027 * authors ....: Thomas Rusert 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 10.11.99 00030 * revisions ..: $Id: ltiReadWriteLock.h,v 1.5 2006/02/08 12:54:22 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_READ_WRITE_LOCK_H_ 00034 #define _LTI_READ_WRITE_LOCK_H_ 00035 00036 #if defined(_LTI_LINUX) || defined(_LTI_MACOSX) 00037 #include "ltiObject.h" 00038 #include <pthread.h> 00039 00040 namespace lti { 00041 00042 /// lti read-write synchronisation class 00043 class readWriteLock : public object { 00044 public: 00045 00046 /// default constructor 00047 readWriteLock(); 00048 00049 /// destructor 00050 virtual ~readWriteLock(); 00051 00052 /** 00053 * wait until read-write lock becomes available and lock it for read 00054 * access 00055 */ 00056 void lockRead() const; 00057 00058 /** 00059 * Try to lock, but do not block. 00060 * Return true if locking was successful. 00061 */ 00062 bool tryLockRead() const; 00063 00064 /** 00065 * wait until read-write lock becomes available and lock it for write 00066 * access 00067 */ 00068 void lockWrite() const; 00069 00070 /** 00071 * Try to lock, but do not block. 00072 * Return true if locking was successful. 00073 */ 00074 bool tryLockWrite() const; 00075 00076 /// unlock read-write lock from read or write access 00077 void unlock() const; 00078 00079 /// returns the name of this type 00080 virtual const char* getTypeName() const; 00081 protected: 00082 void destroy(); 00083 00084 mutable pthread_rwlock_t theLock; 00085 }; 00086 } 00087 00088 #endif 00089 #endif