1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3
4<head>
5<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
6<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 7.0.1.0 for Windows">
7<META http-equiv="Content-Style-Type" content="text/css">
8<title>OS_TryLockMutexFrom[RToW|WToR]</title>
9<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css">
10</head>
11
12<body>
13
14<h1 align="left">OS_TryLockMutexFrom[RToW|WToR] <IMG src="../../image/NTR.gif" align="middle"><IMG src="../../image/TWL.gif" align="middle"></h1>
15<h2>Syntax</h2>
16
17<dl>
18  <dd>
19<CODE>#include &lt;nitro/os.h&gt;</CODE><BR> <BR> <CODE>BOOL OS_TryLockMutexFromRToW( OSMutex* mutex );</CODE><BR> <BR> <CODE>BOOL OS_TryLockMutexFromWToR( OSMutex* mutex );</CODE></dd>
20</dl>
21
22<h2>Arguments</h2>
23<TABLE border="1" width="100%">
24  <TBODY>
25    <TR>
26      <TD width="13%"><CODE>mutex</CODE></TD>
27      <TD width="87%">Pointer to the <CODE>OSMutex</CODE> structure</TD>
28    </TR>
29  </TBODY>
30</TABLE>
31
32<h2>Return Values</h2>
33<p>Returns TRUE if the <CODE>mutex</CODE> lock can be changed from <CODE>read lock</CODE> to <CODE>write lock</CODE>, or conversely from <CODE>write lock</CODE> to <CODE>read lock</CODE>. If not, the function returns FALSE.</p>
34
35<H2>Description</H2>
36<P>Changes the type of the <CODE>mutex</CODE> that is locked.</P>
37<P><CODE>mutex</CODE> is the pointer to the <CODE>OSMutex</CODE> structure to be changed.</P>
38<P>The <CODE>OS_TryLockMutexFromWToR</CODE> function takes a <CODE>mutex</CODE> that is set to <CODE>write lock</CODE> and changes the setting to <CODE>read lock</CODE>. When the function succeeds, the <CODE>mutex</CODE> type is <CODE>read lock</CODE>. To unlock it you need to execute either the <CODE><A href="OS_UnlockMutexRW.html">OS_UnlockMutexR</A></CODE> or <CODE><A href="OS_UnlockMutexRW.html">OS_UnlockMutexRW</A></CODE> function.</P>
39<P>The <CODE>OS_TryLockMutexFromRToW</CODE> takes a <CODE>mutex</CODE> that is set to <CODE>read lock</CODE> and changes the setting to <CODE>write lock</CODE>. When the function succeeds, the <CODE>mutex</CODE> type is <CODE>write lock</CODE>. To unlock it you need to execute either the <CODE><A href="OS_UnlockMutexRW.html">OS_UnlockMutexW</A></CODE> or <CODE><A href="OS_UnlockMutexRW.html">OS_UnlockMutexRW</A></CODE> function.</P>
40<P>If <CODE>mutex</CODE> is locked at multiple levels or if the type is wrong, the function fails and returns FALSE. A multi-level locked mutex is one that is either locked by multiple threads, or by one thread in which more than one lock function calls the same <CODE>OSMutex</CODE> structure. A <I>wrong</I> type, for example, is when the function attempts to change a <CODE>read lock</CODE> mutex into a <CODE>write lock</CODE> mutex, but the target is not a <CODE>read lock</CODE> mutex.</P>
41<BLOCKQUOTE style="background-color:#ffffcc"><CODE><B>Example 1</B><BR> OSMutex mutex;<BR> <BR> OS_LockMutexR( &amp;mutex );<BR> OS_LockMutexR( &amp;mutex );<BR> <BR> if ( OS_TryLockMutexFromRToW( &amp;mutex ) == FALSE )  <FONT color="#ff0000">Returns FALSE because mutex is locked at multiple levels.</FONT><BR> {<BR> :<BR> }</CODE></BLOCKQUOTE>
42<BLOCKQUOTE style="background-color:#ffffcc"><CODE><B>Example 2</B><BR> OSMutex mutex;<BR> <BR> OS_LockMutexR( &amp;mutex );<BR> if ( OS_TryLockMutexFromWToR( &amp;mutex ) == FALSE )  <FONT color="#ff0000">Returns FALSE because mutex is read lock, thus the wrong type for FromWToR.</FONT><BR> {<BR> :<BR> }</CODE></BLOCKQUOTE>
43<P>This function returns immediately, regardless of whether it succeeds or fails. Threads are not switched.</P>
44<h2>See Also</h2>
45<p><CODE><A href="OS_InitMutex.html">OS_InitMutex</A><BR> <A href="OS_LockMutex.html">OS_LockMutex</A><BR> <A href="OS_UnlockMutex.html">OS_UnlockMutex</A><BR> <A href="OS_LockMutexRW.html">OS_LockMutexR</A><BR> <A href="OS_LockMutexRW.html">OS_LockMutexW</A><BR> <A href="OS_UnlockMutexRW.html">OS_UnlocMutexR</A><BR> <A href="OS_UnlockMutexRW.html">OS_UnlocMutexW</A><BR> <A href="OS_TryLockMutexRW.html">OS_TryLockMutexR</A><BR> <A href="OS_TryLockMutexRW.html">OS_TryLockMutexW</A><br> <A href="OS_LockMutexFromToRW.html">OS_LockMutexFromRToW</A><BR> <A href="OS_LockMutexFromToRW.html">OS_LockMutexFromWToR</A></CODE></p>
46
47<H2>Revision History</H2>
48<P>2008/12/16 Initial version.</P>
49<hr><p>CONFIDENTIAL</p></body>
50</html>
51