Home | History | Annotate | Download | only in oscl_html
      1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
      3 <title>oscl_mutex.h Source File</title>
      4 <link href="doxygen.css" rel="stylesheet" type="text/css">
      5 </head><body>
      6 <!-- Generated by Doxygen 1.2.18 -->
      7 <center>
      8 <a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; </center>
      9 <hr><h1>oscl_mutex.h</h1><a href="oscl__mutex_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
     10 00002 <span class="comment">// -*- c++ -*-</span>
     11 00003 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
     12 00004 
     13 00005 <span class="comment">//                     O S C L _ M U T E X</span>
     14 00006 
     15 00007 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
     16 00008 
     17 00015 <span class="preprocessor">#ifndef OSCL_MUTEX_H_INCLUDED</span>
     18 00016 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_MUTEX_H_INCLUDED</span>
     19 00017 <span class="preprocessor"></span>
     20 00018 <span class="preprocessor">#ifndef OSCLCONFIG_PROC_H_INCLUDED</span>
     21 00019 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="osclconfig__proc_8h.html">osclconfig_proc.h</a>"</span>
     22 00020 <span class="preprocessor">#endif</span>
     23 00021 <span class="preprocessor"></span><span class="preprocessor">#ifndef OSCL_TYPES_H_INCLUDED</span>
     24 00022 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__types_8h.html">oscl_types.h</a>"</span>
     25 00023 <span class="preprocessor">#endif</span>
     26 00024 <span class="preprocessor"></span><span class="preprocessor">#ifndef OSCL_BASE_H_INCLUDED</span>
     27 00025 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__base_8h.html">oscl_base.h</a>"</span>
     28 00026 <span class="preprocessor">#endif</span>
     29 00027 <span class="preprocessor"></span><span class="preprocessor">#ifndef OSCL_THREAD_H_INCLUDED</span>
     30 00028 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__thread_8h.html">oscl_thread.h</a>"</span>
     31 00029 <span class="preprocessor">#endif</span>
     32 00030 <span class="preprocessor"></span><span class="preprocessor">#ifndef OSCL_LOCK_BASE_H_INCLUDED</span>
     33 00031 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__lock__base_8h.html">oscl_lock_base.h</a>"</span>
     34 00032 <span class="preprocessor">#endif</span>
     35 00033 <span class="preprocessor"></span>
     36 00034 
     37 <a name="l00038"></a><a class="code" href="classOsclMutex.html">00038</a> <span class="keyword">class </span><a class="code" href="classOsclMutex.html">OsclMutex</a> : <span class="keyword">public</span> <a class="code" href="classOsclLockBase.html">OsclLockBase</a>
     38 00039 {
     39 00040     <span class="keyword">public</span>:
     40 00041 
     41 00045         OSCL_IMPORT_REF <a class="code" href="classOsclMutex.html#a0">OsclMutex</a>();
     42 00046 
     43 00050         OSCL_IMPORT_REF <span class="keyword">virtual</span> <a class="code" href="classOsclMutex.html#a1">~OsclMutex</a>();
     44 00051 
     45 00060         OSCL_IMPORT_REF <a class="code" href="classOsclProcStatus.html#s35">OsclProcStatus::eOsclProcError</a> <a class="code" href="classOsclMutex.html#a2">Create</a>(<span class="keywordtype">void</span>);
     46 00061 
     47 00062 
     48 00070         OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOsclMutex.html#a3">Lock</a>();
     49 00071 
     50 00083         OSCL_IMPORT_REF <a class="code" href="classOsclProcStatus.html#s35">OsclProcStatus::eOsclProcError</a> <a class="code" href="classOsclMutex.html#a4">TryLock</a>();
     51 00084 
     52 00085 
     53 00093         OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOsclMutex.html#a5">Unlock</a>();
     54 00094 
     55 00095 
     56 00104         OSCL_IMPORT_REF <a class="code" href="classOsclProcStatus.html#s35">OsclProcStatus::eOsclProcError</a> <a class="code" href="classOsclMutex.html#a6">Close</a>(<span class="keywordtype">void</span>);
     57 00105 
     58 00106     <span class="keyword">private</span>:
     59 00107 
     60 00115         <a class="code" href="classOsclProcStatus.html#s35">OsclProcStatus::eOsclProcError</a> ErrorMapping(int32 Error);
     61 00116 
     62 00117         TOsclMutexObject    ObjMutex;
     63 00118         <span class="keywordtype">bool</span> bCreated;
     64 00119 
     65 00120 };
     66 00121 
     67 00136 <span class="preprocessor">#if !OSCL_HAS_NON_PREEMPTIVE_THREAD_SUPPORT</span>
     68 00137 <span class="preprocessor"></span><span class="comment">//In pre-emptive threading, OsclNoYieldMutex is identical to OsclMutex</span>
     69 <a name="l00138"></a><a class="code" href="oscl__mutex_8h.html#a0">00138</a> <span class="keyword">typedef</span> <a class="code" href="classOsclMutex.html">OsclMutex</a> <a class="code" href="classOsclMutex.html">OsclNoYieldMutex</a>;
     70 00139 <span class="preprocessor">#else</span>
     71 00140 <span class="preprocessor"></span><span class="comment">//In non-pre-emptive threading, OsclNoYieldMutex is a NO-OP.</span>
     72 00141 <span class="keyword">class </span>OsclNoYieldMutex : <span class="keyword">public</span> <a class="code" href="classOsclLockBase.html">OsclLockBase</a>
     73 00142 {
     74 00143     <span class="keyword">public</span>:
     75 00144 
     76 00148         <a class="code" href="oscl__mutex_8h.html#a0">OsclNoYieldMutex</a>()
     77 00149         {
     78 00150 <span class="preprocessor">#ifndef NDEBUG</span>
     79 00151 <span class="preprocessor"></span>            iNumLock = 0;
     80 00152             bCreated = <span class="keyword">false</span>;
     81 00153 <span class="preprocessor">#endif</span>
     82 00154 <span class="preprocessor"></span>        }
     83 00155 
     84 00159         <span class="keyword">virtual</span> ~OsclNoYieldMutex()
     85 00160         {}
     86 00161 
     87 00170         <a class="code" href="classOsclProcStatus.html#s35">OsclProcStatus::eOsclProcError</a> <a class="code" href="classOsclMutex.html#a2">Create</a>(<span class="keywordtype">void</span>)
     88 00171         {
     89 00172 <span class="preprocessor">#ifndef NDEBUG</span>
     90 00173 <span class="preprocessor"></span>            <span class="keywordflow">if</span> (bCreated)
     91 00174                 <span class="keywordflow">return</span> <a class="code" href="classOsclProcStatus.html#s35s21">OsclProcStatus::INVALID_OPERATION_ERROR</a>;
     92 00175             bCreated = <span class="keyword">true</span>;
     93 00176 <span class="preprocessor">#endif</span>
     94 00177 <span class="preprocessor"></span>            <span class="keywordflow">return</span> <a class="code" href="classOsclProcStatus.html#s35s0">OsclProcStatus::SUCCESS_ERROR</a>;
     95 00178         }
     96 00179 
     97 00180 
     98 00188         <span class="keywordtype">void</span> <a class="code" href="classOsclMutex.html#a3">Lock</a>()
     99 00189         {
    100 00190 <span class="preprocessor">#ifndef NDEBUG</span>
    101 00191 <span class="preprocessor"></span>            <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(bCreated);
    102 00192             <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(iNumLock == 0);<span class="comment">//detect deadlock condition.</span>
    103 00193             iNumLock++;
    104 00194 <span class="preprocessor">#endif</span>
    105 00195 <span class="preprocessor"></span>        }
    106 00196 
    107 00208         <a class="code" href="classOsclProcStatus.html#s35">OsclProcStatus::eOsclProcError</a> <a class="code" href="classOsclMutex.html#a4">TryLock</a>()
    108 00209         {
    109 00210 <span class="preprocessor">#ifndef NDEBUG</span>
    110 00211 <span class="preprocessor"></span>            <span class="keywordflow">if</span> (!bCreated)
    111 00212                 <span class="keywordflow">return</span> <a class="code" href="classOsclProcStatus.html#s35s21">OsclProcStatus::INVALID_OPERATION_ERROR</a>;
    112 00213             <span class="keywordflow">if</span> (iNumLock)
    113 00214                 <span class="keywordflow">return</span> <a class="code" href="classOsclProcStatus.html#s35s29">OsclProcStatus::MUTEX_LOCKED_ERROR</a>;
    114 00215             <span class="keywordflow">else</span>
    115 00216                 <a class="code" href="classOsclMutex.html#a3">Lock</a>();
    116 00217             <span class="keywordflow">return</span> <a class="code" href="classOsclProcStatus.html#s35s0">OsclProcStatus::SUCCESS_ERROR</a>;
    117 00218 <span class="preprocessor">#endif</span>
    118 00219 <span class="preprocessor"></span>        }
    119 00220 
    120 00221 
    121 00229         <span class="keywordtype">void</span> <a class="code" href="classOsclMutex.html#a5">Unlock</a>()
    122 00230         {
    123 00231 <span class="preprocessor">#ifndef NDEBUG</span>
    124 00232 <span class="preprocessor"></span>            <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(bCreated);
    125 00233             <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(iNumLock);
    126 00234             <span class="keywordflow">if</span> (iNumLock &gt; 0)
    127 00235                 iNumLock--;
    128 00236 <span class="preprocessor">#endif</span>
    129 00237 <span class="preprocessor"></span>        }
    130 00238 
    131 00239 
    132 00248         <a class="code" href="classOsclProcStatus.html#s35">OsclProcStatus::eOsclProcError</a> <a class="code" href="classOsclMutex.html#a6">Close</a>(<span class="keywordtype">void</span>)
    133 00249         {
    134 00250 <span class="preprocessor">#ifndef NDEBUG</span>
    135 00251 <span class="preprocessor"></span>            <span class="keywordflow">if</span> (!bCreated)
    136 00252                 <span class="keywordflow">return</span> <a class="code" href="classOsclProcStatus.html#s35s21">OsclProcStatus::INVALID_OPERATION_ERROR</a>;
    137 00253             bCreated = <span class="keyword">false</span>;
    138 00254 <span class="preprocessor">#endif</span>
    139 00255 <span class="preprocessor"></span>            <span class="keywordflow">return</span> <a class="code" href="classOsclProcStatus.html#s35s0">OsclProcStatus::SUCCESS_ERROR</a>;
    140 00256         }
    141 00257 
    142 00258     <span class="keyword">private</span>:
    143 00259 
    144 00260 <span class="preprocessor">#ifndef NDEBUG</span>
    145 00261 <span class="preprocessor"></span>        uint32 iNumLock;
    146 00262         <span class="keywordtype">bool</span> bCreated;
    147 00263 <span class="preprocessor">#endif</span>
    148 00264 <span class="preprocessor"></span>
    149 00265 };
    150 00266 <span class="preprocessor">#endif //OSCL_HAS_NON_PREEMPTIVE_THREAD_SUPPORT</span>
    151 00267 <span class="preprocessor"></span>
    152 <a name="l00271"></a><a class="code" href="classOsclThreadLock.html">00271</a> <span class="keyword">class </span><a class="code" href="classOsclThreadLock.html">OsclThreadLock</a>: <span class="keyword">public</span> <a class="code" href="classOsclLockBase.html">OsclLockBase</a>
    153 00272 {
    154 00273     <span class="keyword">public</span>:
    155 00274         OSCL_IMPORT_REF <a class="code" href="classOsclThreadLock.html#a0">OsclThreadLock</a>();
    156 00275         OSCL_IMPORT_REF <span class="keyword">virtual</span> <a class="code" href="classOsclThreadLock.html#a1">~OsclThreadLock</a>();
    157 00276         OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOsclThreadLock.html#a2">Lock</a>();
    158 00277         OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOsclThreadLock.html#a3">Unlock</a>();
    159 00278     <span class="keyword">private</span>:
    160 00279         <a class="code" href="classOsclMutex.html">OsclMutex</a> iMutex;
    161 00280 };
    162 00281 
    163 00282 <span class="preprocessor">#endif</span>
    164 00283 <span class="preprocessor"></span>
    165 00284 
    166 00285 
    167 </pre></div><hr size="1"><img src="pvlogo_small.jpg"><address style="align: right;"><small>OSCL API</small>
    168 <address style="align: left;"><small>Posting Version: OPENCORE_20090310 </small>
    169 </small></address>
    170 </body>
    171 </html>
    172