155 lines
10 KiB
HTML
155 lines
10 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>SFML - Simple and Fast Multimedia Library</title>
|
|
<meta http-equiv="Content-Type" content="text/html;"/>
|
|
<meta charset="utf-8"/>
|
|
<!--<link rel='stylesheet' type='text/css' href="https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
|
|
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="banner-container">
|
|
<div id="banner">
|
|
<span id="sfml">SFML 2.5.1</span>
|
|
</div>
|
|
</div>
|
|
<div id="content">
|
|
<!-- Generated by Doxygen 1.8.14 -->
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="navrow2" class="tabs2">
|
|
<ul class="tablist">
|
|
<li><a href="annotated.html"><span>Class List</span></a></li>
|
|
<li><a href="classes.html"><span>Class Index</span></a></li>
|
|
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
|
|
<li><a href="functions.html"><span>Class Members</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><b>sf</b></li><li class="navelem"><a class="el" href="classsf_1_1Lock.html">Lock</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#pub-methods">Public Member Functions</a> |
|
|
<a href="classsf_1_1Lock-members.html">List of all members</a> </div>
|
|
<div class="headertitle">
|
|
<div class="title">sf::Lock Class Reference<div class="ingroups"><a class="el" href="group__system.html">System module</a></div></div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p>Automatic wrapper for locking and unlocking mutexes.
|
|
<a href="classsf_1_1Lock.html#details">More...</a></p>
|
|
|
|
<p><code>#include <<a class="el" href="Lock_8hpp_source.html">Lock.hpp</a>></code></p>
|
|
<div class="dynheader">
|
|
Inheritance diagram for sf::Lock:</div>
|
|
<div class="dyncontent">
|
|
<div class="center">
|
|
<img src="classsf_1_1Lock.png" usemap="#sf::Lock_map" alt=""/>
|
|
<map id="sf::Lock_map" name="sf::Lock_map">
|
|
<area href="classsf_1_1NonCopyable.html" title="Utility class that makes any derived class non-copyable. " alt="sf::NonCopyable" shape="rect" coords="0,0,105,24"/>
|
|
</map>
|
|
</div></div>
|
|
<table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
|
|
Public Member Functions</h2></td></tr>
|
|
<tr class="memitem:a1a4c5d7a15da61103d85c9aa7f118920"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Lock.html#a1a4c5d7a15da61103d85c9aa7f118920">Lock</a> (<a class="el" href="classsf_1_1Mutex.html">Mutex</a> &mutex)</td></tr>
|
|
<tr class="memdesc:a1a4c5d7a15da61103d85c9aa7f118920"><td class="mdescLeft"> </td><td class="mdescRight">Construct the lock with a target mutex. <a href="#a1a4c5d7a15da61103d85c9aa7f118920">More...</a><br /></td></tr>
|
|
<tr class="separator:a1a4c5d7a15da61103d85c9aa7f118920"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a8168b36323a18ccf5b6bc531d964aec5"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Lock.html#a8168b36323a18ccf5b6bc531d964aec5">~Lock</a> ()</td></tr>
|
|
<tr class="memdesc:a8168b36323a18ccf5b6bc531d964aec5"><td class="mdescLeft"> </td><td class="mdescRight">Destructor. <a href="#a8168b36323a18ccf5b6bc531d964aec5">More...</a><br /></td></tr>
|
|
<tr class="separator:a8168b36323a18ccf5b6bc531d964aec5"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p>Automatic wrapper for locking and unlocking mutexes. </p>
|
|
<p><a class="el" href="classsf_1_1Lock.html" title="Automatic wrapper for locking and unlocking mutexes. ">sf::Lock</a> is a RAII wrapper for <a class="el" href="classsf_1_1Mutex.html" title="Blocks concurrent access to shared resources from multiple threads. ">sf::Mutex</a>.</p>
|
|
<p>By unlocking it in its destructor, it ensures that the mutex will always be released when the current scope (most likely a function) ends. This is even more important when an exception or an early return statement can interrupt the execution flow of the function.</p>
|
|
<p>For maximum robustness, <a class="el" href="classsf_1_1Lock.html" title="Automatic wrapper for locking and unlocking mutexes. ">sf::Lock</a> should always be used to lock/unlock a mutex.</p>
|
|
<p>Usage example: </p><div class="fragment"><div class="line"><a class="code" href="classsf_1_1Mutex.html">sf::Mutex</a> mutex;</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> <span class="keyword">function</span>()</div><div class="line">{</div><div class="line"> <a class="code" href="classsf_1_1Lock.html">sf::Lock</a> lock(mutex); <span class="comment">// mutex is now locked</span></div><div class="line"></div><div class="line"> functionThatMayThrowAnException(); <span class="comment">// mutex is unlocked if this function throws</span></div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (someCondition)</div><div class="line"> <span class="keywordflow">return</span>; <span class="comment">// mutex is unlocked</span></div><div class="line"></div><div class="line">} <span class="comment">// mutex is unlocked</span></div></div><!-- fragment --><p>Because the mutex is not explicitly unlocked in the code, it may remain locked longer than needed. If the region of the code that needs to be protected by the mutex is not the entire function, a good practice is to create a smaller, inner scope so that the lock is limited to this part of the code.</p>
|
|
<div class="fragment"><div class="line"><a class="code" href="classsf_1_1Mutex.html">sf::Mutex</a> mutex;</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> <span class="keyword">function</span>()</div><div class="line">{</div><div class="line"> {</div><div class="line"> <a class="code" href="classsf_1_1Lock.html">sf::Lock</a> lock(mutex);</div><div class="line"> codeThatRequiresProtection();</div><div class="line"></div><div class="line"> } <span class="comment">// mutex is unlocked here</span></div><div class="line"></div><div class="line"> codeThatDoesntCareAboutTheMutex();</div><div class="line">}</div></div><!-- fragment --><p>Having a mutex locked longer than required is a bad practice which can lead to bad performances. Don't forget that when a mutex is locked, other threads may be waiting doing nothing until it is released.</p>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Mutex.html" title="Blocks concurrent access to shared resources from multiple threads. ">sf::Mutex</a> </dd></dl>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="Lock_8hpp_source.html#l00043">43</a> of file <a class="el" href="Lock_8hpp_source.html">Lock.hpp</a>.</p>
|
|
</div><h2 class="groupheader">Constructor & Destructor Documentation</h2>
|
|
<a id="a1a4c5d7a15da61103d85c9aa7f118920"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a1a4c5d7a15da61103d85c9aa7f118920">◆ </a></span>Lock()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">sf::Lock::Lock </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="classsf_1_1Mutex.html">Mutex</a> & </td>
|
|
<td class="paramname"><em>mutex</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">explicit</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Construct the lock with a target mutex. </p>
|
|
<p>The mutex passed to <a class="el" href="classsf_1_1Lock.html" title="Automatic wrapper for locking and unlocking mutexes. ">sf::Lock</a> is automatically locked.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">mutex</td><td><a class="el" href="classsf_1_1Mutex.html" title="Blocks concurrent access to shared resources from multiple threads. ">Mutex</a> to lock </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a8168b36323a18ccf5b6bc531d964aec5"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a8168b36323a18ccf5b6bc531d964aec5">◆ </a></span>~Lock()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">sf::Lock::~Lock </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Destructor. </p>
|
|
<p>The destructor of <a class="el" href="classsf_1_1Lock.html" title="Automatic wrapper for locking and unlocking mutexes. ">sf::Lock</a> automatically unlocks its mutex. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<hr/>The documentation for this class was generated from the following file:<ul>
|
|
<li><a class="el" href="Lock_8hpp_source.html">Lock.hpp</a></li>
|
|
</ul>
|
|
</div><!-- contents -->
|
|
</div>
|
|
<div id="footer-container">
|
|
<div id="footer">
|
|
SFML is licensed under the terms and conditions of the <a href="https://www.sfml-dev.org/license.php">zlib/png license</a>.<br>
|
|
Copyright © Laurent Gomila ::
|
|
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> ::
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|