aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/a03382.html
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--docs/doxygen/nel/a03382.html328
1 files changed, 328 insertions, 0 deletions
diff --git a/docs/doxygen/nel/a03382.html b/docs/doxygen/nel/a03382.html
new file mode 100644
index 00000000..1811e263
--- /dev/null
+++ b/docs/doxygen/nel/a03382.html
@@ -0,0 +1,328 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
+<title>NeL: NLMISC::CSharedMemory class Reference</title>
+<link href="doxygen.css" rel="stylesheet" type="text/css">
+</head><body>
+<!-- Generated by Doxygen 1.3.6 -->
+<div class="qindex"> <form class="search" action="search.php" method="get">
+<a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a> | <span class="search"><u>S</u>earch&nbsp;for&nbsp;<input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
+<h1>NLMISC::CSharedMemory Class Reference</h1><code>#include &lt;<a class="el" href="a06383.html">shared_memory.h</a>&gt;</code>
+<p>
+<hr><a name="_details"></a><h2>Detailed Description</h2>
+Encapsulation of shared memory APIs. Using file mapping under Windows, System V shared memory (shm) under Linux.<p>
+Note: under Linux, an option could be added to prevent a segment to be swapped out.<p>
+<dl compact><dt><b>Author:</b></dt><dd>Olivier Cado <p>
+Nevrax France </dd></dl>
+<dl compact><dt><b>Date:</b></dt><dd>2002 </dd></dl>
+
+<p>
+
+<p>
+Definition at line <a class="el" href="a06383.html#l00068">68</a> of file <a class="el" href="a06383.html">shared_memory.h</a>.<table border=0 cellpadding=0 cellspacing=0>
+<tr><td></td></tr>
+<tr><td colspan=2><br><h2>Static Public Member Functions</h2></td></tr>
+<tr><td class="memItemLeft" nowrap align=right valign=top>void *&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a03382.html#NLMISC_1_1CSharedMemorye0">accessSharedMemory</a> (<a class="el" href="a05378.html#a232">TSharedMemId</a> sharedMemId)</td></tr>
+
+<tr><td class="memItemLeft" nowrap align=right valign=top>bool&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a03382.html#NLMISC_1_1CSharedMemorye1">closeSharedMemory</a> (void *accessAddress)</td></tr>
+
+<tr><td class="memItemLeft" nowrap align=right valign=top>void *&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a03382.html#NLMISC_1_1CSharedMemorye2">createSharedMemory</a> (<a class="el" href="a05378.html#a232">TSharedMemId</a> sharedMemId, <a class="el" href="a04558.html#a11">uint32</a> <a class="el" href="a04223.html#a587">size</a>)</td></tr>
+
+<tr><td class="memItemLeft" nowrap align=right valign=top>void&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a03382.html#NLMISC_1_1CSharedMemorye3">destroySharedMemory</a> (<a class="el" href="a05378.html#a232">TSharedMemId</a> sharedMemId, bool force=false)</td></tr>
+
+</table>
+<hr><h2>Member Function Documentation</h2>
+<a class="anchor" name="NLMISC_1_1CSharedMemorye0" doxytag="NLMISC::CSharedMemory::accessSharedMemory" ></a><p>
+<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
+ <tr>
+ <td class="mdRow">
+ <table cellpadding="0" cellspacing="0" border="0">
+ <tr>
+ <td class="md" nowrap valign="top"> void * NLMISC::CSharedMemory::accessSharedMemory </td>
+ <td class="md" valign="top">(&nbsp;</td>
+ <td class="md" nowrap valign="top"><a class="el" href="a05378.html#a232">TSharedMemId</a>&nbsp;</td>
+ <td class="mdname1" valign="top" nowrap> <em>sharedMemId</em> </td>
+ <td class="md" valign="top">&nbsp;)&nbsp;</td>
+ <td class="md" nowrap><code> [static]</code></td>
+ </tr>
+
+ </table>
+ </td>
+ </tr>
+</table>
+<table cellspacing=5 cellpadding=0 border=0>
+ <tr>
+ <td>
+ &nbsp;
+ </td>
+ <td>
+
+<p>
+Get access to an existing shared memory segment. The id must be used. <dl compact><dt><b>Returns:</b></dt><dd>Access address of the segment. Its size was determined at the creation.</dd></dl>
+
+<p>
+Definition at line <a class="el" href="a06382.html#l00100">100</a> of file <a class="el" href="a06382.html">shared_memory.cpp</a>.
+<p>
+References <a class="el" href="a06383.html#l00041">NLMISC::TSharedMemId</a>.
+<p>
+<div class="fragment"><pre>00101 {
+00102 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span>
+00103 <span class="preprocessor"></span>
+00104 <span class="comment">// Open the existing file mapping by name</span>
+00105 HANDLE hMapFile = OpenFileMapping( FILE_MAP_ALL_ACCESS, <span class="keyword">false</span>, sharedMemId );
+00106 <span class="keywordflow">if</span> ( hMapFile == NULL )
+00107 <span class="keywordflow">return</span> NULL;
+00108 <span class="comment">//nldebug( "SHDMEM: Opening smid %s --&gt; mapFile %p", sharedMemId, hMapFile );</span>
+00109
+00110 <span class="comment">// Map the file into memory address space</span>
+00111 <span class="keywordtype">void</span> *accessAddress = MapViewOfFile( hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
+00112 AccessAddressesToHandles.insert( make_pair( accessAddress, hMapFile ) );
+00113 <span class="keywordflow">return</span> accessAddress;
+00114
+00115 <span class="preprocessor">#else</span>
+00116 <span class="preprocessor"></span>
+00117 <span class="comment">// Open an existing shared memory segment</span>
+00118 <span class="keywordtype">int</span> shmid = shmget( sharedMemId, 0, 0666 );
+00119 <span class="keywordflow">if</span> ( shmid == -1 )
+00120 <span class="keywordflow">return</span> NULL;
+00121
+00122 <span class="comment">// Map the segment into memory address space</span>
+00123 <span class="keywordtype">void</span> *accessAddress = (<span class="keywordtype">void</span>*)shmat( shmid, 0, 0 );
+00124 <span class="keywordflow">if</span> ( accessAddress == (<span class="keywordtype">void</span>*)-1 )
+00125 <span class="keywordflow">return</span> NULL;
+00126 <span class="keywordflow">else</span>
+00127 <span class="keywordflow">return</span> accessAddress;
+00128
+00129 <span class="preprocessor">#endif</span>
+00130 <span class="preprocessor"></span>}
+</pre></div> </td>
+ </tr>
+</table>
+<a class="anchor" name="NLMISC_1_1CSharedMemorye1" doxytag="NLMISC::CSharedMemory::closeSharedMemory" ></a><p>
+<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
+ <tr>
+ <td class="mdRow">
+ <table cellpadding="0" cellspacing="0" border="0">
+ <tr>
+ <td class="md" nowrap valign="top"> bool NLMISC::CSharedMemory::closeSharedMemory </td>
+ <td class="md" valign="top">(&nbsp;</td>
+ <td class="md" nowrap valign="top">void *&nbsp;</td>
+ <td class="mdname1" valign="top" nowrap> <em>accessAddress</em> </td>
+ <td class="md" valign="top">&nbsp;)&nbsp;</td>
+ <td class="md" nowrap><code> [static]</code></td>
+ </tr>
+
+ </table>
+ </td>
+ </tr>
+</table>
+<table cellspacing=5 cellpadding=0 border=0>
+ <tr>
+ <td>
+ &nbsp;
+ </td>
+ <td>
+
+<p>
+Close a shared memory segment, given the address returned by <a class="el" href="a03382.html#NLMISC_1_1CSharedMemorye2">createSharedMemory()</a> or <a class="el" href="a03382.html#NLMISC_1_1CSharedMemorye0">accessSharedMemory()</a>. Must be called by each process that called <a class="el" href="a03382.html#NLMISC_1_1CSharedMemorye2">createSharedMemory()</a> or <a class="el" href="a03382.html#NLMISC_1_1CSharedMemorye0">accessSharedMemory()</a>.
+<p>
+Definition at line <a class="el" href="a06382.html#l00136">136</a> of file <a class="el" href="a06382.html">shared_memory.cpp</a>.
+<p>
+References <a class="el" href="a05622.html#l00135">nlwarning</a>.
+<p>
+<div class="fragment"><pre>00137 {
+00138 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span>
+00139 <span class="preprocessor"></span>
+00140 <span class="keywordtype">bool</span> result = <span class="keyword">true</span>;
+00141
+00142 <span class="comment">// Unmap the file from memory address space</span>
+00143 <span class="keywordflow">if</span> ( UnmapViewOfFile( accessAddress ) == 0 )
+00144 {
+00145 <a class="code" href="a04199.html#a2">nlwarning</a>( <span class="stringliteral">"SHDMEM: UnmapViewOfFile failed: error %u"</span>, GetLastError() );
+00146 result = <span class="keyword">false</span>;
+00147 }
+00148
+00149 <span class="comment">// Close the corresponding handle</span>
+00150 map&lt;void*,HANDLE&gt;::iterator im = AccessAddressesToHandles.find( accessAddress );
+00151 <span class="keywordflow">if</span> ( im != AccessAddressesToHandles.end() )
+00152 {
+00153 <span class="comment">//nldebug( "SHDMEM: CloseHandle mapFile %u", (*im).second );</span>
+00154 <span class="keywordflow">if</span> ( ! CloseHandle( (*im).second ) )
+00155 <a class="code" href="a04199.html#a2">nlwarning</a>( <span class="stringliteral">"SHDMEM: CloseHandle failed: error %u, mapFile %u"</span>, GetLastError(), (*im).second );
+00156 AccessAddressesToHandles.erase( im );
+00157 <span class="keywordflow">return</span> result;
+00158 }
+00159 <span class="keywordflow">else</span>
+00160 {
+00161 <span class="keywordflow">return</span> <span class="keyword">false</span>;
+00162 }
+00163
+00164 <span class="preprocessor">#else</span>
+00165 <span class="preprocessor"></span>
+00166 <span class="comment">// Detach the shared memory segment</span>
+00167 <span class="keywordflow">return</span> ( shmdt( accessAddress ) != -1 );
+00168
+00169 <span class="preprocessor">#endif</span>
+00170 <span class="preprocessor"></span>}
+</pre></div> </td>
+ </tr>
+</table>
+<a class="anchor" name="NLMISC_1_1CSharedMemorye2" doxytag="NLMISC::CSharedMemory::createSharedMemory" ></a><p>
+<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
+ <tr>
+ <td class="mdRow">
+ <table cellpadding="0" cellspacing="0" border="0">
+ <tr>
+ <td class="md" nowrap valign="top"> void * NLMISC::CSharedMemory::createSharedMemory </td>
+ <td class="md" valign="top">(&nbsp;</td>
+ <td class="md" nowrap valign="top"><a class="el" href="a05378.html#a232">TSharedMemId</a>&nbsp;</td>
+ <td class="mdname" nowrap> <em>sharedMemId</em>, </td>
+ </tr>
+ <tr>
+ <td class="md" nowrap align="right"></td>
+ <td></td>
+ <td class="md" nowrap><a class="el" href="a04558.html#a11">uint32</a>&nbsp;</td>
+ <td class="mdname" nowrap> <em>size</em></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td class="md">)&nbsp;</td>
+ <td class="md" colspan="2"><code> [static]</code></td>
+ </tr>
+
+ </table>
+ </td>
+ </tr>
+</table>
+<table cellspacing=5 cellpadding=0 border=0>
+ <tr>
+ <td>
+ &nbsp;
+ </td>
+ <td>
+
+<p>
+Create a shared memory segment and get access to it. The id must not be used. The id 0x3a732235 is used by the NeL memory manager. <dl compact><dt><b>Returns:</b></dt><dd>Access address of the segment of the choosen size</dd></dl>
+
+<p>
+Definition at line <a class="el" href="a06382.html#l00055">55</a> of file <a class="el" href="a06382.html">shared_memory.cpp</a>.
+<p>
+References <a class="el" href="a05622.html#l00135">nlwarning</a>, <a class="el" href="a06382.html#l00048">NLMISC::SharedMemIdsToShmids</a>, <a class="el" href="a05646.html#l00645">size</a>, <a class="el" href="a06383.html#l00041">NLMISC::TSharedMemId</a>, and <a class="el" href="a05981.html#l00100">uint32</a>.
+<p>
+<div class="fragment"><pre>00056 {
+00057 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span>
+00058 <span class="preprocessor"></span>
+00059 <span class="comment">// Create a file mapping backed by the virtual memory swap file (not a data file)</span>
+00060 HANDLE hMapFile = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, sharedMemId );
+00061 <span class="keywordflow">if</span> ( (hMapFile == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS) )
+00062 {
+00063 <a class="code" href="a04199.html#a2">nlwarning</a>( <span class="stringliteral">"SHDMEM: Cannot create file mapping: error %u, mapFile %p"</span>, GetLastError(), hMapFile );
+00064 <span class="keywordflow">return</span> NULL;
+00065 }
+00066 <span class="comment">//else</span>
+00067 <span class="comment">// nldebug( "SHDMEM: Creating smid %s --&gt; mapFile %p", sharedMemId, hMapFile );</span>
+00068
+00069
+00070 <span class="comment">// Map the file into memory address space</span>
+00071 <span class="keywordtype">void</span> *accessAddress = MapViewOfFile( hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
+00072 AccessAddressesToHandles.insert( make_pair( accessAddress, hMapFile ) );
+00073 <span class="comment">/*if ( accessAddress == NULL )</span>
+00074 <span class="comment"> {</span>
+00075 <span class="comment"> nlwarning( "SHDMEM: Cannot map view of file: error %u", GetLastError() );</span>
+00076 <span class="comment"> }*/</span>
+00077 <span class="keywordflow">return</span> accessAddress;
+00078
+00079 <span class="preprocessor">#else</span>
+00080 <span class="preprocessor"></span>
+00081 <span class="comment">// Create a shared memory segment</span>
+00082 <span class="keywordtype">int</span> shmid = shmget( sharedMemId, size, IPC_CREAT | IPC_EXCL | 0666 );
+00083 <span class="keywordflow">if</span> ( shmid == -1 )
+00084 <span class="keywordflow">return</span> NULL;
+00085 <a class="code" href="a05378.html#a36">SharedMemIdsToShmids</a>.insert( make_pair( sharedMemId, shmid ) );
+00086
+00087 <span class="comment">// Map the segment into memory address space</span>
+00088 <span class="keywordtype">void</span> *accessAddress = (<span class="keywordtype">void</span>*)shmat( shmid, 0, 0 );
+00089 <span class="keywordflow">if</span> ( accessAddress == (<span class="keywordtype">void</span>*)-1 )
+00090 <span class="keywordflow">return</span> NULL;
+00091 <span class="keywordflow">else</span>
+00092 <span class="keywordflow">return</span> accessAddress;
+00093 <span class="preprocessor">#endif</span>
+00094 <span class="preprocessor"></span>}
+</pre></div> </td>
+ </tr>
+</table>
+<a class="anchor" name="NLMISC_1_1CSharedMemorye3" doxytag="NLMISC::CSharedMemory::destroySharedMemory" ></a><p>
+<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
+ <tr>
+ <td class="mdRow">
+ <table cellpadding="0" cellspacing="0" border="0">
+ <tr>
+ <td class="md" nowrap valign="top"> void NLMISC::CSharedMemory::destroySharedMemory </td>
+ <td class="md" valign="top">(&nbsp;</td>
+ <td class="md" nowrap valign="top"><a class="el" href="a05378.html#a232">TSharedMemId</a>&nbsp;</td>
+ <td class="mdname" nowrap> <em>sharedMemId</em>, </td>
+ </tr>
+ <tr>
+ <td class="md" nowrap align="right"></td>
+ <td></td>
+ <td class="md" nowrap>bool&nbsp;</td>
+ <td class="mdname" nowrap> <em>force</em> = false</td>
+ </tr>
+ <tr>
+ <td></td>
+ <td class="md">)&nbsp;</td>
+ <td class="md" colspan="2"><code> [static]</code></td>
+ </tr>
+
+ </table>
+ </td>
+ </tr>
+</table>
+<table cellspacing=5 cellpadding=0 border=0>
+ <tr>
+ <td>
+ &nbsp;
+ </td>
+ <td>
+
+<p>
+Destroy a shared memory segment (must be called by the process that created the segment, not by the accessors).<p>
+"Rescue feature": set "force" to true if a segment was created and left out of control (meaning a new <a class="el" href="a03382.html#NLMISC_1_1CSharedMemorye2">createSharedMemory()</a> with the same sharedMemId fails), but before, make sure the segment really belongs to you!<p>
+Note: this method does nothing under Windows, destroying is automatic.
+<p>
+Definition at line <a class="el" href="a06382.html#l00177">177</a> of file <a class="el" href="a06382.html">shared_memory.cpp</a>.
+<p>
+References <a class="el" href="a06382.html#l00048">NLMISC::SharedMemIdsToShmids</a>, and <a class="el" href="a06383.html#l00041">NLMISC::TSharedMemId</a>.
+<p>
+<div class="fragment"><pre>00178 {
+00179 <span class="preprocessor">#ifndef NL_OS_WINDOWS</span>
+00180 <span class="preprocessor"></span> <span class="comment">// Set the segment to auto-destroying (when the last process detaches)</span>
+00181 map&lt;TSharedMemId,int&gt;::iterator im = <a class="code" href="a05378.html#a36">SharedMemIdsToShmids</a>.find( sharedMemId );
+00182 <span class="keywordflow">if</span> ( im != <a class="code" href="a05378.html#a36">SharedMemIdsToShmids</a>.end() )
+00183 {
+00184 <span class="comment">// Destroy the segment created before</span>
+00185 shmctl( (*im).second, IPC_RMID, 0 );
+00186 <a class="code" href="a05378.html#a36">SharedMemIdsToShmids</a>.erase( im );
+00187 }
+00188 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( force )
+00189 {
+00190 <span class="comment">// Open and destroy the segment</span>
+00191 <span class="keywordtype">int</span> shmid = shmget( sharedMemId, 0, 0666 );
+00192 <span class="keywordflow">if</span> ( shmid != -1 )
+00193 {
+00194 <span class="comment">// Destroy the segment</span>
+00195 shmctl( shmid, IPC_RMID, 0 );
+00196 }
+00197 }
+00198 <span class="preprocessor">#endif</span>
+00199 <span class="preprocessor"></span>}
+</pre></div> </td>
+ </tr>
+</table>
+<hr>The documentation for this class was generated from the following files:<ul>
+<li><a class="el" href="a06383.html">shared_memory.h</a><li><a class="el" href="a06382.html">shared_memory.cpp</a></ul>
+<hr size="1"><address style="align: right;"><small>Generated on Tue Mar 16 13:32:41 2004 for NeL by
+<a href="http://www.doxygen.org/index.html">
+<img src="doxygen.png" alt="doxygen" align="middle" border=0 >
+</a>1.3.6 </small></address>
+</body>
+</html>