S3FC project page | S3FC home page |
00001 /* 00002 * Stone Three Foundation Class (s3fc) provides a number of utility classes. 00003 * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd. 00004 * 00005 * Authored by Stone Three Signal Processing (Pty) Ltd. 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * 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 this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * Please see the file 'COPYING' in the source root directory. 00022 */ 00023 00033 #include <s3fc/s3_condition.h> 00034 #include <s3fc/s3_exception.h> 00035 00036 #ifndef CONST_OVERRIDE_COND_T 00037 #define CONST_OVERRIDE_COND_T(x) const_cast<pthread_cond_t*>(x) 00038 #endif 00039 00040 #ifndef CONST_OVERRIDE_MUTEX_T 00041 #define CONST_OVERRIDE_MUTEX_T(x) const_cast<pthread_mutex_t*>(x) 00042 #endif 00043 00044 // 00045 s3_condition::s3_condition() 00046 { 00047 // this always works (or anyway doesn't tell you if it fails) 00048 pthread_cond_init(&cond, 0); 00049 } 00050 00051 // 00052 s3_condition::~s3_condition() 00053 { 00054 if ( pthread_cond_destroy(CONST_OVERRIDE_COND_T(&cond)) != 0 ) 00055 { 00056 throw s3_generic_exception("s3_mutex::~s3_mutex()", 00057 "Attempted to destroy condition with " 00058 "threads waiting on it"); 00059 } 00060 } 00061 00062 // 00063 void s3_condition::wait(const s3_mutex& mutex) const 00064 { 00065 pthread_cond_wait(CONST_OVERRIDE_COND_T(&cond), 00066 CONST_OVERRIDE_MUTEX_T(&(mutex.mutex))); 00067 } 00068 00069 00070 // 00071 void s3_condition::signal() const 00072 { 00073 pthread_cond_signal(CONST_OVERRIDE_COND_T(&cond)); 00074 } 00075 00076 // 00077 void s3_condition::broadcast() const 00078 { 00079 pthread_cond_broadcast(CONST_OVERRIDE_COND_T(&cond)); 00080 }
Send comments to: s3fc@stonethree.com |
|