windows-recmutex.h 1.9 KB

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