⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 safecoll_8h-source.html

📁 pwlib开发文档
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>safecoll.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center><hr><h1>safecoll.h</h1><a href="safecoll_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> * safecoll.h</span>00003 <span class="comment"> *</span>00004 <span class="comment"> * Thread safe collection classes.</span>00005 <span class="comment"> *</span>00006 <span class="comment"> * Portable Windows Library</span>00007 <span class="comment"> *</span>00008 <span class="comment"> * Copyright (c) 2002 Equivalence Pty. Ltd.</span>00009 <span class="comment"> *</span>00010 <span class="comment"> * The contents of this file are subject to the Mozilla Public License</span>00011 <span class="comment"> * Version 1.0 (the "License"); you may not use this file except in</span>00012 <span class="comment"> * compliance with the License. You may obtain a copy of the License at</span>00013 <span class="comment"> * http://www.mozilla.org/MPL/</span>00014 <span class="comment"> *</span>00015 <span class="comment"> * Software distributed under the License is distributed on an "AS IS"</span>00016 <span class="comment"> * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See</span>00017 <span class="comment"> * the License for the specific language governing rights and limitations</span>00018 <span class="comment"> * under the License.</span>00019 <span class="comment"> *</span>00020 <span class="comment"> * The Original Code is Portable Windows Library.</span>00021 <span class="comment"> *</span>00022 <span class="comment"> * The Initial Developer of the Original Code is Equivalence Pty. Ltd.</span>00023 <span class="comment"> *</span>00024 <span class="comment"> * Contributor(s): ______________________________________.</span>00025 <span class="comment"> *</span>00026 <span class="comment"> * $Log: safecoll.h,v $</span>00027 <span class="comment"> * Revision 1.9  2004/08/12 12:37:40  rjongbloed</span>00028 <span class="comment"> * Fixed bug recently introduced so removes deleted object from deletion list.</span>00029 <span class="comment"> * Also changed removal list to be correct type.</span>00030 <span class="comment"> *</span>00031 <span class="comment"> * Revision 1.8  2004/08/05 12:15:56  rjongbloed</span>00032 <span class="comment"> * Added classes for auto unlocking read only and read write mutex on</span>00033 <span class="comment"> *   PSafeObject - similar to PWaitAndSIgnal.</span>00034 <span class="comment"> * Utilised mutable keyword for mutex and improved the constness of functions.</span>00035 <span class="comment"> * Added DisallowDeleteObjects to safe collections so can have a PSafeObject in</span>00036 <span class="comment"> *   multiple collections.</span>00037 <span class="comment"> * Added a tempalte function to do casting of PSafePtr to a PSafePtr of a derived</span>00038 <span class="comment"> *   class.</span>00039 <span class="comment"> * Assured that a PSafeObject present on a collection always increments its</span>00040 <span class="comment"> *   reference count so while in collection it is not deleted.</span>00041 <span class="comment"> *</span>00042 <span class="comment"> * Revision 1.7  2002/12/10 07:36:57  robertj</span>00043 <span class="comment"> * Fixed possible deadlock in PSafeCollection find functions.</span>00044 <span class="comment"> *</span>00045 <span class="comment"> * Revision 1.6  2002/10/29 00:06:14  robertj</span>00046 <span class="comment"> * Changed template classes so things like PSafeList actually creates the</span>00047 <span class="comment"> *   base collection class as well.</span>00048 <span class="comment"> * Allowed for the PSafeList::Append() to return a locked pointer to the</span>00049 <span class="comment"> *   object just appended.</span>00050 <span class="comment"> *</span>00051 <span class="comment"> * Revision 1.5  2002/10/04 08:22:40  robertj</span>00052 <span class="comment"> * Changed read/write mutex so can be called by same thread without deadlock</span>00053 <span class="comment"> *   removing the need to a lock count in safe pointer.</span>00054 <span class="comment"> * Added asserts if try and dereference a NULL safe pointer.</span>00055 <span class="comment"> * Added more documentation on behaviour.</span>00056 <span class="comment"> *</span>00057 <span class="comment"> * Revision 1.4  2002/09/16 01:08:59  robertj</span>00058 <span class="comment"> * Added #define so can select if #pragma interface/implementation is used on</span>00059 <span class="comment"> *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.</span>00060 <span class="comment"> *</span>00061 <span class="comment"> * Revision 1.3  2002/08/29 06:51:11  robertj</span>00062 <span class="comment"> * Added optimisiation, separate mutex for toBeRemoved list.</span>00063 <span class="comment"> *</span>00064 <span class="comment"> * Revision 1.2  2002/05/06 00:44:45  robertj</span>00065 <span class="comment"> * Made the lock/unlock read only const so can be used in const functions.</span>00066 <span class="comment"> *</span>00067 <span class="comment"> * Revision 1.1  2002/05/01 04:16:43  robertj</span>00068 <span class="comment"> * Added thread safe collection classes.</span>00069 <span class="comment"> *</span>00070 <span class="comment"> */</span>00071  00072 <span class="preprocessor">#ifndef _SAFE_COLLECTION_H</span>00073 <span class="preprocessor"></span><span class="preprocessor">#define _SAFE_COLLECTION_H</span>00074 <span class="preprocessor"></span>00075 <span class="preprocessor">#ifdef P_USE_PRAGMA</span>00076 <span class="preprocessor"></span><span class="preprocessor">#pragma interface</span>00077 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00078 <span class="preprocessor"></span>00079 <a name="l00138"></a><a class="code" href="classPSafeObject.html">00138</a> <span class="keyword">class </span><a class="code" href="classPSafeObject.html">PSafeObject</a> : <span class="keyword">public</span> <a class="code" href="classPObject.html">PObject</a>00139 {00140     <a class="code" href="object_8h.html#a27">PCLASSINFO</a>(<a class="code" href="classPSafeObject.html">PSafeObject</a>, <a class="code" href="classPObject.html">PObject</a>);00141   <span class="keyword">public</span>:00146     <a class="code" href="classPSafeObject.html#z319_0">PSafeObject</a>();00148 00169     BOOL <a class="code" href="classPSafeObject.html#z321_0">SafeReference</a>();00170 00178     <span class="keywordtype">void</span> <a class="code" href="classPSafeObject.html#z321_1">SafeDereference</a>();00179 00197     BOOL <a class="code" href="classPSafeObject.html#z321_2">LockReadOnly</a>() <span class="keyword">const</span>;00198 00209     <span class="keywordtype">void</span> <a class="code" href="classPSafeObject.html#z321_3">UnlockReadOnly</a>() <span class="keyword">const</span>;00210 00228     BOOL <a class="code" href="classPSafeObject.html#z321_4">LockReadWrite</a>();00229 00240     <span class="keywordtype">void</span> <a class="code" href="classPSafeObject.html#z321_5">UnlockReadWrite</a>();00241 00251     <span class="keywordtype">void</span> <a class="code" href="classPSafeObject.html#z321_6">SafeRemove</a>();00252 00260     BOOL <a class="code" href="classPSafeObject.html#z321_7">SafelyCanBeDeleted</a>() <span class="keyword">const</span>;00262 00263   <span class="keyword">protected</span>:<a name="l00264"></a><a class="code" href="classPSafeObject.html#n0">00264</a>     <span class="keyword">mutable</span> <a class="code" href="classPMutex.html">PMutex</a>          <a class="code" href="classPSafeObject.html#n0">safetyMutex</a>;<a name="l00265"></a><a class="code" href="classPSafeObject.html#n1">00265</a>             <span class="keywordtype">unsigned</span>        <a class="code" href="classPSafeObject.html#n1">safeReferenceCount</a>;<a name="l00266"></a><a class="code" href="classPSafeObject.html#n2">00266</a>             BOOL            <a class="code" href="classPSafeObject.html#n2">safelyBeingRemoved</a>;<a name="l00267"></a><a class="code" href="classPSafeObject.html#n3">00267</a>     <span class="keyword">mutable</span> <a class="code" href="classPReadWriteMutex.html">PReadWriteMutex</a> <a class="code" href="classPSafeObject.html#n3">safeInUseFlag</a>;00268 };00269 00270 <a name="l00273"></a><a class="code" href="classPSafeLockReadOnly.html">00273</a> <span class="keyword">class </span><a class="code" href="classPSafeLockReadOnly.html">PSafeLockReadOnly</a>00274 {00275   <span class="keyword">public</span>:<a name="l00276"></a><a class="code" href="classPSafeLockReadOnly.html#a0">00276</a>     <a class="code" href="classPSafeLockReadOnly.html#a0">PSafeLockReadOnly</a>(<span class="keyword">const</span> <a class="code" href="classPSafeObject.html">PSafeObject</a> &amp; object)00277       : <a class="code" href="classPSafeLockReadOnly.html#n0">safeObject</a>((<a class="code" href="classPSafeObject.html">PSafeObject</a> &amp;)object)00278     {00279       <a class="code" href="classPSafeLockReadOnly.html#n1">locked</a> = <a class="code" href="classPSafeLockReadOnly.html#n0">safeObject</a>.<a class="code" href="classPSafeObject.html#z321_2">LockReadOnly</a>();00280     }<a name="l00281"></a><a class="code" href="classPSafeLockReadOnly.html#a1">00281</a>     <a class="code" href="classPSafeLockReadOnly.html#a1">~PSafeLockReadOnly</a>()00282     {00283       <span class="keywordflow">if</span> (locked)00284         <a class="code" href="classPSafeLockReadOnly.html#n0">safeObject</a>.<a class="code" href="classPSafeObject.html#z321_3">UnlockReadOnly</a>();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -