xref: /netbsd-src/external/gpl3/gdb/dist/gnulib/import/windows-recmutex.h (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
18dffb485Schristos /* Plain recursive mutexes (native Windows implementation).
2*4b169a6bSchristos    Copyright (C) 2005-2022 Free Software Foundation, Inc.
38dffb485Schristos 
4*4b169a6bSchristos    This file is free software: you can redistribute it and/or modify
5*4b169a6bSchristos    it under the terms of the GNU Lesser General Public License as
6*4b169a6bSchristos    published by the Free Software Foundation; either version 2.1 of the
7*4b169a6bSchristos    License, or (at your option) any later version.
88dffb485Schristos 
9*4b169a6bSchristos    This file is distributed in the hope that it will be useful,
108dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
118dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*4b169a6bSchristos    GNU Lesser General Public License for more details.
138dffb485Schristos 
14*4b169a6bSchristos    You should have received a copy of the GNU Lesser General Public License
15*4b169a6bSchristos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
168dffb485Schristos 
178dffb485Schristos /* Written by Bruno Haible <bruno@clisp.org>, 2005.
188dffb485Schristos    Based on GCC's gthr-win32.h.  */
198dffb485Schristos 
208dffb485Schristos #ifndef _WINDOWS_RECMUTEX_H
218dffb485Schristos #define _WINDOWS_RECMUTEX_H
228dffb485Schristos 
238dffb485Schristos #define WIN32_LEAN_AND_MEAN  /* avoid including junk */
248dffb485Schristos #include <windows.h>
258dffb485Schristos 
268dffb485Schristos #include "windows-initguard.h"
278dffb485Schristos 
288dffb485Schristos /* The native Windows documentation says that CRITICAL_SECTION already
298dffb485Schristos    implements a recursive lock.  But we need not rely on it: It's easy to
308dffb485Schristos    implement a recursive lock without this assumption.  */
318dffb485Schristos 
328dffb485Schristos typedef struct
338dffb485Schristos         {
348dffb485Schristos           glwthread_initguard_t guard; /* protects the initialization */
358dffb485Schristos           DWORD owner;
368dffb485Schristos           unsigned long depth;
378dffb485Schristos           CRITICAL_SECTION lock;
388dffb485Schristos         }
398dffb485Schristos         glwthread_recmutex_t;
408dffb485Schristos 
418dffb485Schristos #define GLWTHREAD_RECMUTEX_INIT { GLWTHREAD_INITGUARD_INIT, 0, 0 }
428dffb485Schristos 
438dffb485Schristos #ifdef __cplusplus
448dffb485Schristos extern "C" {
458dffb485Schristos #endif
468dffb485Schristos 
478dffb485Schristos extern void glwthread_recmutex_init (glwthread_recmutex_t *mutex);
488dffb485Schristos extern int glwthread_recmutex_lock (glwthread_recmutex_t *mutex);
498dffb485Schristos extern int glwthread_recmutex_trylock (glwthread_recmutex_t *mutex);
508dffb485Schristos extern int glwthread_recmutex_unlock (glwthread_recmutex_t *mutex);
518dffb485Schristos extern int glwthread_recmutex_destroy (glwthread_recmutex_t *mutex);
528dffb485Schristos 
538dffb485Schristos #ifdef __cplusplus
548dffb485Schristos }
558dffb485Schristos #endif
568dffb485Schristos 
578dffb485Schristos #endif /* _WINDOWS_RECMUTEX_H */
58