1 /* 2 * Read/Write lock functions 3 * 4 * Copyright (C) 2012-2020, Joachim Metz <joachim.metz@gmail.com> 5 * 6 * Refer to AUTHORS for acknowledgements. 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #if !defined( _LIBCTHREADS_INTERNAL_READ_WRITE_LOCK_H ) 23 #define _LIBCTHREADS_INTERNAL_READ_WRITE_LOCK_H 24 25 #include <common.h> 26 #include <types.h> 27 28 #if defined( WINAPI ) && ( WINVER >= 0x0602 ) 29 #include <Synchapi.h> 30 #endif 31 32 #if defined( HAVE_PTHREAD_H ) && !defined( WINAPI ) 33 #include <pthread.h> 34 #endif 35 36 #include "libcthreads_extern.h" 37 #include "libcthreads_libcerror.h" 38 #include "libcthreads_types.h" 39 40 #if defined( __cplusplus ) 41 extern "C" { 42 #endif 43 44 #if !defined( HAVE_LOCAL_LIBCTHREADS ) || defined( HAVE_MULTI_THREAD_SUPPORT ) 45 46 typedef struct libcthreads_internal_read_write_lock libcthreads_internal_read_write_lock_t; 47 48 struct libcthreads_internal_read_write_lock 49 { 50 #if defined( WINAPI ) && ( WINVER >= 0x0600 ) 51 /* The slim read/write lock 52 */ 53 SRWLOCK slim_read_write_lock; 54 55 #elif defined( WINAPI ) 56 /* The read critical section 57 */ 58 CRITICAL_SECTION read_critical_section; 59 60 /* The write critical section 61 */ 62 CRITICAL_SECTION write_critical_section; 63 64 /* The number of readers 65 */ 66 int number_of_readers; 67 68 /* The no read event handle 69 */ 70 HANDLE no_read_event_handle; 71 72 #elif defined( HAVE_PTHREAD_H ) 73 /* The read/write lock 74 */ 75 pthread_rwlock_t read_write_lock; 76 77 #else 78 #error Missing read/write lock type 79 #endif 80 }; 81 82 LIBCTHREADS_EXTERN \ 83 int libcthreads_read_write_lock_initialize( 84 libcthreads_read_write_lock_t **read_write_lock, 85 libcerror_error_t **error ); 86 87 LIBCTHREADS_EXTERN \ 88 int libcthreads_read_write_lock_free( 89 libcthreads_read_write_lock_t **read_write_lock, 90 libcerror_error_t **error ); 91 92 LIBCTHREADS_EXTERN \ 93 int libcthreads_read_write_lock_grab_for_read( 94 libcthreads_read_write_lock_t *read_write_lock, 95 libcerror_error_t **error ); 96 97 LIBCTHREADS_EXTERN \ 98 int libcthreads_read_write_lock_grab_for_write( 99 libcthreads_read_write_lock_t *read_write_lock, 100 libcerror_error_t **error ); 101 102 LIBCTHREADS_EXTERN \ 103 int libcthreads_read_write_lock_release_for_read( 104 libcthreads_read_write_lock_t *read_write_lock, 105 libcerror_error_t **error ); 106 107 LIBCTHREADS_EXTERN \ 108 int libcthreads_read_write_lock_release_for_write( 109 libcthreads_read_write_lock_t *read_write_lock, 110 libcerror_error_t **error ); 111 112 #endif /* !defined( HAVE_LOCAL_LIBCTHREADS ) || defined( HAVE_MULTI_THREAD_SUPPORT ) */ 113 114 #if defined( __cplusplus ) 115 } 116 #endif 117 118 #endif /* !defined( _LIBCTHREADS_INTERNAL_READ_WRITE_LOCK_H ) */ 119 120