Home | History | Annotate | Line # | Download | only in import
      1      1.1  christos /* Plain recursive mutexes (native Windows implementation).
      2  1.1.1.2  christos    Copyright (C) 2005-2022 Free Software Foundation, Inc.
      3      1.1  christos 
      4  1.1.1.2  christos    This file is free software: you can redistribute it and/or modify
      5  1.1.1.2  christos    it under the terms of the GNU Lesser General Public License as
      6  1.1.1.2  christos    published by the Free Software Foundation; either version 2.1 of the
      7  1.1.1.2  christos    License, or (at your option) any later version.
      8      1.1  christos 
      9  1.1.1.2  christos    This file is distributed in the hope that it will be useful,
     10      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  1.1.1.2  christos    GNU Lesser General Public License for more details.
     13      1.1  christos 
     14  1.1.1.2  christos    You should have received a copy of the GNU Lesser General Public License
     15  1.1.1.2  christos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
     16      1.1  christos 
     17      1.1  christos /* Written by Bruno Haible <bruno (at) clisp.org>, 2005.
     18      1.1  christos    Based on GCC's gthr-win32.h.  */
     19      1.1  christos 
     20      1.1  christos #ifndef _WINDOWS_RECMUTEX_H
     21      1.1  christos #define _WINDOWS_RECMUTEX_H
     22      1.1  christos 
     23      1.1  christos #define WIN32_LEAN_AND_MEAN  /* avoid including junk */
     24      1.1  christos #include <windows.h>
     25      1.1  christos 
     26      1.1  christos #include "windows-initguard.h"
     27      1.1  christos 
     28      1.1  christos /* The native Windows documentation says that CRITICAL_SECTION already
     29      1.1  christos    implements a recursive lock.  But we need not rely on it: It's easy to
     30      1.1  christos    implement a recursive lock without this assumption.  */
     31      1.1  christos 
     32      1.1  christos typedef struct
     33      1.1  christos         {
     34      1.1  christos           glwthread_initguard_t guard; /* protects the initialization */
     35      1.1  christos           DWORD owner;
     36      1.1  christos           unsigned long depth;
     37      1.1  christos           CRITICAL_SECTION lock;
     38      1.1  christos         }
     39      1.1  christos         glwthread_recmutex_t;
     40      1.1  christos 
     41      1.1  christos #define GLWTHREAD_RECMUTEX_INIT { GLWTHREAD_INITGUARD_INIT, 0, 0 }
     42      1.1  christos 
     43      1.1  christos #ifdef __cplusplus
     44      1.1  christos extern "C" {
     45      1.1  christos #endif
     46      1.1  christos 
     47      1.1  christos extern void glwthread_recmutex_init (glwthread_recmutex_t *mutex);
     48      1.1  christos extern int glwthread_recmutex_lock (glwthread_recmutex_t *mutex);
     49      1.1  christos extern int glwthread_recmutex_trylock (glwthread_recmutex_t *mutex);
     50      1.1  christos extern int glwthread_recmutex_unlock (glwthread_recmutex_t *mutex);
     51      1.1  christos extern int glwthread_recmutex_destroy (glwthread_recmutex_t *mutex);
     52      1.1  christos 
     53      1.1  christos #ifdef __cplusplus
     54      1.1  christos }
     55      1.1  christos #endif
     56      1.1  christos 
     57      1.1  christos #endif /* _WINDOWS_RECMUTEX_H */
     58