00001 /* 00002 * Copyright (C) 2006, Jose Renato Santos. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 */ 00017 00018 /////////////////////////////////////////////////////////////////////////////// 00019 // vsicondition.cpp: Implementation of class CvsiCondition (VSI condition 00020 // variable) 00021 // (VSI: Virtual System Interface) 00022 /////////////////////////////////////////////////////////////////////////////// 00023 00024 00025 #include <vsicondition.h> 00026 00027 /////////////////////////////////////////////////////////////////////////////// 00028 // Construction/Destruction 00029 CvsiCondition::CvsiCondition() 00030 { 00031 int result = pthread_cond_init(&m_Condition,NULL); 00032 if(result == 0) 00033 { 00034 result = pthread_mutex_init(&m_Mutex,NULL); 00035 if(result == 0) 00036 { 00037 m_isopen = true; 00038 } 00039 else 00040 { 00041 pthread_cond_destroy(&m_Condition); 00042 m_isopen = false; 00043 } 00044 } 00045 else 00046 m_isopen = false; 00047 00048 } 00049 00050 /////////////////////////////////////////////////////////////////////////////// 00051 CvsiCondition::~CvsiCondition() 00052 { 00053 if(m_isopen) 00054 { 00055 pthread_cond_destroy(&m_Condition); 00056 pthread_mutex_destroy(&m_Mutex); 00057 } 00058 } 00059 00060 /////////////////////////////////////////////////////////////////////////////// 00061 void CvsiCondition::Lock() 00062 { 00063 pthread_mutex_lock(&m_Mutex); 00064 } 00065 00066 /////////////////////////////////////////////////////////////////////////////// 00067 void CvsiCondition::Unlock() 00068 { 00069 pthread_mutex_unlock(&m_Mutex); 00070 } 00071 00072 /////////////////////////////////////////////////////////////////////////////// 00073 int CvsiCondition::IsOpen() 00074 { 00075 return m_isopen; 00076 } 00077 00078 /////////////////////////////////////////////////////////////////////////////// 00079 void CvsiCondition::Wait() 00080 { 00081 pthread_cond_wait(&m_Condition,&m_Mutex); 00082 } 00083 00084 /////////////////////////////////////////////////////////////////////////////// 00085 void CvsiCondition::Signal() 00086 { 00087 pthread_cond_broadcast(&m_Condition); 00088 }