List:Commits« Previous MessageNext Message »
From:Mats Kindahl Date:October 4 2007 7:45pm
Subject:Re: bk commit into 5.0 tree (msvensson:1.2526) BUG#30992
View as plain text  
Magnus Svensson wrote:
> tor 2007-10-04 klockan 11:11 +0200 skrev Mats Kindahl:
>   
>> Hi Magnus!
>>
>> Patch approved. I checked that the recursion count really is increased.
>>     
>
> Good, I did that in the debugger. Couldn't really figure out how to
> implement that assert you mentioned to be atomic. Or should I do it only
> only as a test?
>   

Not really critical to have an assertion, as long as we have verified 
that it is a documented behavior. Microsoft isn't likely to change it.

> The scary thing is that we really are looking into a struct defined by
> MS.
>
>   
>> Just my few cents,
>> Mats Kindahl
>>
>> msvensson@stripped wrote:
>>     
>>> Below is the list of changes that have just been committed into a local
>>> 5.0 repository of msvensson. When msvensson does a push these changes will
>>> be propagated to the main repository and, within 24 hours after the
>>> push, to the public repository.
>>> For information on how to access the public repository
>>> see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
>>>
>>> ChangeSet@stripped, 2007-10-03 21:38:32+02:00, msvensson@stripped +2 -0
>>>   Bug#30992 Wrong implementation of pthread_mutex_trylock()
>>>   It's not possible to use WaitForSingleObject to wait
>>>   on a CRITICAL_SECTION, instead use the TryEnterCriticalSection function.
>>>    - if "mutex" was already taken => return EBUSY
>>>    - if "mutex" was aquired => return 0
>>>
>>>   include/config-win.h@stripped, 2007-10-03 21:38:30+02:00,
> msvensson@stripped +3 -0
>>>     Make windows.h define TryEnterCriticalSection
>>>
>>>   mysys/my_winthread.c@stripped, 2007-10-03 21:38:30+02:00,
> msvensson@stripped +10 -12
>>>     Use the TryEnterCriticalSection function to implement
> pthread_mutex_trylock
>>>     Prevent recursive behaviour by looking at the RecursionCount variable
>>>     in the CRITICAL_SECTION struct and return EBUSY from function if
>>>     the mutex was already locked once.
>>>
>>> diff -Nrup a/include/config-win.h b/include/config-win.h
>>> --- a/include/config-win.h	2007-03-28 23:00:25 +02:00
>>> +++ b/include/config-win.h	2007-10-03 21:38:30 +02:00
>>> @@ -19,6 +19,9 @@
>>>  /* We have to do this define before including windows.h to get the AWE API
>>>  functions */
>>>  #define _WIN32_WINNT     0x0500
>>> +#else
>>> +/* Get NT 4.0 functions */
>>> +#define _WIN32_WINNT     0x0400
>>>  #endif
>>>  
>>>  #if defined(_MSC_VER) && _MSC_VER >= 1400
>>> diff -Nrup a/mysys/my_winthread.c b/mysys/my_winthread.c
>>> --- a/mysys/my_winthread.c	2007-10-01 15:11:12 +02:00
>>> +++ b/mysys/my_winthread.c	2007-10-03 21:38:30 +02:00
>>> @@ -40,30 +40,28 @@ void win_pthread_init(void)
>>>    pthread_mutex_init(&THR_LOCK_thread,MY_MUTEX_INIT_FAST);
>>>  }
>>>  
>>> +
>>>  /**
>>>     Adapter to @c pthread_mutex_trylock()
>>>  
>>>     @retval 0      Mutex was acquired
>>>     @retval EBUSY  Mutex was already locked by a thread
>>> -   @retval EINVAL Mutex could not be acquired due to other error
>>>   */
>>>  int
>>>  win_pthread_mutex_trylock(pthread_mutex_t *mutex)
>>>  {
>>> -  switch (WaitForSingleObject(mutex, 0)) {
>>> -  case WAIT_TIMEOUT:
>>> -    return EBUSY;
>>> -
>>> -  default:
>>> -  case WAIT_FAILURE:
>>> -    return EINVAL;
>>> -
>>> -  case WAIT_OBJECT_0:
>>> -  case WAIT_ABANDONED: /* The mutex was acquired because it was
>>> -                        * abandoned */
>>> +  if (TryEnterCriticalSection(mutex))
>>> +  {
>>> +    /* Don't allow recursive lock */
>>> +    if (mutex->RecursionCount > 1){
>>> +      LeaveCriticalSection(mutex);
>>> +      return EBUSY;
>>> +    }
>>>      return 0;
>>>    }
>>> +  return EBUSY;
>>>  }
>>> +
>>>  
>>>  /*
>>>  ** We have tried to use '_beginthreadex' instead of '_beginthread' here
>>>
>>>   
>>>       
>>     


-- 
Mats Kindahl
Lead Software Developer
Replication Team
MySQL AB, www.mysql.com


Thread
bk commit into 5.0 tree (msvensson:1.2526) BUG#30992msvensson3 Oct
  • Re: bk commit into 5.0 tree (msvensson:1.2526) BUG#30992Mats Kindahl4 Oct
    • Re: bk commit into 5.0 tree (msvensson:1.2526) BUG#30992Magnus Svensson4 Oct
      • Re: bk commit into 5.0 tree (msvensson:1.2526) BUG#30992Mats Kindahl4 Oct