reSIProcate/rutil  9694
Condition.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_CONDITION_HXX)
00002 #define RESIP_CONDITION_HXX
00003 
00004 #if defined(WIN32)
00005 #  include <windows.h>
00006 #  include <winbase.h>
00007 #else
00008 #  include <pthread.h>
00009 #endif
00010 
00011 // !kh!
00012 // Attempt to resolve POSIX behaviour conformance for win32 build.
00013 #define RESIP_CONDITION_WIN32_CONFORMANCE_TO_POSIX
00014 
00015 namespace resip
00016 {
00017 
00018 class Mutex;
00019 
00051 class Condition
00052 {
00053    public:
00054       Condition();
00055       virtual ~Condition();
00056 
00060       void wait (Mutex& mtx);
00066       bool wait (Mutex& mutex, unsigned int ms);
00067 
00068       // !kh!
00069       //  deprecate these?
00070       void wait (Mutex* mutex);
00071       bool wait (Mutex* mutex, unsigned int ms);
00072 
00077       void signal();
00078 
00083       void broadcast();
00084 
00085    private:
00086       // !kh!
00087       //  no value sematics, therefore private and not implemented.
00088       Condition (const Condition&);
00089       Condition& operator= (const Condition&);
00090 
00091    private:
00092 #ifdef WIN32
00093 #  ifdef RESIP_CONDITION_WIN32_CONFORMANCE_TO_POSIX
00094    // !kh!
00095    // boost clone with modification (license text below)
00096    void enterWait ();
00097    void* m_gate;
00098    void* m_queue;
00099    void* m_mutex;
00100    unsigned m_gone;  // # threads that timed out and never made it to m_queue
00101    unsigned long m_blocked; // # threads blocked on the condition
00102    unsigned m_waiting; // # threads no longer waiting for the condition but
00103                         // still waiting to be removed from m_queue
00104 #  else
00105    HANDLE mId;
00106 #  endif
00107 #else
00108    mutable  pthread_cond_t mId;
00109 #endif
00110 };
00111 
00112 }
00113 
00114 #endif
00115 
00116 // Note:  Win32 Condition implementation is a modified version of the
00117 // Boost.org Condition implementation
00118 //
00119 
00120 /* ====================================================================
00121  *
00122  * Boost Software License - Version 1.0 - August 17th, 2003
00123  * 
00124  * Permission is hereby granted, free of charge, to any person or organization
00125  * obtaining a copy of the software and accompanying documentation covered by
00126  * this license (the "Software") to use, reproduce, display, distribute,
00127  * execute, and transmit the Software, and to prepare derivative works of the
00128  * Software, and to permit third-parties to whom the Software is furnished to
00129  * do so, all subject to the following:
00130  * 
00131  * The copyright notices in the Software and this entire statement, including
00132  * the above license grant, this restriction and the following disclaimer,
00133  * must be included in all copies of the Software, in whole or in part, and
00134  * all derivative works of the Software, unless such copies or derivative
00135  * works are solely in the form of machine-executable object code generated by
00136  * a source language processor.
00137  * 
00138  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00139  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00140  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00141  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00142  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00143  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00144  * DEALINGS IN THE SOFTWARE.
00145  *
00146  * ====================================================================
00147  */
00148 
00149 
00150 /* ====================================================================
00151  * The Vovida Software License, Version 1.0
00152  *
00153  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00154  *
00155  * Redistribution and use in source and binary forms, with or without
00156  * modification, are permitted provided that the following conditions
00157  * are met:
00158  *
00159  * 1. Redistributions of source code must retain the above copyright
00160  *    notice, this list of conditions and the following disclaimer.
00161  *
00162  * 2. Redistributions in binary form must reproduce the above copyright
00163  *    notice, this list of conditions and the following disclaimer in
00164  *    the documentation and/or other materials provided with the
00165  *    distribution.
00166  *
00167  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00168  *    and "Vovida Open Communication Application Library (VOCAL)" must
00169  *    not be used to endorse or promote products derived from this
00170  *    software without prior written permission. For written
00171  *    permission, please contact vocal@vovida.org.
00172  *
00173  * 4. Products derived from this software may not be called "VOCAL", nor
00174  *    may "VOCAL" appear in their name, without prior written
00175  *    permission of Vovida Networks, Inc.
00176  *
00177  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00178  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00179  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00180  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00181  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00182  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00183  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00184  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00185  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00186  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00187  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00188  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00189  * DAMAGE.
00190  *
00191  * ====================================================================
00192  *
00193  * This software consists of voluntary contributions made by Vovida
00194  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00195  * Inc.  For more information on Vovida Networks, Inc., please see
00196  * <http://www.vovida.org/>.
00197  *
00198  */