00001 /*00002 * The Software License00003 * =================================================================================00004 * Copyright (c) 2003-.The Terimber Corporation. All rights reserved.00005 * =================================================================================00006 * Redistributions of source code must retain the above copyright notice, 00007 * this list of conditions and the following disclaimer.00008 * Redistributions in binary form must reproduce the above copyright notice, 00009 * this list of conditions and the following disclaimer in the documentation 00010 * and/or other materials provided with the distribution.00011 * The end-user documentation included with the redistribution, if any, 00012 * must include the following acknowledgment:00013 * "This product includes software developed by the Terimber Corporation."00014 * =================================================================================00015 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, 00016 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00017 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00018 * IN NO EVENT SHALL THE TERIMBER CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR 00019 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00020 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00021 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00022 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT00023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE00024 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.00025 * ================================================================================00026 */00027
00028 #ifndef _terimber_keymaker_h_00029 #define _terimber_keymaker_h_00030
00031 #include "base/primitives.h"00032
00033 BEGIN_TERIMBER_NAMESPACE00034 #pragma pack(4)00035
00038class keylocker00039 {
00040 public:
00042 inline00043 keylocker( size_t capacity = os_def_size00044 );
00047 inline00048 bool00049 enter( size_t timeout
00050 ) const;
00052 inline00053 void00054 leave() const;
00057 inline00058 bool00059 lock( size_t timeout
00060 ) const;
00062 inline00063 void00064 unlock() const;
00065 private:
00066constsize_t_capacity;
00067mutablebool_opened;
00068mutablesize_t_clients;
00069event_ev_open;
00070event_ev_close;
00071event_ev_client;
00072event_ev_server;
00073mutex_access_mtx;
00074mutex_server_mtx;
00075 };
00076
00079class keylocker_server00080 {
00081 public:
00083 inline00084 keylocker_server( constkeylocker& locker,
00085 size_t timeout = INFINITE
00086 );
00088 inline00089 ~keylocker_server();
00091 inline00092 operator bool() const;
00094 inline00095 bool00096 operator!() const;
00098 inline00099 void00100 unlock() const;
00102 inline00103 void00104 lock(size_t timeout = INFINITE) const;
00105 private:
00106mutablebool_locked;
00107constkeylocker& _locker;
00108 };
00109
00112class keylocker_client00113 {
00114 public:
00116 inline00117 keylocker_client( constkeylocker& locker,
00118 size_t timeout = INFINITE
00119 );
00121 inline00122 ~keylocker_client();
00124 inline00125 operator bool() const;
00127 inline00128 bool00129 operator!() const;
00131 inline00132 void00133 leave() const;
00135 inline00136 void00137 enter(size_t timeout = INFINITE) const;
00138 private:
00139mutablebool_inside;
00140constkeylocker& _locker;
00141 };
00142
00143
00144 #pragma pack()00145 END_TERIMBER_NAMESPACE00146
00147 #endif // _terimber_keymaker_h_00148