<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>54408</bug_id>
          
          <creation_ts>2011-02-14 12:31:43 -0800</creation_ts>
          <short_desc>Fix Mutex::tryLock() on Windows to work properly with PlatformCondition::timedWait()</short_desc>
          <delta_ts>2011-02-15 11:53:16 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Other</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Chris Rogers">crogers</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>aroben</cc>
    
    <cc>kbr</cc>
    
    <cc>sfalken</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>350822</commentid>
    <comment_count>0</comment_count>
    <who name="Chris Rogers">crogers</who>
    <bug_when>2011-02-14 12:31:43 -0800</bug_when>
    <thetext>Fix Mutex::tryLock() on Windows to work properly with PlatformCondition::timedWait()</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>350823</commentid>
    <comment_count>1</comment_count>
      <attachid>82352</attachid>
    <who name="Chris Rogers">crogers</who>
    <bug_when>2011-02-14 12:33:20 -0800</bug_when>
    <thetext>Created attachment 82352
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>350825</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Rogers">crogers</who>
    <bug_when>2011-02-14 12:39:34 -0800</bug_when>
    <thetext>The bug I&apos;m seeing without this fix is that tryLock() will always fail on Windows when another thread is waiting on a ThreadCondition.  Here&apos;s the pattern:

// Worker thread waiting to be signalled

        {
            MutexLocker locker(m_backgroundThreadLock);
            while (!m_moreInputBuffered &amp;&amp; !m_wantsToExit)
                m_backgroundThreadCondition.wait(m_backgroundThreadLock);
        }

.
.
.

    // Another thread has some work and tries to signal (using a tryLock())

    // Not using a MutexLocker looks strange, but we use a tryLock() instead because this is run on the real-time
    // thread where it is a disaster for the lock to be contended (causes audio glitching).  It&apos;s OK if we fail to
    // signal from time to time, since we&apos;ll get to it the next time we&apos;re called.  We&apos;re called repeatedly
    // and frequently (around every 3ms).  The background thread is processing well into the future and has a considerable amount of 
    // leeway here...
    if (m_backgroundThreadLock.tryLock()) {            //  &lt;----------------- this will alway FAIL currently on Windows
        m_moreInputBuffered = true;
        m_backgroundThreadCondition.signal();
        m_backgroundThreadLock.unlock();
    }</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>350833</commentid>
    <comment_count>3</comment_count>
      <attachid>82352</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-02-14 12:59:45 -0800</bug_when>
    <thetext>Comment on attachment 82352
Patch

Seems fine to make this change, although the design seems surprising. Why is the boolean variable shared between threads needed at all? Can you just use wait/signal without a separate boolean variable?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>350841</commentid>
    <comment_count>4</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-02-14 13:13:08 -0800</bug_when>
    <thetext>I&apos;m wondering if we can use &quot;fast mutexes&quot; on windows instead: &lt;http://msdn.microsoft.com/en-us/library/ms810047.aspx#locks__topic7&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>350842</commentid>
    <comment_count>5</comment_count>
    <who name="Chris Rogers">crogers</who>
    <bug_when>2011-02-14 13:16:31 -0800</bug_when>
    <thetext>Thanks Alexey.  I think you may be right about my use of the bool variable being redundant.  I&apos;ll have to look closer at what I was thinking there and may be able to simplify that.  But I&apos;ll land this fix first.

I&apos;m by no means a Windows programming expert so I&apos;m not sure about the &quot;fast mutexes&quot;...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>350885</commentid>
    <comment_count>6</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2011-02-14 14:26:00 -0800</bug_when>
    <thetext>(In reply to comment #4)
&gt; I&apos;m wondering if we can use &quot;fast mutexes&quot; on windows instead: &lt;http://msdn.microsoft.com/en-us/library/ms810047.aspx#locks__topic7&gt;.

Those look like they&apos;re for implementing device drivers...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>351439</commentid>
    <comment_count>7</comment_count>
    <who name="Chris Rogers">crogers</who>
    <bug_when>2011-02-15 11:53:16 -0800</bug_when>
    <thetext>Committed r78597: &lt;http://trac.webkit.org/changeset/78597&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>82352</attachid>
            <date>2011-02-14 12:33:20 -0800</date>
            <delta_ts>2011-02-14 12:59:45 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-54408-20110214123319.patch</filename>
            <type>text/plain</type>
            <size>1316</size>
            <attacher name="Chris Rogers">crogers</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gNzg0OTYpCisrKyBTb3VyY2Uv
SmF2YVNjcmlwdENvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBAIC0xLDMgKzE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tX3JlY3Vyc2lvbkNvdW50OwogICAgIExlYXZlQ3JpdGljYWxTZWN0aW9uKCZtdXRleC5t
X2ludGVybmFsTXV0ZXgpOwogCiAgICAgLy8gTWFpbiB3YWl0IC0gdXNlIHRpbWVvdXQuCkBAIC0z
NjUsNiArMzY2LDcgQEAgYm9vbCBQbGF0Zm9ybUNvbmRpdGlvbjo6dGltZWRXYWl0KFBsYXRmbwog
ICAgIH0KIAogICAgIEVudGVyQ3JpdGljYWxTZWN0aW9uICgmbXV0ZXgubV9pbnRlcm5hbE11dGV4
KTsKKyAgICArK211dGV4Lm1fcmVjdXJzaW9uQ291bnQ7CiAKICAgICByZXR1cm4gIXRpbWVkT3V0
OwogfQo=
</data>
<flag name="review"
          id="74006"
          type_id="1"
          status="+"
          setter="ap"
    />
          </attachment>
      

    </bug>

</bugzilla>