<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Using LWP_Mutex functions</title>
<description> Hi all. Forgive me if this is a daft question!

I have read the libogc mutex documentation, but I am unsure about something; When using mutex locks, which is the correct way to get a lock? Do you simply call LWP_MutexLock(lock) or do I need to use while and wait for LWP_MutexLock to return 0?

//global
mutex_t lock;

void InitFunction() {
LWP_MutexInit(lock);
}

void Function_1() {
LWP_MutexLock(lock);
// Do stuff here
LWP_MutexUnlock(lock);
}
void Function_2() {
while (LWP_MutexLock(lock) != 0); // Do I need to wait for the lock like this?
// Do stuff here
LWP_MutexUnlock(lock);
}
Which is the correct method, Function_1 or Function_2?</description><link>http://forum.wiibrew.org/read.php?11,7736,7736#msg-7736</link><lastBuildDate>Sat, 11 Jul 2026 22:18:37 +0200</lastBuildDate>
<generator>Phorum 5.2.23</generator>
<item>
<guid>http://forum.wiibrew.org/read.php?11,7736,7815#msg-7815</guid>
<title>Re: Using LWP_Mutex functions</title><link>http://forum.wiibrew.org/read.php?11,7736,7815#msg-7815</link><description><![CDATA[ Hi,<br /><br />LWP_MutexLock returns with !=0 not &lt; 0 and will only happen if you try to call MutexLock another time in the same thread without having it initialized as a recursive lock.<br /><br />regards<br />shagkur]]></description>
<dc:creator>shagkur</dc:creator>
<category>Coding</category><pubDate>Tue, 13 Jan 2009 13:13:34 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,7736,7813#msg-7813</guid>
<title>Re: Using LWP_Mutex functions</title><link>http://forum.wiibrew.org/read.php?11,7736,7813#msg-7813</link><description><![CDATA[ Thanks for the help!<br />If LWP_MutexLock returns &lt; 0 on failure, what conditions would cause a failure and should I be checking for them?]]></description>
<dc:creator>DrTwox</dc:creator>
<category>Coding</category><pubDate>Tue, 13 Jan 2009 12:52:17 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,7736,7810#msg-7810</guid>
<title>Re: Using LWP_Mutex functions</title><link>http://forum.wiibrew.org/read.php?11,7736,7810#msg-7810</link><description><![CDATA[ Hi,<br /><br />Function_1 is enough. Also LWP_MutexInit takes a 2nd paramter which tells whether the lock should be recursive or not.<br />By recursive means the thread which acquired the lock won&#039;t deadlock if LWP_MutexLock is called again.<br /><br />regards<br />shagkur]]></description>
<dc:creator>shagkur</dc:creator>
<category>Coding</category><pubDate>Tue, 13 Jan 2009 10:43:39 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,7736,7787#msg-7787</guid>
<title>Re: Using LWP_Mutex functions</title><link>http://forum.wiibrew.org/read.php?11,7736,7787#msg-7787</link><description><![CDATA[ I am sure that it is a blocking function, when it returns, the mutex will be locked.]]></description>
<dc:creator>henke37</dc:creator>
<category>Coding</category><pubDate>Tue, 13 Jan 2009 07:09:18 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,7736,7736#msg-7736</guid>
<title>Using LWP_Mutex functions</title><link>http://forum.wiibrew.org/read.php?11,7736,7736#msg-7736</link><description><![CDATA[ Hi all. Forgive me if this is a daft question!<br /><br />I have read the <a href="http://libogc.devkitpro.org/mutex_8h.html" rel="nofollow">libogc mutex documentation</a>, but I am unsure about something; When using mutex locks, which is the correct way to get a lock? Do you simply call LWP_MutexLock(lock) or do I need to use <i>while</i> and wait for LWP_MutexLock to return 0?<br /><pre class="bbcode">
//global
mutex_t lock;

void InitFunction() {
    LWP_MutexInit(lock);
}

void Function_1() {
    LWP_MutexLock(lock);
    // Do stuff here
    LWP_MutexUnlock(lock);
}
void Function_2() {
    while (LWP_MutexLock(lock) != 0); // Do I need to wait for the lock like this?
    // Do stuff here
    LWP_MutexUnlock(lock);
}</pre>
Which is the correct method, Function_1 or Function_2?]]></description>
<dc:creator>DrTwox</dc:creator>
<category>Coding</category><pubDate>Tue, 13 Jan 2009 00:21:35 +0100</pubDate></item>
</channel>
</rss>