From 534b4a9d11f066a72719c9ba88037bdb1cfc9369 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 21 Jan 2021 19:48:30 -0600 Subject: [PATCH] Bugfix: thread delete functions and related. --- build/level_0/settings | 2 +- build/monolithic/settings | 2 +- level_0/f_thread/c/private-thread.c | 183 +++++++++++++++ level_0/f_thread/c/private-thread.h | 224 ++++++++++++++++++ level_0/f_thread/c/thread-common.h | 94 +++----- level_0/f_thread/c/thread.c | 301 ++++++++++++++++++++++-- level_0/f_thread/c/thread.h | 432 ++++++++++++++++++++++++++++++++++- level_0/f_thread/data/build/settings | 2 +- 8 files changed, 1155 insertions(+), 85 deletions(-) create mode 100644 level_0/f_thread/c/private-thread.c create mode 100644 level_0/f_thread/c/private-thread.h diff --git a/build/level_0/settings b/build/level_0/settings index 6a2a00d..d07decb 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -22,7 +22,7 @@ build_libraries -lc -lcap build_libraries-level build_libraries-level_threadless build_sources_library account.c private-account.c capability.c color.c color-common.c console.c console-common.c control_group.c control_group-common.c conversion.c directory.c private-directory.c environment.c private-environment.c file.c file-common.c private-file.c fss.c private-fss.c fss_named.c fss_nest.c fss_set.c iki.c iki-common.c private-iki.c limit.c memory.c memory_structure.c private-memory.c path.c path-common.c private-path.c pipe.c print.c private-print.c serialize.c serialize-common.c private-serialize.c signal.c socket.c string.c string-common.c private-string.c string_dynamic.c string_map.c string_quantity.c string_range.c string_triple.c type_array.c private-type_array.c utf.c utf-common.c private-utf.c utf_dynamic.c utf_map.c utf_quantity.c utf_range.c utf_triple.c -build_sources_library-level thread.c +build_sources_library-level thread.c private-thread.c build_sources_program build_sources_headers account.h account-common.h capability.h capability-common.h color.h color-common.h console.h console-common.h control_group.h control_group-common.h conversion.h conversion-common.h directory.h directory_type.h directory-common.h environment.h environment-common.h execute.h execute-common.h file.h file-common.h fss.h private-fss.h fss-common.h fss_comment.h fss_delimit.h fss_named.h fss_nest.h fss_quote.h fss_set.h iki.h iki-common.h limit.h limit-common.h memory.h memory_structure.h memory-common.h path.h path-common.h pipe.h print.h serialize.h serialize-common.h signal.h signal-common.h socket.h socket-common.h status.h status_array.h string.h string-common.h private-string.h string_dynamic.h string_map.h string_quantity.h string_range.h string_triple.h type.h type_array.h private-type_array.h type_array-common.h utf.h utf-common.h utf_dynamic.h utf_map.h utf_quantity.h utf_range.h utf_triple.h build_sources_headers-level thread.h thread-common.h diff --git a/build/monolithic/settings b/build/monolithic/settings index 1322c32..0dfe062 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -22,7 +22,7 @@ build_libraries -lc -lcap build_libraries-monolithic build_libraries-monolithic_threadless build_sources_library level_0/account.c level_0/private-account.c level_0/capability.c level_0/color.c level_0/color-common.c level_0/console.c level_0/console-common.c level_0/control_group.c level_0/control_group-common.c level_0/conversion.c level_0/directory.c level_0/private-directory.c level_0/environment.c level_0/private-environment.c level_0/file.c level_0/file-common.c level_0/private-file.c level_0/fss.c level_0/private-fss.c level_0/fss_named.c level_0/fss_nest.c level_0/fss_set.c level_0/iki.c level_0/iki-common.c level_0/private-iki.c level_0/limit.c level_0/memory.c level_0/memory_structure.c level_0/private-memory.c level_0/path.c level_0/path-common.c level_0/private-path.c level_0/pipe.c level_0/print.c level_0/private-print.c level_0/serialize.c level_0/serialize-common.c level_0/private-serialize.c level_0/signal.c level_0/socket.c level_0/string.c level_0/string-common.c level_0/private-string.c level_0/string_dynamic.c level_0/string_map.c level_0/string_quantity.c level_0/string_range.c level_0/string_triple.c level_0/type_array.c level_0/private-type_array.c level_0/utf.c level_0/utf-common.c level_0/private-utf.c level_0/utf_dynamic.c level_0/utf_map.c level_0/utf_quantity.c level_0/utf_range.c level_0/utf_triple.c level_1/color.c level_1/console.c level_1/control_group.c level_1/conversion.c level_1/directory.c level_1/private-directory.c level_1/environment.c level_1/private-fss.c level_1/fss_basic.c level_1/fss_basic_list.c level_1/fss_embedded_list.c level_1/fss_extended.c level_1/fss_extended_list.c level_1/iki.c level_1/print.c level_1/private-print.c level_1/status.c level_1/string.c level_1/private-string.c level_1/utf.c level_1/private-utf.c level_1/utf_file.c level_1/private-utf_file.c level_2/control_group.c level_2/error.c level_2/error-common.c level_2/private-error.c level_2/execute.c level_2/private-execute.c level_2/file.c level_2/private-file.c level_2/fss.c level_2/private-fss.c level_2/fss_basic.c level_2/fss_basic_list.c level_2/fss_embedded_list.c level_2/fss_extended.c level_2/fss_extended_list.c level_2/fss_status.c level_2/iki.c level_2/private-iki.c level_2/path.c level_2/program.c level_2/status.c -build_sources_library-monolithic level_0/thread.c +build_sources_library-monolithic level_0/thread.c level_0/private-thread.c build_sources_program build_sources_headers level_0/account.h level_0/account-common.h level_0/capability.h level_0/capability-common.h level_0/color.h level_0/color-common.h level_0/console.h level_0/console-common.h level_0/control_group.h level_0/control_group-common.h level_0/conversion.h level_0/conversion-common.h level_0/directory.h level_0/directory_type.h level_0/directory-common.h level_0/environment.h level_0/environment-common.h level_0/execute.h level_0/execute-common.h level_0/file.h level_0/file-common.h level_0/fss.h level_0/private-fss.h level_0/fss-common.h level_0/fss_comment.h level_0/fss_delimit.h level_0/fss_named.h level_0/fss_nest.h level_0/fss_quote.h level_0/fss_set.h level_0/iki.h level_0/iki-common.h level_0/limit.h level_0/limit-common.h level_0/memory.h level_0/memory_structure.h level_0/memory-common.h level_0/path.h level_0/path-common.h level_0/pipe.h level_0/print.h level_0/serialize.h level_0/serialize-common.h level_0/signal.h level_0/signal-common.h level_0/socket.h level_0/socket-common.h level_0/status.h level_0/status_array.h level_0/string.h level_0/string-common.h level_0/private-string.h level_0/string_dynamic.h level_0/string_map.h level_0/string_quantity.h level_0/string_range.h level_0/string_triple.h level_0/type.h level_0/type_array.h level_0/private-type_array.h level_0/type_array-common.h level_0/utf.h level_0/utf-common.h level_0/utf_dynamic.h level_0/utf_map.h level_0/utf_quantity.h level_0/utf_range.h level_0/utf_triple.h level_1/color.h level_1/console.h level_1/control_group.h level_1/conversion.h level_1/directory.h level_1/environment.h level_1/execute.h level_1/execute-common.h level_1/fss.h level_1/fss_basic.h level_1/fss_basic_list.h level_1/fss_embedded_list.h level_1/fss_extended.h level_1/fss_extended_list.h level_1/fss_status.h level_1/iki.h level_1/print.h level_1/status.h level_1/string.h level_1/utf.h level_1/utf_file.h level_2/control_group.h level_2/error.h level_2/error-common.h level_2/execute.h level_2/file.h level_2/fss.h level_2/fss_basic.h level_2/fss_basic_list.h level_2/fss_embedded_list.h level_2/fss_extended.h level_2/fss_extended_list.h level_2/fss_status.h level_2/iki.h level_2/path.h level_2/program.h level_2/status.h build_sources_headers-monolithic level_0/thread.h level_0/thread-common.h diff --git a/level_0/f_thread/c/private-thread.c b/level_0/f_thread/c/private-thread.c new file mode 100644 index 0000000..fad975d --- /dev/null +++ b/level_0/f_thread/c/private-thread.c @@ -0,0 +1,183 @@ +#include "thread.h" +#include "private-thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_thread_attributes_adjust_) || !defined(_di_f_thread_attributes_decimate_by_) || !defined(_di_f_thread_attributes_decrease_) || !defined(_di_f_thread_attributes_decrease_by_) || !defined(_di_f_thread_attributes_increase_) || !defined(_di_f_thread_attributes_increase_by_) || !defined(_di_f_thread_attributes_resize_) || !defined(_di_f_thread_sets_adjust_) || !defined(_di_f_thread_sets_decimate_by_) || !defined(_di_f_thread_sets_decrease_) || !defined(_di_f_thread_sets_decrease_by_) || !defined(_di_f_thread_sets_increase_) || !defined(_di_f_thread_sets_increase_by_) || !defined(_di_f_thread_sets_resize_) + f_status_t private_f_thread_attribute_delete(f_thread_attribute_t *attribute) { + + if (pthread_attr_destroy(attribute)) { + return F_status_set_error(F_failure); + } + + attribute = 0; + + return F_none; + } +#endif // !defined(_di_f_thread_attributes_adjust_) || !defined(_di_f_thread_attributes_decimate_by_) || !defined(_di_f_thread_attributes_decrease_) || !defined(_di_f_thread_attributes_decrease_by_) || !defined(_di_f_thread_attributes_increase_) || !defined(_di_f_thread_attributes_increase_by_) || !defined(_di_f_thread_attributes_resize_) || !defined(_di_f_thread_sets_adjust_) || !defined(_di_f_thread_sets_decimate_by_) || !defined(_di_f_thread_sets_decrease_) || !defined(_di_f_thread_sets_decrease_by_) || !defined(_di_f_thread_sets_increase_) || !defined(_di_f_thread_sets_increase_by_) || !defined(_di_f_thread_sets_resize_) + +#if !defined(_di_f_thread_attributes_adjust_) || !defined(_di_f_thread_attributes_decimate_by_) + f_status_t private_f_thread_attributes_adjust(const f_array_length_t length, f_thread_attributes_t *attributes) { + f_status_t status = F_none; + + for (f_array_length_t i = length; i < attributes->size; ++i) { + + status = private_f_thread_attribute_delete(&attributes->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(attributes->size, length, sizeof(f_thread_attribute_t), (void **) & attributes->array); + + if (F_status_is_error_not(status)) { + attributes->size = length; + + if (attributes->used > attributes->size) { + attributes->used = length; + } + } + + return status; + } +#endif // !defined(_di_f_thread_attributes_adjust_) || !defined(_di_f_thread_attributes_decimate_by_) + +#if !defined(_di_f_thread_attributes_decrease_) || !defined(_di_f_thread_attributes_decrease_by_) || !defined(_di_f_thread_attributes_increase_) || !defined(_di_f_thread_attributes_increase_by_) + f_status_t private_f_thread_attributes_resize(const f_array_length_t length, f_thread_attributes_t *attributes) { + f_status_t status = F_none; + + for (f_array_length_t i = length; i < attributes->size; ++i) { + + status = private_f_thread_attribute_delete(&attributes->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(attributes->size, length, sizeof(f_thread_attribute_t), (void **) & attributes->array); + + if (F_status_is_error_not(status)) { + attributes->size = length; + + if (attributes->used > attributes->size) { + attributes->used = length; + } + } + + return status; + } +#endif // !defined(_di_f_thread_attributes_decrease_) || !defined(_di_f_thread_attributes_decrease_by_) || !defined(_di_f_thread_attributes_increase_) || !defined(_di_f_thread_attributes_increase_by_) + +#if !defined(_di_f_thread_mutexs_adjust_) || !defined(_di_f_thread_mutexs_decimate_by_) || !defined(_di_f_thread_mutexs_decrease_) || !defined(_di_f_thread_mutexs_decrease_by_) || !defined(_di_f_thread_mutexs_increase_) || !defined(_di_f_thread_mutexs_increase_by_) || !defined(_di_f_thread_mutexs_resize_) + f_status_t private_f_thread_mutex_delete(f_thread_mutex_t *mutex) { + + const int error = pthread_mutex_destroy(mutex); + + if (error) { + if (error == EBUSY) return F_status_set_error(F_busy); + if (error == EINVAL) return F_status_set_error(F_parameter); + + return F_status_set_error(F_failure); + } + + return F_none; + } +#endif // !defined(_di_f_thread_mutexs_adjust_) || !defined(_di_f_thread_mutexs_decimate_by_) || !defined(_di_f_thread_mutexs_decrease_) || !defined(_di_f_thread_mutexs_decrease_by_) || !defined(_di_f_thread_mutexs_increase_) || !defined(_di_f_thread_mutexs_increase_by_) || !defined(_di_f_thread_mutexs_resize_) + +#if !defined(_di_f_thread_mutexs_adjust_) || !defined(_di_f_thread_mutexs_decimate_by_) + f_status_t private_f_thread_mutexs_adjust(const f_array_length_t length, f_thread_mutexs_t *mutexs) { + f_status_t status = F_none; + + for (f_array_length_t i = length; i < mutexs->size; ++i) { + + status = private_f_thread_mutex_delete(&mutexs->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(mutexs->size, length, sizeof(f_thread_mutex_t), (void **) & mutexs->array); + + if (F_status_is_error_not(status)) { + mutexs->size = length; + + if (mutexs->used > mutexs->size) { + mutexs->used = length; + } + } + + return status; + } +#endif // !defined(_di_f_thread_mutexs_adjust_) || !defined(_di_f_thread_mutexs_decimate_by_) + +#if !defined(_di_f_thread_mutexs_decrease_) || !defined(_di_f_thread_mutexs_decrease_by_) || !defined(_di_f_thread_mutexs_increase_) || !defined(_di_f_thread_mutexs_increase_by_) + f_status_t private_f_thread_mutexs_resize(const f_array_length_t length, f_thread_mutexs_t *mutexs) { + f_status_t status = F_none; + + for (f_array_length_t i = length; i < mutexs->size; ++i) { + + status = private_f_thread_mutex_delete(&mutexs->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(mutexs->size, length, sizeof(f_thread_mutex_t), (void **) & mutexs->array); + + if (F_status_is_error_not(status)) { + mutexs->size = length; + + if (mutexs->used > mutexs->size) { + mutexs->used = length; + } + } + + return status; + } +#endif // !defined(_di_f_thread_mutexs_decrease_) || !defined(_di_f_thread_mutexs_decrease_by_) || !defined(_di_f_thread_mutexs_increase_) || !defined(_di_f_thread_mutexs_increase_by_) + +#if !defined(_di_f_thread_sets_adjust_) || !defined(_di_f_thread_sets_decimate_by_) + f_status_t private_f_thread_sets_adjust(const f_array_length_t length, f_thread_sets_t *sets) { + f_status_t status = F_none; + + for (f_array_length_t i = length; i < sets->size; ++i) { + + status = private_f_thread_attribute_delete(&sets->array[i].attribute); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(sets->size, length, sizeof(f_thread_set_t), (void **) & sets->array); + + if (F_status_is_error_not(status)) { + sets->size = length; + + if (sets->used > sets->size) { + sets->used = length; + } + } + + return status; + } +#endif // !defined(_di_f_thread_sets_adjust_) || !defined(_di_f_thread_sets_decimate_by_) + +#if !defined(_di_f_thread_sets_decrease_) || !defined(_di_f_thread_sets_decrease_by_) || !defined(_di_f_thread_sets_increase_) || !defined(_di_f_thread_sets_increase_by_) + f_status_t private_f_thread_sets_resize(const f_array_length_t length, f_thread_sets_t *sets) { + f_status_t status = F_none; + + for (f_array_length_t i = length; i < sets->size; ++i) { + + status = private_f_thread_attribute_delete(&sets->array[i].attribute); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(sets->size, length, sizeof(f_thread_set_t), (void **) & sets->array); + + if (F_status_is_error_not(status)) { + sets->size = length; + + if (sets->used > sets->size) { + sets->used = length; + } + } + + return status; + } +#endif // !defined(_di_f_thread_sets_decrease_) || !defined(_di_f_thread_sets_decrease_by_) || !defined(_di_f_thread_sets_increase_) || !defined(_di_f_thread_sets_increase_by_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/private-thread.h b/level_0/f_thread/c/private-thread.h new file mode 100644 index 0000000..e23ff83 --- /dev/null +++ b/level_0/f_thread/c/private-thread.h @@ -0,0 +1,224 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_thread_h +#define _PRIVATE_F_thread_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for deleting (and destroying). + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param attributes + * The attributes to adjust. + * + * @return + * F_none on success. + * + * F_failure (with error bit) on error. + * + * @see f_thread_attributes_adjust() + * @see f_thread_attributes_decimate_by() + * @see f_thread_attributes_decrease() + * @see f_thread_attributes_decrease_by() + * @see f_thread_attributes_increase() + * @see f_thread_attributes_increase_by() + * @see f_thread_attributes_resize() + * @see f_thread_sets_adjust() + * @see f_thread_sets_decimate_by() + * @see f_thread_sets_decrease() + * @see f_thread_sets_decrease_by() + * @see f_thread_sets_increase() + * @see f_thread_sets_increase_by() + * @see f_thread_sets_resize() + */ +#if !defined(_di_f_thread_attributes_adjust_) || !defined(_di_f_thread_attributes_decimate_by_) || !defined(_di_f_thread_attributes_decrease_) || !defined(_di_f_thread_attributes_decrease_by_) || !defined(_di_f_thread_attributes_increase_) || !defined(_di_f_thread_attributes_increase_by_) || !defined(_di_f_thread_attributes_resize_) || !defined(_di_f_thread_sets_adjust_) || !defined(_di_f_thread_sets_decimate_by_) || !defined(_di_f_thread_sets_decrease_) || !defined(_di_f_thread_sets_decrease_by_) || !defined(_di_f_thread_sets_increase_) || !defined(_di_f_thread_sets_increase_by_) || !defined(_di_f_thread_sets_resize_) + extern f_status_t private_f_thread_attribute_delete(f_thread_attribute_t *attribute) f_gcc_attribute_visibility_internal; +#endif // !defined(_di_f_thread_attributes_adjust_) || !defined(_di_f_thread_attributes_decimate_by_) || !defined(_di_f_thread_attributes_decrease_) || !defined(_di_f_thread_attributes_decrease_by_) || !defined(_di_f_thread_attributes_increase_) || !defined(_di_f_thread_attributes_increase_by_) || !defined(_di_f_thread_sets_adjust_) || !defined(_di_f_thread_sets_decimate_by_) || !defined(_di_f_thread_sets_decrease_) || !defined(_di_f_thread_sets_decrease_by_) || !defined(_di_f_thread_sets_increase_) || !defined(_di_f_thread_sets_increase_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param attributes + * The attributes to adjust. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_thread_attributes_adjust() + * @see f_thread_attributes_decimate_by() + */ +#if !defined(_di_f_thread_attributes_adjust_) || !defined(_di_f_thread_attributes_decimate_by_) + extern f_status_t private_f_thread_attributes_adjust(const f_array_length_t length, f_thread_attributes_t *attributes) f_gcc_attribute_visibility_internal; +#endif // !defined(_di_f_thread_attributes_adjust_) || !defined(_di_f_thread_attributes_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param attributes + * The attributes to resize. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_thread_attributes_decrease_by() + * @see f_thread_attributes_increase() + * @see f_thread_attributes_increase_by() + */ +#if !defined(_di_f_thread_attributes_decrease_by_) || !defined(_di_f_thread_attributes_increase_) || !defined(_di_f_thread_attributes_increase_by_) + extern f_status_t private_f_thread_attributes_resize(const f_array_length_t length, f_thread_attributes_t *attributes) f_gcc_attribute_visibility_internal; +#endif // !defined(_di_f_thread_attributes_decrease_by_) || !defined(_di_f_thread_attributes_increase_) || !defined(_di_f_thread_attributes_increase_by_) + +/** + * Private implementation for deleting (and destroying). + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param mutexs + * The mutexs to adjust. + * + * @return + * F_none on success. + * + * F_failure (with error bit) on error. + * + * @see f_thread_mutexs_adjust() + * @see f_thread_mutexs_decimate_by() + * @see f_thread_mutexs_decrease() + * @see f_thread_mutexs_decrease_by() + * @see f_thread_mutexs_increase() + * @see f_thread_mutexs_increase_by() + * @see f_thread_mutexs_resize() + */ +#if !defined(_di_f_thread_mutexs_adjust_) || !defined(_di_f_thread_mutexs_decimate_by_) || !defined(_di_f_thread_mutexs_decrease_) || !defined(_di_f_thread_mutexs_decrease_by_) || !defined(_di_f_thread_mutexs_increase_) || !defined(_di_f_thread_mutexs_increase_by_) || !defined(_di_f_thread_mutexs_resize_) + extern f_status_t private_f_thread_mutex_delete(f_thread_mutex_t *mutex) f_gcc_attribute_visibility_internal; +#endif // !defined(_di_f_thread_mutexs_adjust_) || !defined(_di_f_thread_mutexs_decimate_by_) || !defined(_di_f_thread_mutexs_decrease_) || !defined(_di_f_thread_mutexs_decrease_by_) || !defined(_di_f_thread_mutexs_increase_) || !defined(_di_f_thread_mutexs_increase_by_) || !defined(_di_f_thread_mutexs_resize_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param mutexs + * The mutexs to adjust. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_thread_mutexs_adjust() + * @see f_thread_mutexs_decimate_by() + */ +#if !defined(_di_f_thread_mutexs_adjust_) || !defined(_di_f_thread_mutexs_decimate_by_) + extern f_status_t private_f_thread_mutexs_adjust(const f_array_length_t length, f_thread_mutexs_t *mutexs) f_gcc_attribute_visibility_internal; +#endif // !defined(_di_f_thread_mutexs_adjust_) || !defined(_di_f_thread_mutexs_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param mutexs + * The mutexs to resize. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_thread_mutexs_decrease_by() + * @see f_thread_mutexs_increase() + * @see f_thread_mutexs_increase_by() + */ +#if !defined(_di_f_thread_mutexs_decrease_by_) || !defined(_di_f_thread_mutexs_increase_) || !defined(_di_f_thread_mutexs_increase_by_) + extern f_status_t private_f_thread_mutexs_resize(const f_array_length_t length, f_thread_mutexs_t *mutexs) f_gcc_attribute_visibility_internal; +#endif // !defined(_di_f_thread_mutexs_decrease_by_) || !defined(_di_f_thread_mutexs_increase_) || !defined(_di_f_thread_mutexs_increase_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param sets + * The sets to adjust. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_thread_sets_adjust() + * @see f_thread_sets_decimate_by() + */ +#if !defined(_di_f_thread_sets_adjust_) || !defined(_di_f_thread_sets_decimate_by_) + extern f_status_t private_f_thread_sets_adjust(const f_array_length_t length, f_thread_sets_t *sets) f_gcc_attribute_visibility_internal; +#endif // !defined(_di_f_thread_sets_adjust_) || !defined(_di_f_thread_sets_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param sets + * The sets to resize. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_thread_sets_decrease_by() + * @see f_thread_sets_increase() + * @see f_thread_sets_increase_by() + */ +#if !defined(_di_f_thread_sets_decrease_by_) || !defined(_di_f_thread_sets_increase_) || !defined(_di_f_thread_sets_increase_by_) + extern f_status_t private_f_thread_sets_resize(const f_array_length_t length, f_thread_sets_t *sets) f_gcc_attribute_visibility_internal; +#endif // !defined(_di_f_thread_sets_decrease_by_) || !defined(_di_f_thread_sets_increase_) || !defined(_di_f_thread_sets_increase_by_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_thread_h diff --git a/level_0/f_thread/c/thread-common.h b/level_0/f_thread/c/thread-common.h index 8f39edf..4131614 100644 --- a/level_0/f_thread/c/thread-common.h +++ b/level_0/f_thread/c/thread-common.h @@ -27,8 +27,6 @@ extern "C" { // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). #define f_macro_thread_attribute_t_clear(attribute) attribute.__align = 0 - #define f_macro_thread_attribute_t_delete(status, attribute) status = f_thread_attribute_delete(&attribute); - #define f_macro_thread_attribute_t_delete_simple(attribute) f_thread_attribute_delete(&attribute); #endif // _di_f_thread_attribute_t_ @@ -49,20 +47,18 @@ extern "C" { #define f_thread_attributes_t_initialize { 0, 0, 0 } - #define f_macro_thread_attributes_t_resize(status, attributes, length) f_macro_memory_structure_resize(status, attributes, f_thread_attribute_t, length) - #define f_macro_thread_attributes_t_adjust(status, attributes, length) f_macro_memory_structure_adjust(status, attributes, f_thread_attribute_t, length) + #define f_macro_thread_attributes_t_clear(attributes) f_macro_memory_structure_clear(attributes) - // @todo implement custom delete functions to call f_thread_attribute_delete() as appropriate. - #define f_macro_thread_attributes_t_delete(status, attributes) f_macro_memory_structure_delete(status, attributes, f_thread_attribute_t) - #define f_macro_thread_attributes_t_destroy(status, attributes) f_macro_memory_structure_destroy(status, attributes, f_thread_attribute_t) + #define f_macro_thread_attributes_t_resize(status, attributes, length) status = f_thread_attributes_resize(length, &attributes); + #define f_macro_thread_attributes_t_adjust(status, attributes, length) status = f_thread_attributes_adjust(length, &attributes); - #define f_macro_thread_attributes_t_delete_simple(attributes) f_macro_memory_structure_delete_simple(attributes, f_thread_attribute_t) - #define f_macro_thread_attributes_t_destroy_simple(attributes) f_macro_memory_structure_destroy_simple(attributes, f_thread_attribute_t) + #define f_macro_thread_attributes_t_delete_simple(attributes) f_thread_attributes_resize(0, &attributes); + #define f_macro_thread_attributes_t_destroy_simple(attributes) f_thread_attributes_adjust(0, &attributes); - #define f_macro_thread_attributes_t_increase(status, attributes) f_macro_memory_structure_increase(status, attributes, f_thread_attribute_t) - #define f_macro_thread_attributes_t_increase_by(status, attributes, amount) f_macro_memory_structure_increase_by(status, attributes, f_thread_attribute_t, amount) - #define f_macro_thread_attributes_t_decrease_by(status, attributes, amount) f_macro_memory_structure_decrease_by(status, attributes, f_thread_attribute_t, amount) - #define f_macro_thread_attributes_t_decimate_by(status, attributes, amount) f_macro_memory_structure_decimate_by(status, attributes, f_thread_attribute_t, amount) + #define f_macro_thread_attributes_t_increase(status, attributes) status = f_thread_attributes_increase(attributes); + #define f_macro_thread_attributes_t_increase_by(status, attributes, amount) status = f_thread_attributes_increase_by(amount, attributes); + #define f_macro_thread_attributes_t_decrease_by(status, attributes, amount) status = f_thread_attributes_decrease_by(amount, attributes); + #define f_macro_thread_attributes_t_decimate_by(status, attributes, amount) status = f_thread_attributes_decimate_by(amount, attributes); #endif // _di_f_thread_attributes_t_ /** @@ -96,9 +92,6 @@ extern "C" { #define f_macro_thread_conditions_t_resize(status, conditions, length) f_macro_memory_structure_resize(status, conditions, f_thread_condition_t, length) #define f_macro_thread_conditions_t_adjust(status, conditions, length) f_macro_memory_structure_adjust(status, conditions, f_thread_condition_t, length) - #define f_macro_thread_conditions_t_delete(status, conditions) f_macro_memory_structure_delete(status, conditions, f_thread_condition_t) - #define f_macro_thread_conditions_t_destroy(status, conditions) f_macro_memory_structure_destroy(status, conditions, f_thread_condition_t) - #define f_macro_thread_conditions_t_delete_simple(conditions) f_macro_memory_structure_delete_simple(conditions, f_thread_condition_t) #define f_macro_thread_conditions_t_destroy_simple(conditions) f_macro_memory_structure_destroy_simple(conditions, f_thread_condition_t) @@ -139,9 +132,6 @@ extern "C" { #define f_macro_thread_ids_t_resize(status, ids, length) f_macro_memory_structure_resize(status, ids, f_thread_id_t, length) #define f_macro_thread_ids_t_adjust(status, ids, length) f_macro_memory_structure_adjust(status, ids, f_thread_id_t, length) - #define f_macro_thread_ids_t_delete(status, ids) f_macro_memory_structure_delete(status, ids, f_thread_id_t) - #define f_macro_thread_ids_t_destroy(status, ids) f_macro_memory_structure_destroy(status, ids, f_thread_id_t) - #define f_macro_thread_ids_t_delete_simple(ids) f_macro_memory_structure_delete_simple(ids, f_thread_id_t) #define f_macro_thread_ids_t_destroy_simple(ids) f_macro_memory_structure_destroy_simple(ids, f_thread_id_t) @@ -182,9 +172,6 @@ extern "C" { #define f_macro_thread_keys_t_resize(status, keys, length) f_macro_memory_structure_resize(status, keys, f_thread_key_t, length) #define f_macro_thread_keys_t_adjust(status, keys, length) f_macro_memory_structure_adjust(status, keys, f_thread_key_t, length) - #define f_macro_thread_keys_t_delete(status, keys) f_macro_memory_structure_delete(status, keys, f_thread_key_t) - #define f_macro_thread_keys_t_destroy(status, keys) f_macro_memory_structure_destroy(status, keys, f_thread_key_t) - #define f_macro_thread_keys_t_delete_simple(keys) f_macro_memory_structure_delete_simple(keys, f_thread_key_t) #define f_macro_thread_keys_t_destroy_simple(keys) f_macro_memory_structure_destroy_simple(keys, f_thread_key_t) @@ -225,9 +212,6 @@ extern "C" { #define f_macro_thread_locks_t_resize(status, locks, length) f_macro_memory_structure_resize(status, locks, f_thread_lock_t, length) #define f_macro_thread_locks_t_adjust(status, locks, length) f_macro_memory_structure_adjust(status, locks, f_thread_lock_t, length) - #define f_macro_thread_locks_t_delete(status, locks) f_macro_memory_structure_delete(status, locks, f_thread_lock_t) - #define f_macro_thread_locks_t_destroy(status, locks) f_macro_memory_structure_destroy(status, locks, f_thread_lock_t) - #define f_macro_thread_locks_t_delete_simple(locks) f_macro_memory_structure_delete_simple(locks, f_thread_lock_t) #define f_macro_thread_locks_t_destroy_simple(locks) f_macro_memory_structure_destroy_simple(locks, f_thread_lock_t) @@ -247,8 +231,6 @@ extern "C" { #define f_macro_thread_mutex_t_clear(mutex) mutex = 0 - #define f_macro_thread_mutex_t_delete(status, mutex) status = f_thread_mutex_delete(&mutex); - #define f_macro_thread_mutex_t_delete_simple(mutex) f_thread_mutex_delete(&mutex); #endif // _di_f_thread_mutex_t_ @@ -269,20 +251,18 @@ extern "C" { #define f_thread_mutexs_t_initialize { 0, 0, 0 } - #define f_macro_thread_mutexs_t_resize(status, mutexs, length) f_macro_memory_structure_resize(status, mutexs, f_thread_mutex_t, length) - #define f_macro_thread_mutexs_t_adjust(status, mutexs, length) f_macro_memory_structure_adjust(status, mutexs, f_thread_mutex_t, length) + #define f_macro_thread_mutexs_t_clear(mutexs) f_macro_memory_structure_clear(mutexs) - // @todo implement custom delete functions to call f_thread_mutex_delete() as appropriate. - #define f_macro_thread_mutexs_t_delete(status, mutexs) f_macro_memory_structure_delete(status, mutexs, f_thread_mutex_t) - #define f_macro_thread_mutexs_t_destroy(status, mutexs) f_macro_memory_structure_destroy(status, mutexs, f_thread_mutex_t) + #define f_macro_thread_mutexs_t_resize(status, mutexs, length) status = f_thread_mutexs_resize(length, &mutexs); + #define f_macro_thread_mutexs_t_adjust(status, mutexs, length) status = f_thread_mutexs_adjust(length, &mutexs); - #define f_macro_thread_mutexs_t_delete_simple(mutexs) f_macro_memory_structure_delete_simple(mutexs, f_thread_mutex_t) - #define f_macro_thread_mutexs_t_destroy_simple(mutexs) f_macro_memory_structure_destroy_simple(mutexs, f_thread_mutex_t) + #define f_macro_thread_mutexs_t_delete_simple(mutexs) f_thread_mutexs_resize(0, &mutexs); + #define f_macro_thread_mutexs_t_destroy_simple(mutexs) f_thread_mutexs_adjust(0, &mutexs); - #define f_macro_thread_mutexs_t_increase(status, mutexs) f_macro_memory_structure_increase(status, mutexs, f_thread_mutex_t) - #define f_macro_thread_mutexs_t_increase_by(status, mutexs, amount) f_macro_memory_structure_increase_by(status, mutexs, f_thread_mutex_t, amount) - #define f_macro_thread_mutexs_t_decrease_by(status, mutexs, amount) f_macro_memory_structure_decrease_by(status, mutexs, f_thread_mutex_t, amount) - #define f_macro_thread_mutexs_t_decimate_by(status, mutexs, amount) f_macro_memory_structure_decimate_by(status, mutexs, f_thread_mutex_t, amount) + #define f_macro_thread_mutexs_t_increase(status, mutexs) status = f_thread_mutexs_increase(mutexs); + #define f_macro_thread_mutexs_t_increase_by(status, mutexs, amount) status = f_thread_mutexs_increase_by(amount, mutexs); + #define f_macro_thread_mutexs_t_decrease_by(status, mutexs, amount) status = f_thread_mutexs_decrease_by(amount, mutexs); + #define f_macro_thread_mutexs_t_decimate_by(status, mutexs, amount) status = f_thread_mutexs_decimate_by(amount, mutexs); #endif // _di_f_thread_mutexs_t_ /** @@ -316,9 +296,6 @@ extern "C" { #define f_macro_thread_mutex_attributes_t_resize(status, mutex_attributes, length) f_macro_memory_structure_resize(status, mutex_attributes, f_thread_mutex_attribute_t, length) #define f_macro_thread_mutex_attributes_t_adjust(status, mutex_attributes, length) f_macro_memory_structure_adjust(status, mutex_attributes, f_thread_mutex_attribute_t, length) - #define f_macro_thread_mutex_attributes_t_delete(status, mutex_attributes) f_macro_memory_structure_delete(status, mutex_attributes, f_thread_mutex_attribute_t) - #define f_macro_thread_mutex_attributes_t_destroy(status, mutex_attributes) f_macro_memory_structure_destroy(status, mutex_attributes, f_thread_mutex_attribute_t) - #define f_macro_thread_mutex_attributes_t_delete_simple(mutex_attributes) f_macro_memory_structure_delete_simple(mutex_attributes, f_thread_mutex_attribute_t) #define f_macro_thread_mutex_attributes_t_destroy_simple(mutex_attributes) f_macro_memory_structure_destroy_simple(mutex_attributes, f_thread_mutex_attribute_t) @@ -359,9 +336,6 @@ extern "C" { #define f_macro_thread_onces_t_resize(status, onces, length) f_macro_memory_structure_resize(status, onces, f_thread_once_t, length) #define f_macro_thread_onces_t_adjust(status, onces, length) f_macro_memory_structure_adjust(status, onces, f_thread_once_t, length) - #define f_macro_thread_onces_t_delete(status, onces) f_macro_memory_structure_delete(status, onces, f_thread_once_t) - #define f_macro_thread_onces_t_destroy(status, onces) f_macro_memory_structure_destroy(status, onces, f_thread_once_t) - #define f_macro_thread_onces_t_delete_simple(onces) f_macro_memory_structure_delete_simple(onces, f_thread_once_t) #define f_macro_thread_onces_t_destroy_simple(onces) f_macro_memory_structure_destroy_simple(onces, f_thread_once_t) @@ -374,13 +348,13 @@ extern "C" { /** * A structure containing basic thread information. * - * attributes: The thread attributes (which is a union). - * id: The thread identifier. - * result: The result of the thread on exit. + * attribute: The thread attributes (which is a union). + * id: The thread identifier. + * result: The result of the thread on exit. */ #ifndef _di_f_thread_set_t_ typedef struct { - f_thread_attribute_t attributes; + f_thread_attribute_t attribute; f_thread_id_t id; int result; } f_thread_set_t; @@ -388,11 +362,9 @@ extern "C" { #define f_thread_set_t_initialize { f_thread_attribute_t_initialize, f_thread_id_t_initialize, 0 } #define f_macro_thread_set_t_clear(thread) \ - f_macro_thread_attribute_t_clear(thread.attributes) \ + f_macro_thread_attribute_t_clear(thread.attribute) \ f_macro_thread_id_t_clear(thread.id) - #define f_macro_thread_set_t_delete(status, set) f_macro_thread_attribute_t_delete(status, set.attribute) - #define f_macro_thread_set_t_delete_simple(set) f_macro_thread_attribute_t_delete_simple(set.attribute) #endif // _di_f_thread_set_t_ @@ -413,20 +385,18 @@ extern "C" { #define f_thread_sets_t_initialize { 0, 0, 0 } - #define f_macro_thread_sets_t_resize(status, sets, length) f_macro_memory_structure_resize(status, sets, f_thread_set_t, length) - #define f_macro_thread_sets_t_adjust(status, sets, length) f_macro_memory_structure_adjust(status, sets, f_thread_set_t, length) + #define f_macro_thread_sets_t_clear(sets) f_macro_memory_structure_clear(sets) - // @todo implement custom delete functions to call f_macro_thread_set_t_delete() as appropriate. - #define f_macro_thread_sets_t_delete(status, sets) f_macro_memory_structure_delete(status, sets, f_thread_set_t) - #define f_macro_thread_sets_t_destroy(status, sets) f_macro_memory_structure_destroy(status, sets, f_thread_set_t) + #define f_macro_thread_sets_t_resize(status, sets, length) status = f_thread_sets_resize(length, &sets); + #define f_macro_thread_sets_t_adjust(status, sets, length) status = f_thread_sets_adjust(length, &sets); - #define f_macro_thread_sets_t_delete_simple(sets) f_macro_memory_structure_delete_simple(sets, f_thread_set_t) - #define f_macro_thread_sets_t_destroy_simple(sets) f_macro_memory_structure_destroy_simple(sets, f_thread_set_t) + #define f_macro_thread_sets_t_delete_simple(sets) f_thread_sets_resize(0, &sets); + #define f_macro_thread_sets_t_destroy_simple(sets) f_thread_sets_adjust(0, &sets); - #define f_macro_thread_sets_t_increase(status, sets) f_macro_memory_structure_increase(status, sets, f_thread_set_t) - #define f_macro_thread_sets_t_increase_by(status, sets, amount) f_macro_memory_structure_increase_by(status, sets, f_thread_set_t, amount) - #define f_macro_thread_sets_t_decrease_by(status, sets, amount) f_macro_memory_structure_decrease_by(status, sets, f_thread_set_t, amount) - #define f_macro_thread_sets_t_decimate_by(status, sets, amount) f_macro_memory_structure_decimate_by(status, sets, f_thread_set_t, amount) + #define f_macro_thread_sets_t_increase(status, sets) status = f_thread_sets_increase(sets); + #define f_macro_thread_sets_t_increase_by(status, sets, amount) status = f_thread_sets_increase_by(amount, sets); + #define f_macro_thread_sets_t_decrease_by(status, sets, amount) status = f_thread_sets_decrease_by(amount, sets); + #define f_macro_thread_sets_t_decimate_by(status, sets, amount) status = f_thread_sets_decimate_by(amount, sets); #endif // _di_f_thread_sets_t_ #ifdef __cplusplus diff --git a/level_0/f_thread/c/thread.c b/level_0/f_thread/c/thread.c index e56a428..1819f98 100644 --- a/level_0/f_thread/c/thread.c +++ b/level_0/f_thread/c/thread.c @@ -1,4 +1,5 @@ #include "thread.h" +#include "private-thread.h" #ifdef __cplusplus extern "C" { @@ -122,15 +123,7 @@ extern "C" { if (!attribute) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - const int error = pthread_attr_destroy(attribute); - - if (error) { - return F_status_set_error(F_failure); - } - - attribute = 0; - - return F_none; + return private_f_thread_attribute_delete(attribute); } #endif // _di_f_thread_attribute_delete_ @@ -389,6 +382,99 @@ extern "C" { } #endif // _di_f_thread_attribute_stack_set_ +#ifndef _di_f_thread_attributes_adjust_ + f_status_t f_thread_attributes_adjust(const f_array_length_t length, f_thread_attributes_t *attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_attributes_adjust(length, attributes); + } +#endif // _di_f_thread_attributes_adjust_ + +#ifndef _di_f_thread_attributes_decimate_by_ + f_status_t f_thread_attributes_decimate_by(const f_array_length_t amount, f_thread_attributes_t *attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (attributes->size - amount > 0) { + return private_f_thread_attributes_adjust(attributes->size - amount, attributes); + } + + return private_f_thread_attributes_adjust(0, attributes); + } +#endif // _di_f_thread_attributes_decimate_by_ + +#ifndef _di_f_thread_attributes_decrease_by_ + f_status_t f_thread_attributes_decrease_by(const f_array_length_t amount, f_thread_attributes_t *attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (attributes->size - amount > 0) { + return private_f_thread_attributes_resize(attributes->size - amount, attributes); + } + + return private_f_thread_attributes_resize(0, attributes); + } +#endif // _di_f_thread_attributes_decrease_by_ + +#ifndef _di_f_thread_attributes_increase_ + f_status_t f_thread_attributes_increase(f_thread_attributes_t *attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (attributes->used + 1 > attributes->size) { + f_array_length_t size = attributes->used + f_memory_default_allocation_step; + + if (size > f_array_length_t_size) { + if (attributes->used + 1 > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + size = f_array_length_t_size; + } + + return private_f_thread_attributes_resize(size, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_attributes_increase_ + +#ifndef _di_f_thread_attributes_increase_by_ + f_status_t f_thread_attributes_increase_by(const f_array_length_t amount, f_thread_attributes_t *attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (attributes->used + amount > attributes->size) { + if (attributes->used + amount > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_attributes_resize(attributes->used + amount, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_attributes_increase_by_ + +#ifndef _di_f_thread_attributes_resize_ + f_status_t f_thread_attributes_resize(const f_array_length_t length, f_thread_attributes_t *attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_attributes_resize(length, attributes); + } +#endif // _di_f_thread_attributes_resize_ + #ifndef _di_f_thread_caller_ f_thread_id_t f_thread_caller() { return pthread_self(); @@ -760,16 +846,7 @@ extern "C" { if (!mutex) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - const int error = pthread_mutex_destroy(mutex); - - if (error) { - if (error == EBUSY) return F_status_set_error(F_busy); - if (error == EINVAL) return F_status_set_error(F_parameter); - - return F_status_set_error(F_failure); - } - - return F_none; + return private_f_thread_mutex_delete(mutex); } #endif // _di_f_thread_mutex_delete_ @@ -834,6 +911,99 @@ extern "C" { } #endif // _di_f_thread_mutex_unlock_ +#ifndef _di_f_thread_mutexs_adjust_ + f_status_t f_thread_mutexs_adjust(const f_array_length_t length, f_thread_mutexs_t *mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_mutexs_adjust(length, mutexs); + } +#endif // _di_f_thread_mutexs_adjust_ + +#ifndef _di_f_thread_mutexs_decimate_by_ + f_status_t f_thread_mutexs_decimate_by(const f_array_length_t amount, f_thread_mutexs_t *mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (mutexs->size - amount > 0) { + return private_f_thread_mutexs_adjust(mutexs->size - amount, mutexs); + } + + return private_f_thread_mutexs_adjust(0, mutexs); + } +#endif // _di_f_thread_mutexs_decimate_by_ + +#ifndef _di_f_thread_mutexs_decrease_by_ + f_status_t f_thread_mutexs_decrease_by(const f_array_length_t amount, f_thread_mutexs_t *mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (mutexs->size - amount > 0) { + return private_f_thread_mutexs_resize(mutexs->size - amount, mutexs); + } + + return private_f_thread_mutexs_resize(0, mutexs); + } +#endif // _di_f_thread_mutexs_decrease_by_ + +#ifndef _di_f_thread_mutexs_increase_ + f_status_t f_thread_mutexs_increase(f_thread_mutexs_t *mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (mutexs->used + 1 > mutexs->size) { + f_array_length_t size = mutexs->used + f_memory_default_allocation_step; + + if (size > f_array_length_t_size) { + if (mutexs->used + 1 > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + size = f_array_length_t_size; + } + + return private_f_thread_mutexs_resize(size, mutexs); + } + + return F_data_not; + } +#endif // _di_f_thread_mutexs_increase_ + +#ifndef _di_f_thread_mutexs_increase_by_ + f_status_t f_thread_mutexs_increase_by(const f_array_length_t amount, f_thread_mutexs_t *mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (mutexs->used + amount > mutexs->size) { + if (mutexs->used + amount > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_mutexs_resize(mutexs->used + amount, mutexs); + } + + return F_data_not; + } +#endif // _di_f_thread_mutexs_increase_by_ + +#ifndef _di_f_thread_mutexs_resize_ + f_status_t f_thread_mutexs_resize(const f_array_length_t length, f_thread_mutexs_t *mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_mutexs_resize(length, mutexs); + } +#endif // _di_f_thread_mutexs_resize_ + #ifndef _di_f_thread_once_ f_status_t f_thread_once(void (*routine) (void), f_thread_once_t *once) { #ifndef _di_level_0_parameter_checking_ @@ -853,6 +1023,99 @@ extern "C" { } #endif // _di_f_thread_once_ +#ifndef _di_f_thread_sets_adjust_ + f_status_t f_thread_sets_adjust(const f_array_length_t length, f_thread_sets_t *sets) { + #ifndef _di_level_0_parameter_checking_ + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_sets_adjust(length, sets); + } +#endif // _di_f_thread_sets_adjust_ + +#ifndef _di_f_thread_sets_decimate_by_ + f_status_t f_thread_sets_decimate_by(const f_array_length_t amount, f_thread_sets_t *sets) { + #ifndef _di_level_0_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (sets->size - amount > 0) { + return private_f_thread_sets_adjust(sets->size - amount, sets); + } + + return private_f_thread_sets_adjust(0, sets); + } +#endif // _di_f_thread_sets_decimate_by_ + +#ifndef _di_f_thread_sets_decrease_by_ + f_status_t f_thread_sets_decrease_by(const f_array_length_t amount, f_thread_sets_t *sets) { + #ifndef _di_level_0_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (sets->size - amount > 0) { + return private_f_thread_sets_resize(sets->size - amount, sets); + } + + return private_f_thread_sets_resize(0, sets); + } +#endif // _di_f_thread_sets_decrease_by_ + +#ifndef _di_f_thread_sets_increase_ + f_status_t f_thread_sets_increase(f_thread_sets_t *sets) { + #ifndef _di_level_0_parameter_checking_ + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (sets->used + 1 > sets->size) { + f_array_length_t size = sets->used + f_memory_default_allocation_step; + + if (size > f_array_length_t_size) { + if (sets->used + 1 > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + size = f_array_length_t_size; + } + + return private_f_thread_sets_resize(size, sets); + } + + return F_data_not; + } +#endif // _di_f_thread_sets_increase_ + +#ifndef _di_f_thread_sets_increase_by_ + f_status_t f_thread_sets_increase_by(const f_array_length_t amount, f_thread_sets_t *sets) { + #ifndef _di_level_0_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (sets->used + amount > sets->size) { + if (sets->used + amount > f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_sets_resize(sets->used + amount, sets); + } + + return F_data_not; + } +#endif // _di_f_thread_sets_increase_by_ + +#ifndef _di_f_thread_sets_resize_ + f_status_t f_thread_sets_resize(const f_array_length_t length, f_thread_sets_t *sets) { + #ifndef _di_level_0_parameter_checking_ + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_sets_resize(length, sets); + } +#endif // _di_f_thread_sets_resize_ + #ifndef _di_f_thread_signal_ f_status_t f_thread_signal(const f_thread_id_t id, const int signal) { diff --git a/level_0/f_thread/c/thread.h b/level_0/f_thread/c/thread.h index 03b7d52..436a86f 100644 --- a/level_0/f_thread/c/thread.h +++ b/level_0/f_thread/c/thread.h @@ -44,6 +44,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_memory_not (with error bit) if out of memory. * F_failure (with error bit) on any other error. @@ -66,6 +67,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -87,6 +89,7 @@ extern "C" { * * @return * F_none on success. + * * F_memory_not (with error bit) if out of memory. * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. @@ -105,6 +108,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_memory_not (with error bit) if out of memory. * F_failure (with error bit) on any other error. @@ -123,6 +127,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -140,6 +145,7 @@ extern "C" { * * @return * F_none on success. + * * F_memory_not (with error bit) if out of memory. * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. @@ -155,11 +161,15 @@ extern "C" { * * On successfully delete, the pointer address is set to 0. * + * The pthread_attr_destroy() function has no distinction like the *_destroy() and the *_delete() used by the FLL project. + * Therefore there is only this function for both deleting and destroying. + * * @param attribute * The thread attributes to delete. * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -179,6 +189,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -198,6 +209,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -217,6 +229,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -236,6 +249,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -255,6 +269,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -274,6 +289,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -293,6 +309,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -312,6 +329,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -331,6 +349,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -350,6 +369,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -369,6 +389,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -388,6 +409,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_supported_not (with error bit) if the scope is not supported by the current OS (such as Linux not supporting PTHREAD_SCOPE_PROCESS). * F_failure (with error bit) on any other error. @@ -410,6 +432,7 @@ extern "C" { * * @return * F_none on success. + * * F_access_denied (with error bit) if the caller cannot both read and write to the stack address. * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. @@ -432,6 +455,7 @@ extern "C" { * * @return * F_none on success. + * * F_access_denied (with error bit) if the caller cannot both read and write to the stack address. * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. @@ -443,6 +467,131 @@ extern "C" { #endif // _di_f_thread_attribute_stack_set_ /** + * Resize the string attributes array. + * + * @param length + * The new size to use. + * @param attributes + * The string attributes array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_attributes_adjust_ + extern f_status_t f_thread_attributes_adjust(const f_array_length_t length, f_thread_attributes_t *attributes); +#endif // _di_f_thread_attributes_adjust_ + +/** + * Resize the string attributes array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decimate the size by. + * @param attributes + * The string attributes array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_attributes_decimate_by_ + extern f_status_t f_thread_attributes_decimate_by(const f_array_length_t amount, f_thread_attributes_t *attributes); +#endif // _di_f_thread_attributes_decimate_by_ + +/** + * Resize the string attributes array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param attributes + * The string attributes array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_attributes_decrease_by_ + extern f_status_t f_thread_attributes_decrease_by(const f_array_length_t amount, f_thread_attributes_t *attributes); +#endif // _di_f_thread_attributes_decrease_by_ + +/** + * Increase the size of the string attributes array, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param attributes + * The string attributes array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_attributes_increase_ + extern f_status_t f_thread_attributes_increase(f_thread_attributes_t *attributes); +#endif // _di_f_thread_attributes_increase_ + +/** + * Resize the string attributes array to a larger size. + * + * This will resize making the string larger based on the given length. + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param amount + * A positive number representing how much to increase the size by. + * @param attributes + * The string attributes array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * F_array_too_large (with error bit) if the new array length is too large. + */ +#ifndef _di_f_thread_attributes_increase_by_ + extern f_status_t f_thread_attributes_increase_by(const f_array_length_t amount, f_thread_attributes_t *attributes); +#endif // _di_f_thread_attributes_increase_by_ + +/** + * Resize the string attributes array. + * + * @param length + * The new size to use. + * @param attributes + * The string attributes array to adjust. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_attributes_resize_ + extern f_status_t f_thread_attributes_resize(const f_array_length_t length, f_thread_attributes_t *attributes); +#endif // _di_f_thread_attributes_resize_ + +/** * Get the ID of the calling thread. * * @return @@ -462,6 +611,7 @@ extern "C" { * * @return * F_none on success. + * * F_found_not (with error bit) if no thread by the given ID was found. * F_failure (with error bit) on any other error. * @@ -483,6 +633,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -519,6 +670,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -538,6 +690,7 @@ extern "C" { * * @return * F_none on success. + * * F_found_not (with error bit) if no thread by the given ID was found. * F_supported_not (with error bit) if per-CPU clocks are not supported by the OS. * F_failure (with error bit) on any other error. @@ -572,6 +725,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -589,6 +743,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -610,6 +765,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. * @@ -636,6 +792,7 @@ extern "C" { * @return * F_none on success. * F_time on success, and wait timeout was reached before condition was triggered. + * * F_parameter (with error bit) if a parameter is invalid. * F_prohibited (with error bit) if not allowed to perform the operation (possibly because mutex is not owned by current thread). * F_failure (with error bit) on any other error. @@ -663,6 +820,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_prohibited (with error bit) if not allowed to set the scheduling policy and parameters specified in attribute. * F_resource_not (with error bit) if there are not enough resources to create another thread. @@ -688,6 +846,7 @@ extern "C" { * * @return * F_none on success. + * * F_deadlock (with error bit) if operation would cause a deadlock.ead. * F_found_not (with error bit) if no thread by the given ID was found. * F_parameter (with error bit) if a parameter is invalid. @@ -708,6 +867,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * * @see pthread_exit() @@ -730,6 +890,7 @@ extern "C" { * * @return * F_none on success. + * * F_deadlock (with error bit) if operation would cause a deadlock.ead. * F_found_not (with error bit) if no thread by the given ID was found. * F_parameter (with error bit) if a parameter is invalid. @@ -757,6 +918,7 @@ extern "C" { * @return * F_none on success. * F_busy on success, but thread could not be joined because it has not yet exited. + * * F_deadlock (with error bit) if operation would cause a deadlock.ead. * F_found_not (with error bit) if no thread by the given ID was found. * F_parameter (with error bit) if a parameter is invalid. @@ -789,6 +951,7 @@ extern "C" { * F_none on success. * F_busy on success, but thread could not be joined because it has not yet exited. * F_time on success, but thread could not be joined because it has not yet exited and the wait timeout was reached. + * * F_deadlock (with error bit) if operation would cause a deadlock. * F_found_not (with error bit) if no thread by the given ID was found. * F_parameter (with error bit) if a parameter is invalid. @@ -811,6 +974,7 @@ extern "C" { * * @return * F_none on success. + * * F_memory_not (with error bit) if out of memory. * F_parameter (with error bit) if a parameter is invalid. * F_prohibited (with error bit) if not allowed to set the scheduling policy and parameters specified in attribute. @@ -832,6 +996,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * * @see pthread_getspecific() @@ -850,6 +1015,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * * @see pthread_setspecific() @@ -866,6 +1032,7 @@ extern "C" { * * @return * F_none on success. + * * F_deadlock (with error bit) if operation would cause a deadlock. * F_parameter (with error bit) if a parameter is invalid. * F_resource_not (with error bit) if max read/write locks is reached. @@ -885,6 +1052,7 @@ extern "C" { * @return * F_none on success. * F_busy on success, but the read/write lock is already locked. + * * F_parameter (with error bit) if a parameter is invalid. * F_resource_not (with error bit) if max read/write locks is reached. * @@ -905,6 +1073,7 @@ extern "C" { * * @return * F_none on success. + * * F_busy (with error bit) if the mutex is busy. * F_memory_not (with error bit) if out of memory. * F_parameter (with error bit) if a parameter is invalid. @@ -919,13 +1088,17 @@ extern "C" { #endif // _di_f_thread_mutex_create_ /** - * Create a thread mutex. + * Delete a thread mutex. + * + * The pthread_mutex_destroy() function has no distinction like the *_destroy() and the *_delete() used by the FLL project. + * Therefore there is only this function for both deleting and destroying. * * @param mutex * The mutex to delete. * * @return * F_none on success. + * * F_busy (with error bit) if the mutex is busy. * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) on any other error. @@ -946,6 +1119,7 @@ extern "C" { * * @return * F_none on success. + * * F_deadlock (with error bit) if operation would cause a deadlock. * F_parameter (with error bit) if a parameter is invalid. * F_resource_not (with error bit) if max mutex locks is reached. @@ -969,6 +1143,7 @@ extern "C" { * @return * F_none on success. * F_busy on success, but the mutex is already locked. + * * F_parameter (with error bit) if a parameter is invalid. * F_resource_not (with error bit) if max mutex locks is reached. * @@ -986,6 +1161,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * F_prohibited (with error bit) if not allowed to perform the operation (possibly because mutex is not owned by current thread). * F_resource_not (with error bit) if max mutex locks is reached. @@ -997,6 +1173,131 @@ extern "C" { #endif // _di_f_thread_mutex_unlock_ /** + * Resize the string mutexs array. + * + * @param length + * The new size to use. + * @param mutexs + * The string mutexs array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_mutexs_adjust_ + extern f_status_t f_thread_mutexs_adjust(const f_array_length_t length, f_thread_mutexs_t *mutexs); +#endif // _di_f_thread_mutexs_adjust_ + +/** + * Resize the string mutexs array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decimate the size by. + * @param mutexs + * The string mutexs array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_mutexs_decimate_by_ + extern f_status_t f_thread_mutexs_decimate_by(const f_array_length_t amount, f_thread_mutexs_t *mutexs); +#endif // _di_f_thread_mutexs_decimate_by_ + +/** + * Resize the string mutexs array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param mutexs + * The string mutexs array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_mutexs_decrease_by_ + extern f_status_t f_thread_mutexs_decrease_by(const f_array_length_t amount, f_thread_mutexs_t *mutexs); +#endif // _di_f_thread_mutexs_decrease_by_ + +/** + * Increase the size of the string mutexs array, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param mutexs + * The string mutexs array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_mutexs_increase_ + extern f_status_t f_thread_mutexs_increase(f_thread_mutexs_t *mutexs); +#endif // _di_f_thread_mutexs_increase_ + +/** + * Resize the string mutexs array to a larger size. + * + * This will resize making the string larger based on the given length. + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param amount + * A positive number representing how much to increase the size by. + * @param mutexs + * The string mutexs array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * F_array_too_large (with error bit) if the new array length is too large. + */ +#ifndef _di_f_thread_mutexs_increase_by_ + extern f_status_t f_thread_mutexs_increase_by(const f_array_length_t amount, f_thread_mutexs_t *mutexs); +#endif // _di_f_thread_mutexs_increase_by_ + +/** + * Resize the string mutexs array. + * + * @param length + * The new size to use. + * @param mutexs + * The string mutexs array to adjust. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_mutexs_resize_ + extern f_status_t f_thread_mutexs_resize(const f_array_length_t length, f_thread_mutexs_t *mutexs); +#endif // _di_f_thread_mutexs_resize_ + +/** * Call the given routine only one time and never again. * * Subsequent calls will not call the given routine. @@ -1006,6 +1307,7 @@ extern "C" { * * @return * F_none on success. + * * F_parameter (with error bit) if a parameter is invalid. * * @see pthread_once() @@ -1015,6 +1317,131 @@ extern "C" { #endif // _di_f_thread_once_ /** + * Resize the string sets array. + * + * @param length + * The new size to use. + * @param sets + * The string sets array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_sets_adjust_ + extern f_status_t f_thread_sets_adjust(const f_array_length_t length, f_thread_sets_t *sets); +#endif // _di_f_thread_sets_adjust_ + +/** + * Resize the string sets array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decimate the size by. + * @param sets + * The string sets array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_sets_decimate_by_ + extern f_status_t f_thread_sets_decimate_by(const f_array_length_t amount, f_thread_sets_t *sets); +#endif // _di_f_thread_sets_decimate_by_ + +/** + * Resize the string sets array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param sets + * The string sets array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_sets_decrease_by_ + extern f_status_t f_thread_sets_decrease_by(const f_array_length_t amount, f_thread_sets_t *sets); +#endif // _di_f_thread_sets_decrease_by_ + +/** + * Increase the size of the string sets array, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param sets + * The string sets array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_sets_increase_ + extern f_status_t f_thread_sets_increase(f_thread_sets_t *sets); +#endif // _di_f_thread_sets_increase_ + +/** + * Resize the string sets array to a larger size. + * + * This will resize making the string larger based on the given length. + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param amount + * A positive number representing how much to increase the size by. + * @param sets + * The string sets array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * F_array_too_large (with error bit) if the new array length is too large. + */ +#ifndef _di_f_thread_sets_increase_by_ + extern f_status_t f_thread_sets_increase_by(const f_array_length_t amount, f_thread_sets_t *sets); +#endif // _di_f_thread_sets_increase_by_ + +/** + * Resize the string sets array. + * + * @param length + * The new size to use. + * @param sets + * The string sets array to adjust. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_sets_resize_ + extern f_status_t f_thread_sets_resize(const f_array_length_t length, f_thread_sets_t *sets); +#endif // _di_f_thread_sets_resize_ + +/** * Send a signal to the given thread. * * @param id @@ -1026,6 +1453,7 @@ extern "C" { * @return * F_none on success and signal is not 0. * F_found on success, signal is 0, and the thread by the given ID does exist. + * * F_found_not on success, signal is 0, and the thread by the given ID does not exist. * F_found_not (with error bit) if no thread by the given ID was found (and signal is not 0). * F_parameter (with error bit) if a parameter is invalid. @@ -1053,6 +1481,7 @@ extern "C" { * * @return * F_none on success but no signal found. + * * F_parameter (with error bit) if a parameter is invalid. * F_failure (with error bit) for any other error. * @@ -1074,6 +1503,7 @@ extern "C" { * * @return * F_none on success but no signal found. + * * F_found_not (with error bit) if no thread by the given ID was found. * F_parameter (with error bit) if a parameter is invalid. * F_resource_not (with error bit) if the max signals is reached. diff --git a/level_0/f_thread/data/build/settings b/level_0/f_thread/data/build/settings index 80deffd..204bc1a 100644 --- a/level_0/f_thread/data/build/settings +++ b/level_0/f_thread/data/build/settings @@ -20,7 +20,7 @@ build_indexer ar build_language c build_libraries -pthread -lc build_libraries-individual -lf_memory -build_sources_library thread.c +build_sources_library thread.c private-thread.c build_sources_program build_sources_headers thread.h thread-common.h build_sources_script -- 1.8.3.1