1 /* 2 * Mutex 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_MUTEX_H ) 23 #define _LIBCTHREADS_INTERNAL_MUTEX_H 24 25 #include <common.h> 26 #include <types.h> 27 28 #if defined( HAVE_PTHREAD_H ) && !defined( WINAPI ) 29 #include <pthread.h> 30 #endif 31 32 #include "libcthreads_extern.h" 33 #include "libcthreads_libcerror.h" 34 #include "libcthreads_types.h" 35 36 #if defined( __cplusplus ) 37 extern "C" { 38 #endif 39 40 #if !defined( HAVE_LOCAL_LIBCTHREADS ) || defined( HAVE_MULTI_THREAD_SUPPORT ) 41 42 typedef struct libcthreads_internal_mutex libcthreads_internal_mutex_t; 43 44 struct libcthreads_internal_mutex 45 { 46 #if defined( WINAPI ) && ( WINVER >= 0x0600 ) 47 /* The critical section 48 */ 49 CRITICAL_SECTION critical_section; 50 51 #elif defined( WINAPI ) 52 /* The mutex handle 53 */ 54 HANDLE mutex_handle; 55 56 #elif defined( HAVE_PTHREAD_H ) 57 /* The mutex 58 */ 59 pthread_mutex_t mutex; 60 61 #else 62 #error Missing mutex type 63 #endif 64 }; 65 66 LIBCTHREADS_EXTERN \ 67 int libcthreads_mutex_initialize( 68 libcthreads_mutex_t **mutex, 69 libcerror_error_t **error ); 70 71 LIBCTHREADS_EXTERN \ 72 int libcthreads_mutex_free( 73 libcthreads_mutex_t **mutex, 74 libcerror_error_t **error ); 75 76 LIBCTHREADS_EXTERN \ 77 int libcthreads_mutex_grab( 78 libcthreads_mutex_t *mutex, 79 libcerror_error_t **error ); 80 81 LIBCTHREADS_EXTERN \ 82 int libcthreads_mutex_try_grab( 83 libcthreads_mutex_t *mutex, 84 libcerror_error_t **error ); 85 86 LIBCTHREADS_EXTERN \ 87 int libcthreads_mutex_release( 88 libcthreads_mutex_t *mutex, 89 libcerror_error_t **error ); 90 91 #endif /* !defined( HAVE_LOCAL_LIBCTHREADS ) || defined( HAVE_MULTI_THREAD_SUPPORT ) */ 92 93 #if defined( __cplusplus ) 94 } 95 #endif 96 97 #endif /* !defined( _LIBCTHREADS_INTERNAL_MUTEX_H ) */ 98 99