1 /* 2 * Queue 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_QUEUE_H ) 23 #define _LIBCTHREADS_INTERNAL_QUEUE_H 24 25 #include <common.h> 26 #include <types.h> 27 28 #include "libcthreads_extern.h" 29 #include "libcthreads_libcerror.h" 30 #include "libcthreads_types.h" 31 32 #if defined( __cplusplus ) 33 extern "C" { 34 #endif 35 36 #if !defined( HAVE_LOCAL_LIBCTHREADS ) || defined( HAVE_MULTI_THREAD_SUPPORT ) 37 38 typedef struct libcthreads_internal_queue libcthreads_internal_queue_t; 39 40 struct libcthreads_internal_queue 41 { 42 /* The (current) pop index 43 */ 44 int pop_index; 45 46 /* The (current) push index 47 */ 48 int push_index; 49 50 /* The number of values 51 */ 52 int number_of_values; 53 54 /* The allocated number of values 55 */ 56 int allocated_number_of_values; 57 58 /* The values array 59 */ 60 intptr_t **values_array; 61 62 /* The condition mutex 63 */ 64 libcthreads_mutex_t *condition_mutex; 65 66 /* The queue empty condition 67 */ 68 libcthreads_condition_t *empty_condition; 69 70 /* The queue full condition 71 */ 72 libcthreads_condition_t *full_condition; 73 }; 74 75 LIBCTHREADS_EXTERN \ 76 int libcthreads_queue_initialize( 77 libcthreads_queue_t **queue, 78 int maximum_number_of_values, 79 libcerror_error_t **error ); 80 81 LIBCTHREADS_EXTERN \ 82 int libcthreads_queue_free( 83 libcthreads_queue_t **queue, 84 int (*value_free_function)( 85 intptr_t **value, 86 libcerror_error_t **error ), 87 libcerror_error_t **error ); 88 89 LIBCTHREADS_EXTERN \ 90 int libcthreads_queue_empty( 91 libcthreads_queue_t *queue, 92 libcerror_error_t **error ); 93 94 LIBCTHREADS_EXTERN \ 95 int libcthreads_queue_try_pop( 96 libcthreads_queue_t *queue, 97 intptr_t **value, 98 libcerror_error_t **error ); 99 100 LIBCTHREADS_EXTERN \ 101 int libcthreads_queue_pop( 102 libcthreads_queue_t *queue, 103 intptr_t **value, 104 libcerror_error_t **error ); 105 106 LIBCTHREADS_EXTERN \ 107 int libcthreads_queue_try_push( 108 libcthreads_queue_t *queue, 109 intptr_t *value, 110 libcerror_error_t **error ); 111 112 LIBCTHREADS_EXTERN \ 113 int libcthreads_queue_push( 114 libcthreads_queue_t *queue, 115 intptr_t *value, 116 libcerror_error_t **error ); 117 118 LIBCTHREADS_EXTERN \ 119 int libcthreads_queue_push_sorted( 120 libcthreads_queue_t *queue, 121 intptr_t *value, 122 int (*value_compare_function)( 123 intptr_t *first_value, 124 intptr_t *second_value, 125 libcerror_error_t **error ), 126 uint8_t sort_flags, 127 libcerror_error_t **error ); 128 129 #endif /* !defined( HAVE_LOCAL_LIBCTHREADS ) || defined( HAVE_MULTI_THREAD_SUPPORT ) */ 130 131 #if defined( __cplusplus ) 132 } 133 #endif 134 135 #endif /* !defined( _LIBCTHREADS_INTERNAL_QUEUE_H ) */ 136 137