Blame gl/tests/windows-rwlock.h

Packit Service 991b93
/* Read-write locks (native Windows implementation).
Packit Service 991b93
   Copyright (C) 2005-2020 Free Software Foundation, Inc.
Packit Service 991b93
Packit Service 991b93
   This program is free software; you can redistribute it and/or modify
Packit Service 991b93
   it under the terms of the GNU General Public License as published by
Packit Service 991b93
   the Free Software Foundation; either version 3, or (at your option)
Packit Service 991b93
   any later version.
Packit Service 991b93
Packit Service 991b93
   This program is distributed in the hope that it will be useful,
Packit Service 991b93
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 991b93
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 991b93
   GNU General Public License for more details.
Packit Service 991b93
Packit Service 991b93
   You should have received a copy of the GNU General Public License
Packit Service 991b93
   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
Packit Service 991b93
Packit Service 991b93
/* Written by Bruno Haible <bruno@clisp.org>, 2005.
Packit Service 991b93
   Based on GCC's gthr-win32.h.  */
Packit Service 991b93
Packit Service 991b93
#ifndef _WINDOWS_RWLOCK_H
Packit Service 991b93
#define _WINDOWS_RWLOCK_H
Packit Service 991b93
Packit Service 991b93
#define WIN32_LEAN_AND_MEAN  /* avoid including junk */
Packit Service 991b93
#include <windows.h>
Packit Service 991b93
Packit Service 991b93
#include "windows-initguard.h"
Packit Service 991b93
Packit Service 991b93
/* It is impossible to implement read-write locks using plain locks, without
Packit Service 991b93
   introducing an extra thread dedicated to managing read-write locks.
Packit Service 991b93
   Therefore here we need to use the low-level Event type.  */
Packit Service 991b93
Packit Service 991b93
typedef struct
Packit Service 991b93
        {
Packit Service 991b93
          HANDLE *array; /* array of waiting threads, each represented by an event */
Packit Service 991b93
          unsigned int count; /* number of waiting threads */
Packit Service 991b93
          unsigned int alloc; /* length of allocated array */
Packit Service 991b93
          unsigned int offset; /* index of first waiting thread in array */
Packit Service 991b93
        }
Packit Service 991b93
        glwthread_carray_waitqueue_t;
Packit Service 991b93
typedef struct
Packit Service 991b93
        {
Packit Service 991b93
          glwthread_initguard_t guard; /* protects the initialization */
Packit Service 991b93
          CRITICAL_SECTION lock; /* protects the remaining fields */
Packit Service 991b93
          glwthread_carray_waitqueue_t waiting_readers; /* waiting readers */
Packit Service 991b93
          glwthread_carray_waitqueue_t waiting_writers; /* waiting writers */
Packit Service 991b93
          int runcount; /* number of readers running, or -1 when a writer runs */
Packit Service 991b93
        }
Packit Service 991b93
        glwthread_rwlock_t;
Packit Service 991b93
Packit Service 991b93
#define GLWTHREAD_RWLOCK_INIT { GLWTHREAD_INITGUARD_INIT }
Packit Service 991b93
Packit Service 991b93
#ifdef __cplusplus
Packit Service 991b93
extern "C" {
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
extern void glwthread_rwlock_init (glwthread_rwlock_t *lock);
Packit Service 991b93
extern int glwthread_rwlock_rdlock (glwthread_rwlock_t *lock);
Packit Service 991b93
extern int glwthread_rwlock_wrlock (glwthread_rwlock_t *lock);
Packit Service 991b93
extern int glwthread_rwlock_tryrdlock (glwthread_rwlock_t *lock);
Packit Service 991b93
extern int glwthread_rwlock_trywrlock (glwthread_rwlock_t *lock);
Packit Service 991b93
extern int glwthread_rwlock_unlock (glwthread_rwlock_t *lock);
Packit Service 991b93
extern int glwthread_rwlock_destroy (glwthread_rwlock_t *lock);
Packit Service 991b93
Packit Service 991b93
#ifdef __cplusplus
Packit Service 991b93
}
Packit Service 991b93
#endif
Packit Service 991b93
Packit Service 991b93
#endif /* _WINDOWS_RWLOCK_H */