LIU Hao wrote:

> While there are certainly no issues in this code, the pragmas don't look 
> quite neat.

I agree that having a pragma around single function call indeed feels a bit off.

> Using the COM-flavor approach which I suggested earlier, it could be
>
>     struct WinpthreadsMutex
>     {
>       const WinpthreadsMutexVtable *vtable;
>     };
>
>     struct WinpthreadsNormalMutex
>     {
>       const WinpthreadsMutexVtable *vtable;
>       HANDLE Event;
>       LONG LockState;
>     };
>
>     static int WinpthreadsNormalMutexInit (WinpthreadsMutex **wMutex, const 
> pthread_mutexattr_t *attr) {
>       WinpthreadsNormalMutex *mutex = malloc (sizeof 
> (WinpthreadsNormalMutex));
>       *wMutex = (WinpthreadsMutex *) mutex;
>       if (!mutex) {
>         return ENOMEM;
>       }
>
>       // ...
>     }

Yes, this approach does seem reasonable now. In the original version of changes 
I sent, `WinpthreadsMutex` simply contained two pointers: one to static 
"vtable" and second to allocated mutex-type specific structure. Now that we no 
longer have the latter, it does make sense to store "vtable" directly in 
mutex-type specific structure.

I'll take care of this tomorrow. Hopefully, it will be the last revision.

>> +
>> +  mutex->Event = CreateEventW (NULL, FALSE, FALSE, NULL);
>> +
>> +  /**
>> +   * The pthread_mutex_init() function shall fail if:
>> +   *
>> +   * [EAGAIN]
>> +   *   The system lacked the necessary resources (other than memory) to
>> +   *   initialize another mutex.
>> +   */
>> +  if (mutex->Event == NULL) {
>> +    free (wMutex);
>> +    return EAGAIN;
>> +  }
>
> This should be `free (*wMutex)`, and likewise somewhere else:

Nice catch! I simply replaced `mutex` with `wMutex` and overlooked different 
indirection levels.

- Kirill Makurin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to