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 // vsisemaphore.cpp: Implementation of class CvsiSemaphore (implements VSI 00020 // semaphore) 00021 // (VSI: Virtual System Interface) 00022 /////////////////////////////////////////////////////////////////////////////// 00023 00024 #include <vsisemaphore.h> 00025 00026 /////////////////////////////////////////////////////////////////////////////// 00027 // Construction/Destruction 00028 /////////////////////////////////////////////////////////////////////////////// 00029 00030 CvsiSemaphore::CvsiSemaphore(int InitialValue) 00031 { 00032 int result = sem_init(&m_Semaphore,0,InitialValue); 00033 if(result == 0) 00034 { 00035 m_isopen = true; 00036 } 00037 else 00038 { 00039 m_isopen = false; 00040 } 00041 } 00042 /////////////////////////////////////////////////////////////////////////////// 00043 CvsiSemaphore::~CvsiSemaphore() 00044 { 00045 if(m_isopen) 00046 { 00047 sem_destroy(&m_Semaphore); 00048 } 00049 } 00050 00051 /////////////////////////////////////////////////////////////////////////////// 00052 int CvsiSemaphore::IsOpen() 00053 { 00054 return m_isopen; 00055 } 00056 /////////////////////////////////////////////////////////////////////////////// 00057 void CvsiSemaphore::P() 00058 { 00059 sem_wait(&m_Semaphore); 00060 } 00061 /////////////////////////////////////////////////////////////////////////////// 00062 void CvsiSemaphore::V() 00063 { 00064 sem_post(&m_Semaphore); 00065 }