From: Kevin Day Date: Mon, 27 Jun 2022 01:52:48 +0000 (-0500) Subject: Bugfix: Problems and clean ups exposed when writing f_thread unit tests. X-Git-Tag: 0.5.10~14 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=71360406c954df008b078d63002df76610a60c4d;p=fll Bugfix: Problems and clean ups exposed when writing f_thread unit tests. This in particular extracts the structure related functions into separate files to better follow the functional oriented programming practice. --- diff --git a/build/level_0/settings b/build/level_0/settings index 6984dec..1d81a18 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -45,9 +45,8 @@ build_sources_library type_array/array_length.c type_array/cell.c type_array/fll build_sources_library type_array/private-array_length.c type_array/private-cell.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c build_sources_library utf.c private-utf.c private-utf_alphabetic.c private-utf_combining.c private-utf_control.c private-utf_digit.c private-utf_emoji.c private-utf_numeric.c private-utf_phonetic.c private-utf_private.c private-utf_punctuation.c private-utf_subscript.c private-utf_superscript.c private-utf_symbol.c private-utf_valid.c private-utf_whitespace.c private-utf_wide.c private-utf_word.c private-utf_zero_width.c build_sources_library utf/common.c utf/convert.c utf/dynamic.c utf/is.c utf/is_character.c utf/map.c utf/private-dynamic.c utf/private-map.c utf/private-map_multi.c utf/private-triple.c utf/private-is_unassigned.c utf/private-string.c utf/static.c utf/string.c utf/triple.c -build_sources_library-level thread.c private-thread.c -build_sources_library_shared -build_sources_library_static + +build_sources_library-level thread.c private-thread.c thread/attribute.c thread/barrier.c thread/barrier_attribute.c thread/condition.c thread/condition_attribute.c thread/id.c thread/key.c thread/lock.c thread/lock_attribute.c thread/mutex.c thread/mutex_attribute.c thread/once.c thread/semaphore.c thread/set.c thread/spin.c build_sources_headers account.h account/common.h build_sources_headers capability.h capability/common.h @@ -76,7 +75,8 @@ build_sources_headers type.h build_sources_headers type_array.h type_array/common.h build_sources_headers type_array/array_length.h type_array/cell.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h build_sources_headers utf.h utf/common.h utf/convert.h utf/dynamic.h utf/is.h utf/is_character.h utf/map.h utf/map_multi.h utf/static.h utf/string.h utf/triple.h -build_sources_headers-level thread.h thread/common.h + +build_sources_headers-level thread.h thread/attribute.h thread/barrier.h thread/barrier_attribute.h thread/condition.h thread/condition_attribute.h thread/id.h thread/key.h thread/lock.h thread/lock_attribute.h thread/mutex.h thread/mutex_attribute.h thread/once.h thread/semaphore.h thread/set.h thread/spin.h build_script yes build_shared yes diff --git a/build/monolithic/settings b/build/monolithic/settings index c652545..daa9c18 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -70,7 +70,7 @@ build_sources_library level_2/print.c build_sources_library level_2/program.c level_2/program/common.c build_sources_library level_2/status_string.c -build_sources_library-monolithic level_0/thread.c level_0/private-thread.c +build_sources_library-monolithic level_0/thread.c level_0/private-thread.c level_0/thread/attribute.c level_0/thread/barrier.c level_0/thread/barrier_attribute.c level_0/thread/condition.c level_0/thread/condition_attribute.c level_0/thread/id.c level_0/thread/key.c level_0/thread/lock.c level_0/thread/lock_attribute.c level_0/thread/mutex.c level_0/thread/mutex_attribute.c level_0/thread/once.c level_0/thread/semaphore.c level_0/thread/set.c level_0/thread/spin.c build_sources_headers level_0/account.h level_0/account/common.h build_sources_headers level_0/capability.h level_0/capability/common.h @@ -125,9 +125,7 @@ build_sources_headers level_2/print.h build_sources_headers level_2/program.h level_2/program/common.h build_sources_headers level_2/status_string.h -build_sources_headers-level level_0/thread.h level_0/thread/common.h - -build_sources_headers-monolithic level_0/thread.h level_0/thread/common.h +build_sources_headers-monolithic level_0/thread.h level_0/thread/attribute.h level_0/thread/barrier.h level_0/thread/barrier_attribute.h level_0/thread/condition.h level_0/thread/condition_attribute.h level_0/thread/id.h level_0/thread/key.h level_0/thread/lock.h level_0/thread/lock_attribute.h level_0/thread/mutex.h level_0/thread/mutex_attribute.h level_0/thread/once.h level_0/thread/semaphore.h level_0/thread/set.h level_0/thread/spin.h build_script yes build_shared yes diff --git a/level_0/f_thread/c/private-thread.c b/level_0/f_thread/c/private-thread.c index 98d163c..410075a 100644 --- a/level_0/f_thread/c/private-thread.c +++ b/level_0/f_thread/c/private-thread.c @@ -20,6 +20,7 @@ extern "C" { #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 * const attributes) { + f_status_t status = F_none; for (f_array_length_t i = length; i < attributes->size; ++i) { @@ -43,6 +44,7 @@ extern "C" { #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 * const attributes) { + f_status_t status = F_none; for (f_array_length_t i = length; i < attributes->size; ++i) { @@ -68,6 +70,9 @@ extern "C" { f_status_t private_f_thread_barrier_delete(f_thread_barrier_t *barrier) { if (pthread_barrier_destroy(barrier)) { + if (errno == EBUSY) return F_status_set_error(F_busy); + if (errno == EINVAL) return F_status_set_error(F_parameter); + return F_status_set_error(F_failure); } @@ -79,6 +84,7 @@ extern "C" { #if !defined(_di_f_thread_barriers_adjust_) || !defined(_di_f_thread_barriers_decimate_by_) f_status_t private_f_thread_barriers_adjust(const f_array_length_t length, f_thread_barriers_t * const barriers) { + f_status_t status = F_none; for (f_array_length_t i = length; i < barriers->size; ++i) { @@ -102,6 +108,7 @@ extern "C" { #if !defined(_di_f_thread_barriers_decrease_) || !defined(_di_f_thread_barriers_decrease_by_) || !defined(_di_f_thread_barriers_increase_) || !defined(_di_f_thread_barriers_increase_by_) f_status_t private_f_thread_barriers_resize(const f_array_length_t length, f_thread_barriers_t * const barriers) { + f_status_t status = F_none; for (f_array_length_t i = length; i < barriers->size; ++i) { @@ -138,6 +145,7 @@ extern "C" { #if !defined(_di_f_thread_barrier_attributes_adjust_) || !defined(_di_f_thread_barrier_attributes_decimate_by_) f_status_t private_f_thread_barrier_attributes_adjust(const f_array_length_t length, f_thread_barrier_attributes_t * const attributes) { + f_status_t status = F_none; for (f_array_length_t i = length; i < attributes->size; ++i) { @@ -161,6 +169,7 @@ extern "C" { #if !defined(_di_f_thread_barrier_attributes_decrease_) || !defined(_di_f_thread_barrier_attributes_decrease_by_) || !defined(_di_f_thread_barrier_attributes_increase_) || !defined(_di_f_thread_barrier_attributes_increase_by_) f_status_t private_f_thread_barrier_attributes_resize(const f_array_length_t length, f_thread_barrier_attributes_t * const attributes) { + f_status_t status = F_none; for (f_array_length_t i = length; i < attributes->size; ++i) { @@ -200,6 +209,7 @@ extern "C" { #if !defined(_di_f_thread_condition_attributes_adjust_) || !defined(_di_f_thread_condition_attributes_decimate_by_) f_status_t private_f_thread_condition_attributes_adjust(const f_array_length_t length, f_thread_condition_attributes_t * const attributes) { + f_status_t status = F_none; for (f_array_length_t i = length; i < attributes->size; ++i) { @@ -223,6 +233,7 @@ extern "C" { #if !defined(_di_f_thread_condition_attributes_decrease_) || !defined(_di_f_thread_condition_attributes_decrease_by_) || !defined(_di_f_thread_condition_attributes_increase_) || !defined(_di_f_thread_condition_attributes_increase_by_) f_status_t private_f_thread_condition_attributes_resize(const f_array_length_t length, f_thread_condition_attributes_t * const attributes) { + f_status_t status = F_none; for (f_array_length_t i = length; i < attributes->size; ++i) { @@ -262,6 +273,7 @@ extern "C" { #if !defined(_di_f_thread_conditions_adjust_) || !defined(_di_f_thread_conditions_decimate_by_) f_status_t private_f_thread_conditions_adjust(const f_array_length_t length, f_thread_conditions_t * const conditions) { + f_status_t status = F_none; for (f_array_length_t i = length; i < conditions->size; ++i) { @@ -285,6 +297,7 @@ extern "C" { #if !defined(_di_f_thread_conditions_decrease_) || !defined(_di_f_thread_conditions_decrease_by_) || !defined(_di_f_thread_conditions_increase_) || !defined(_di_f_thread_conditions_increase_by_) f_status_t private_f_thread_conditions_resize(const f_array_length_t length, f_thread_conditions_t * const conditions) { + f_status_t status = F_none; for (f_array_length_t i = length; i < conditions->size; ++i) { @@ -306,6 +319,44 @@ extern "C" { } #endif // !defined(_di_f_thread_conditions_decrease_) || !defined(_di_f_thread_conditions_decrease_by_) || !defined(_di_f_thread_conditions_increase_) || !defined(_di_f_thread_conditions_increase_by_) +#if !defined(_di_f_thread_ids_adjust_) || !defined(_di_f_thread_ids_decimate_by_) + f_status_t private_f_thread_ids_adjust(const f_array_length_t length, f_thread_ids_t * const ids) { + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < ids->size; ++i) { + memset(&ids->array[i], 0, sizeof(f_thread_id_t)); + } // for + + status = f_memory_adjust(ids->size, length, sizeof(f_thread_id_t), (void **) & ids->array); + if (F_status_is_error(status)) return status; + + ids->size = length; + + if (ids->used > ids->size) { + ids->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_thread_ids_adjust_) || !defined(_di_f_thread_ids_decimate_by_) + +#if !defined(_di_f_thread_ids_decrease_) || !defined(_di_f_thread_ids_decrease_by_) || !defined(_di_f_thread_ids_increase_) || !defined(_di_f_thread_ids_increase_by_) + f_status_t private_f_thread_ids_resize(const f_array_length_t length, f_thread_ids_t * const ids) { + + const f_status_t status = f_memory_resize(ids->size, length, sizeof(f_thread_id_t), (void **) & ids->array); + if (F_status_is_error(status)) return status; + + ids->size = length; + + if (ids->used > ids->size) { + ids->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_thread_ids_decrease_) || !defined(_di_f_thread_ids_decrease_by_) || !defined(_di_f_thread_ids_increase_) || !defined(_di_f_thread_ids_increase_by_) + #if !defined(_di_f_thread_keys_adjust_) || !defined(_di_f_thread_keys_decimate_by_) || !defined(_di_f_thread_keys_decrease_) || !defined(_di_f_thread_keys_decrease_by_) || !defined(_di_f_thread_keys_increase_) || !defined(_di_f_thread_keys_increase_by_) || !defined(_di_f_thread_keys_resize_) f_status_t private_f_thread_key_delete(f_thread_key_t *key) { @@ -321,6 +372,7 @@ extern "C" { #if !defined(_di_f_thread_keys_adjust_) || !defined(_di_f_thread_keys_decimate_by_) f_status_t private_f_thread_keys_adjust(const f_array_length_t length, f_thread_keys_t * const keys) { + f_status_t status = F_none; for (f_array_length_t i = length; i < keys->size; ++i) { @@ -344,6 +396,7 @@ extern "C" { #if !defined(_di_f_thread_keys_decrease_) || !defined(_di_f_thread_keys_decrease_by_) || !defined(_di_f_thread_keys_increase_) || !defined(_di_f_thread_keys_increase_by_) f_status_t private_f_thread_keys_resize(const f_array_length_t length, f_thread_keys_t * const keys) { + f_status_t status = F_none; for (f_array_length_t i = length; i < keys->size; ++i) { @@ -365,10 +418,10 @@ extern "C" { } #endif // !defined(_di_f_thread_keys_decrease_) || !defined(_di_f_thread_keys_decrease_by_) || !defined(_di_f_thread_keys_increase_) || !defined(_di_f_thread_keys_increase_by_) -#if !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) || !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) || !defined(_di_f_thread_locks_resize_) - f_status_t private_f_thread_lock_delete(f_thread_lock_t *lock) { +#if !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) || !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) || !defined(_di_f_thread_lock_attributes_resize_) + f_status_t private_f_thread_lock_attribute_delete(f_thread_lock_attribute_t *attribute) { - const int error = pthread_rwlock_destroy(lock); + const int error = pthread_rwlockattr_destroy(attribute); if (error) { if (error == EBUSY) return F_status_set_error(F_busy); @@ -379,58 +432,60 @@ extern "C" { return F_none; } -#endif // !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) || !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) || !defined(_di_f_thread_locks_resize_) +#endif // !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) || !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) || !defined(_di_f_thread_lock_attributes_resize_) + +#if !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) + f_status_t private_f_thread_lock_attributes_adjust(const f_array_length_t length, f_thread_lock_attributes_t * const attributes) { -#if !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) - f_status_t private_f_thread_locks_adjust(const f_array_length_t length, f_thread_locks_t * const locks) { f_status_t status = F_none; - for (f_array_length_t i = length; i < locks->size; ++i) { + for (f_array_length_t i = length; i < attributes->size; ++i) { - status = private_f_thread_lock_delete(&locks->array[i]); + status = private_f_thread_lock_attribute_delete(&attributes->array[i]); if (F_status_is_error(status)) return status; } // for - status = f_memory_adjust(locks->size, length, sizeof(f_thread_lock_t), (void **) & locks->array); + status = f_memory_adjust(attributes->size, length, sizeof(f_thread_lock_t), (void **) & attributes->array); if (F_status_is_error(status)) return status; - locks->size = length; + attributes->size = length; - if (locks->used > locks->size) { - locks->used = length; + if (attributes->used > attributes->size) { + attributes->used = length; } return F_none; } -#endif // !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) +#endif // !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) + +#if !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) + f_status_t private_f_thread_lock_attributes_resize(const f_array_length_t length, f_thread_lock_attributes_t * const attributes) { -#if !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) - f_status_t private_f_thread_locks_resize(const f_array_length_t length, f_thread_locks_t * const locks) { f_status_t status = F_none; - for (f_array_length_t i = length; i < locks->size; ++i) { + for (f_array_length_t i = length; i < attributes->size; ++i) { - status = private_f_thread_lock_delete(&locks->array[i]); + status = private_f_thread_lock_attribute_delete(&attributes->array[i]); if (F_status_is_error(status)) return status; } // for - status = f_memory_resize(locks->size, length, sizeof(f_thread_lock_t), (void **) & locks->array); + status = f_memory_resize(attributes->size, length, sizeof(f_thread_lock_t), (void **) & attributes->array); if (F_status_is_error(status)) return status; - locks->size = length; + attributes->size = length; - if (locks->used > locks->size) { - locks->used = length; + if (attributes->used > attributes->size) { + attributes->used = length; } return F_none; } -#endif // !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) +#endif // !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) -#if !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) || !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) || !defined(_di_f_thread_lock_attributes_resize_) - f_status_t private_f_thread_lock_attribute_delete(f_thread_lock_attribute_t *attribute) { +#if !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) || !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) || !defined(_di_f_thread_locks_resize_) + f_status_t private_f_thread_lock_delete(f_thread_lock_t *lock) { - const int error = pthread_rwlockattr_destroy(attribute); + const int error = pthread_rwlock_destroy(lock); if (error) { if (error == EBUSY) return F_status_set_error(F_busy); @@ -441,53 +496,55 @@ extern "C" { return F_none; } -#endif // !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) || !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) || !defined(_di_f_thread_lock_attributes_resize_) +#endif // !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) || !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) || !defined(_di_f_thread_locks_resize_) + +#if !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) + f_status_t private_f_thread_locks_adjust(const f_array_length_t length, f_thread_locks_t * const locks) { -#if !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) - f_status_t private_f_thread_lock_attributes_adjust(const f_array_length_t length, f_thread_lock_attributes_t * const attributes) { f_status_t status = F_none; - for (f_array_length_t i = length; i < attributes->size; ++i) { + for (f_array_length_t i = length; i < locks->size; ++i) { - status = private_f_thread_lock_attribute_delete(&attributes->array[i]); + status = private_f_thread_lock_delete(&locks->array[i]); if (F_status_is_error(status)) return status; } // for - status = f_memory_adjust(attributes->size, length, sizeof(f_thread_lock_t), (void **) & attributes->array); + status = f_memory_adjust(locks->size, length, sizeof(f_thread_lock_t), (void **) & locks->array); if (F_status_is_error(status)) return status; - attributes->size = length; + locks->size = length; - if (attributes->used > attributes->size) { - attributes->used = length; + if (locks->used > locks->size) { + locks->used = length; } return F_none; } -#endif // !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) +#endif // !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) + +#if !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) + f_status_t private_f_thread_locks_resize(const f_array_length_t length, f_thread_locks_t * const locks) { -#if !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) - f_status_t private_f_thread_lock_attributes_resize(const f_array_length_t length, f_thread_lock_attributes_t * const attributes) { f_status_t status = F_none; - for (f_array_length_t i = length; i < attributes->size; ++i) { + for (f_array_length_t i = length; i < locks->size; ++i) { - status = private_f_thread_lock_attribute_delete(&attributes->array[i]); + status = private_f_thread_lock_delete(&locks->array[i]); if (F_status_is_error(status)) return status; } // for - status = f_memory_resize(attributes->size, length, sizeof(f_thread_lock_t), (void **) & attributes->array); + status = f_memory_resize(locks->size, length, sizeof(f_thread_lock_t), (void **) & locks->array); if (F_status_is_error(status)) return status; - attributes->size = length; + locks->size = length; - if (attributes->used > attributes->size) { - attributes->used = length; + if (locks->used > locks->size) { + locks->used = length; } return F_none; } -#endif // !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) +#endif // !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) #if !defined(_di_f_thread_mutex_attributes_adjust_) || !defined(_di_f_thread_mutex_attributes_decimate_by_) || !defined(_di_f_thread_mutex_attributes_decrease_) || !defined(_di_f_thread_mutex_attributes_decrease_by_) || !defined(_di_f_thread_mutex_attributes_increase_) || !defined(_di_f_thread_mutex_attributes_increase_by_) || !defined(_di_f_thread_mutex_attributes_resize_) f_status_t private_f_thread_mutex_attribute_delete(f_thread_mutex_attribute_t *attribute) { @@ -507,6 +564,7 @@ extern "C" { #if !defined(_di_f_thread_mutex_attributes_adjust_) || !defined(_di_f_thread_mutex_attributes_decimate_by_) f_status_t private_f_thread_mutex_attributes_adjust(const f_array_length_t length, f_thread_mutex_attributes_t * const attributes) { + f_status_t status = F_none; for (f_array_length_t i = length; i < attributes->size; ++i) { @@ -530,6 +588,7 @@ extern "C" { #if !defined(_di_f_thread_mutex_attributes_decrease_) || !defined(_di_f_thread_mutex_attributes_decrease_by_) || !defined(_di_f_thread_mutex_attributes_increase_) || !defined(_di_f_thread_mutex_attributes_increase_by_) f_status_t private_f_thread_mutex_attributes_resize(const f_array_length_t length, f_thread_mutex_attributes_t * const attributes) { + f_status_t status = F_none; for (f_array_length_t i = length; i < attributes->size; ++i) { @@ -569,6 +628,7 @@ extern "C" { #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 * const mutexs) { + f_status_t status = F_none; for (f_array_length_t i = length; i < mutexs->size; ++i) { @@ -592,6 +652,7 @@ extern "C" { #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 * const mutexs) { + f_status_t status = F_none; for (f_array_length_t i = length; i < mutexs->size; ++i) { @@ -613,6 +674,44 @@ extern "C" { } #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_onces_adjust_) || !defined(_di_f_thread_onces_decimate_by_) + f_status_t private_f_thread_onces_adjust(const f_array_length_t length, f_thread_onces_t * const onces) { + + for (f_array_length_t i = length; i < onces->size; ++i) { + memset(&onces->array[i], 0, sizeof(f_thread_once_t)); + } // for + + const f_status_t status = f_memory_adjust(onces->size, length, sizeof(f_thread_once_t), (void **) & onces->array); + if (F_status_is_error(status)) return status; + + onces->size = length; + + if (onces->used > onces->size) { + onces->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_thread_onces_adjust_) || !defined(_di_f_thread_onces_decimate_by_) + +#if !defined(_di_f_thread_onces_decrease_) || !defined(_di_f_thread_onces_decrease_by_) || !defined(_di_f_thread_onces_increase_) || !defined(_di_f_thread_onces_increase_by_) + f_status_t private_f_thread_onces_resize(const f_array_length_t length, f_thread_onces_t * const onces) { + + f_status_t status = F_none; + + status = f_memory_resize(onces->size, length, sizeof(f_thread_once_t), (void **) & onces->array); + if (F_status_is_error(status)) return status; + + onces->size = length; + + if (onces->used > onces->size) { + onces->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_thread_onces_decrease_) || !defined(_di_f_thread_onces_decrease_by_) || !defined(_di_f_thread_onces_increase_) || !defined(_di_f_thread_onces_increase_by_) + #if !defined(_di_f_thread_semaphores_adjust_) || !defined(_di_f_thread_semaphores_decimate_by_) || !defined(_di_f_thread_semaphores_decrease_) || !defined(_di_f_thread_semaphores_decrease_by_) || !defined(_di_f_thread_semaphores_increase_) || !defined(_di_f_thread_semaphores_increase_by_) || !defined(_di_f_thread_semaphores_resize_) f_status_t private_f_thread_semaphore_delete(f_thread_semaphore_t *semaphore) { @@ -630,6 +729,7 @@ extern "C" { #if !defined(_di_f_thread_semaphores_adjust_) || !defined(_di_f_thread_semaphores_decimate_by_) f_status_t private_f_thread_semaphores_adjust(const f_array_length_t length, f_thread_semaphores_t * const semaphores) { + f_status_t status = F_none; for (f_array_length_t i = length; i < semaphores->size; ++i) { @@ -654,6 +754,7 @@ extern "C" { #if !defined(_di_f_thread_semaphores_decrease_) || !defined(_di_f_thread_semaphores_decrease_by_) || !defined(_di_f_thread_semaphores_increase_) || !defined(_di_f_thread_semaphores_increase_by_) f_status_t private_f_thread_semaphores_resize(const f_array_length_t length, f_thread_semaphores_t * const semaphores) { + f_status_t status = F_none; for (f_array_length_t i = length; i < semaphores->size; ++i) { @@ -677,6 +778,7 @@ extern "C" { #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 * const sets) { + f_status_t status = F_none; for (f_array_length_t i = length; i < sets->size; ++i) { @@ -700,6 +802,7 @@ extern "C" { #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 * const sets) { + f_status_t status = F_none; for (f_array_length_t i = length; i < sets->size; ++i) { @@ -739,6 +842,7 @@ extern "C" { #if !defined(_di_f_thread_spins_adjust_) || !defined(_di_f_thread_spins_decimate_by_) f_status_t private_f_thread_spins_adjust(const f_array_length_t length, f_thread_spins_t * const spins) { + f_status_t status = F_none; for (f_array_length_t i = length; i < spins->size; ++i) { diff --git a/level_0/f_thread/c/private-thread.h b/level_0/f_thread/c/private-thread.h index f54fd5e..13b6223 100644 --- a/level_0/f_thread/c/private-thread.h +++ b/level_0/f_thread/c/private-thread.h @@ -413,6 +413,53 @@ extern "C" { #endif // !defined(_di_f_thread_conditions_decrease_by_) || !defined(_di_f_thread_conditions_increase_) || !defined(_di_f_thread_conditions_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 ids + * The ids to adjust. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_thread_ids_adjust() + * @see f_thread_ids_decimate_by() + */ +#if !defined(_di_f_thread_ids_adjust_) || !defined(_di_f_thread_ids_decimate_by_) + extern f_status_t private_f_thread_ids_adjust(const f_array_length_t length, f_thread_ids_t * const ids) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_ids_adjust_) || !defined(_di_f_thread_ids_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 ids + * The ids to resize. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_thread_ids_decrease_by() + * @see f_thread_ids_increase() + * @see f_thread_ids_increase_by() + */ +#if !defined(_di_f_thread_ids_decrease_by_) || !defined(_di_f_thread_ids_increase_) || !defined(_di_f_thread_ids_increase_by_) + extern f_status_t private_f_thread_ids_resize(const f_array_length_t length, f_thread_ids_t * const ids) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_ids_decrease_by_) || !defined(_di_f_thread_ids_increase_) || !defined(_di_f_thread_ids_increase_by_) + +/** * Private implementation for deleting (and destroying). * * Intended to be shared to each of the different implementation variations. @@ -493,8 +540,8 @@ extern "C" { * * Intended to be shared to each of the different implementation variations. * - * @param lock - * The locks to delete. + * @param attribute + * The attribute to delete. * * @return * F_none on success. @@ -503,19 +550,19 @@ extern "C" { * F_failure (with error bit) on error. * F_parameter (with error bit) if a parameter is invalid. * - * @see pthread_rwlock_destroy() + * @see pthread_rwlockattr_destroy() * - * @see f_thread_locks_adjust() - * @see f_thread_locks_decimate_by() - * @see f_thread_locks_decrease() - * @see f_thread_locks_decrease_by() - * @see f_thread_locks_increase() - * @see f_thread_locks_increase_by() - * @see f_thread_locks_resize() + * @see f_thread_lock_attributes_adjust() + * @see f_thread_lock_attributes_decimate_by() + * @see f_thread_lock_attributes_decrease() + * @see f_thread_lock_attributes_decrease_by() + * @see f_thread_lock_attributes_increase() + * @see f_thread_lock_attributes_increase_by() + * @see f_thread_lock_attributes_resize() */ -#if !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) || !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) || !defined(_di_f_thread_locks_resize_) - extern f_status_t private_f_thread_lock_delete(f_thread_lock_t *lock) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) || !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) || !defined(_di_f_thread_locks_resize_) +#if !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) || !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) || !defined(_di_f_thread_lock_attributes_resize_) + extern f_status_t private_f_thread_lock_attribute_delete(f_thread_lock_attribute_t *attribute) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) || !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) || !defined(_di_f_thread_lock_attributes_resize_) /** * Private implementation for resizing. @@ -524,8 +571,8 @@ extern "C" { * * @param length * The new size to use. - * @param locks - * The locks to adjust. + * @param attributes + * The attributes to adjust. * * @return * F_none on success. @@ -533,12 +580,12 @@ extern "C" { * Errors (with error bit) from: f_memory_adjust(). * * @see f_memory_adjust() - * @see f_thread_locks_adjust() - * @see f_thread_locks_decimate_by() + * @see f_thread_lock_attributes_adjust() + * @see f_thread_lock_attributes_decimate_by() */ -#if !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) - extern f_status_t private_f_thread_locks_adjust(const f_array_length_t length, f_thread_locks_t * const locks) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) +#if !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) + extern f_status_t private_f_thread_lock_attributes_adjust(const f_array_length_t length, f_thread_lock_attributes_t * const attributes) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) /** * Private implementation for resizing. @@ -547,8 +594,8 @@ extern "C" { * * @param length * The new size to use. - * @param locks - * The locks to resize. + * @param attributes + * The attributes to resize. * * @return * F_none on success. @@ -556,21 +603,21 @@ extern "C" { * Errors (with error bit) from: f_memory_resize(). * * @see f_memory_resize() - * @see f_thread_locks_decrease_by() - * @see f_thread_locks_increase() - * @see f_thread_locks_increase_by() + * @see f_thread_lock_attributes_decrease_by() + * @see f_thread_lock_attributes_increase() + * @see f_thread_lock_attributes_increase_by() */ -#if !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) - extern f_status_t private_f_thread_locks_resize(const f_array_length_t length, f_thread_locks_t * const locks) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) +#if !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) + extern f_status_t private_f_thread_lock_attributes_resize(const f_array_length_t length, f_thread_lock_attributes_t * const attributes) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) /** * Private implementation for deleting (and destroying). * * Intended to be shared to each of the different implementation variations. * - * @param attribute - * The attribute to delete. + * @param lock + * The locks to delete. * * @return * F_none on success. @@ -579,19 +626,19 @@ extern "C" { * F_failure (with error bit) on error. * F_parameter (with error bit) if a parameter is invalid. * - * @see pthread_rwlockattr_destroy() + * @see pthread_rwlock_destroy() * - * @see f_thread_lock_attributes_adjust() - * @see f_thread_lock_attributes_decimate_by() - * @see f_thread_lock_attributes_decrease() - * @see f_thread_lock_attributes_decrease_by() - * @see f_thread_lock_attributes_increase() - * @see f_thread_lock_attributes_increase_by() - * @see f_thread_lock_attributes_resize() + * @see f_thread_locks_adjust() + * @see f_thread_locks_decimate_by() + * @see f_thread_locks_decrease() + * @see f_thread_locks_decrease_by() + * @see f_thread_locks_increase() + * @see f_thread_locks_increase_by() + * @see f_thread_locks_resize() */ -#if !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) || !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) || !defined(_di_f_thread_lock_attributes_resize_) - extern f_status_t private_f_thread_lock_attribute_delete(f_thread_lock_attribute_t *attribute) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) || !defined(_di_f_thread_lock_attributes_decrease_) || !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) || !defined(_di_f_thread_lock_attributes_resize_) +#if !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) || !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) || !defined(_di_f_thread_locks_resize_) + extern f_status_t private_f_thread_lock_delete(f_thread_lock_t *lock) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) || !defined(_di_f_thread_locks_decrease_) || !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) || !defined(_di_f_thread_locks_resize_) /** * Private implementation for resizing. @@ -600,8 +647,8 @@ extern "C" { * * @param length * The new size to use. - * @param attributes - * The attributes to adjust. + * @param locks + * The locks to adjust. * * @return * F_none on success. @@ -609,12 +656,12 @@ extern "C" { * Errors (with error bit) from: f_memory_adjust(). * * @see f_memory_adjust() - * @see f_thread_lock_attributes_adjust() - * @see f_thread_lock_attributes_decimate_by() + * @see f_thread_locks_adjust() + * @see f_thread_locks_decimate_by() */ -#if !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) - extern f_status_t private_f_thread_lock_attributes_adjust(const f_array_length_t length, f_thread_lock_attributes_t * const attributes) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_thread_lock_attributes_adjust_) || !defined(_di_f_thread_lock_attributes_decimate_by_) +#if !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) + extern f_status_t private_f_thread_locks_adjust(const f_array_length_t length, f_thread_locks_t * const locks) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_locks_adjust_) || !defined(_di_f_thread_locks_decimate_by_) /** * Private implementation for resizing. @@ -623,8 +670,8 @@ extern "C" { * * @param length * The new size to use. - * @param attributes - * The attributes to resize. + * @param locks + * The locks to resize. * * @return * F_none on success. @@ -632,14 +679,13 @@ extern "C" { * Errors (with error bit) from: f_memory_resize(). * * @see f_memory_resize() - * @see f_thread_lock_attributes_decrease_by() - * @see f_thread_lock_attributes_increase() - * @see f_thread_lock_attributes_increase_by() + * @see f_thread_locks_decrease_by() + * @see f_thread_locks_increase() + * @see f_thread_locks_increase_by() */ -#if !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) - extern f_status_t private_f_thread_lock_attributes_resize(const f_array_length_t length, f_thread_lock_attributes_t * const attributes) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_thread_lock_attributes_decrease_by_) || !defined(_di_f_thread_lock_attributes_increase_) || !defined(_di_f_thread_lock_attributes_increase_by_) - +#if !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) + extern f_status_t private_f_thread_locks_resize(const f_array_length_t length, f_thread_locks_t * const locks) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_locks_decrease_by_) || !defined(_di_f_thread_locks_increase_) || !defined(_di_f_thread_locks_increase_by_) /** * Private implementation for deleting (and destroying). * @@ -793,6 +839,53 @@ extern "C" { #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 onces + * The onces to adjust. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_thread_onces_adjust() + * @see f_thread_onces_decimate_by() + */ +#if !defined(_di_f_thread_onces_adjust_) || !defined(_di_f_thread_onces_decimate_by_) + extern f_status_t private_f_thread_onces_adjust(const f_array_length_t length, f_thread_onces_t * const onces) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_onces_adjust_) || !defined(_di_f_thread_onces_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 onces + * The onces to resize. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_thread_onces_decrease_by() + * @see f_thread_onces_increase() + * @see f_thread_onces_increase_by() + */ +#if !defined(_di_f_thread_onces_decrease_by_) || !defined(_di_f_thread_onces_increase_) || !defined(_di_f_thread_onces_increase_by_) + extern f_status_t private_f_thread_onces_resize(const f_array_length_t length, f_thread_onces_t * const onces) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_thread_onces_decrease_by_) || !defined(_di_f_thread_onces_increase_) || !defined(_di_f_thread_onces_increase_by_) + +/** * Private implementation for deleting (and destroying). * * Intended to be shared to each of the different implementation variations. diff --git a/level_0/f_thread/c/thread.c b/level_0/f_thread/c/thread.c index 4aa5442..03bade9 100644 --- a/level_0/f_thread/c/thread.c +++ b/level_0/f_thread/c/thread.c @@ -78,23 +78,27 @@ extern "C" { } #endif // defined(_pthread_attr_unsupported_) && !defined(_di_f_thread_attribute_affinity_set_) -#ifndef _di_f_thread_attribute_clock_get_ - f_status_t f_thread_attribute_clock_get(const f_thread_condition_attribute_t * const attribute, clockid_t * const id) { +#ifndef _di_f_thread_attribute_condition_clock_get_ + f_status_t f_thread_attribute_condition_clock_get(const f_thread_condition_attribute_t * const attribute, clockid_t * const id) { #ifndef _di_level_0_parameter_checking_ if (!attribute) return F_status_set_error(F_parameter); if (!id) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (pthread_condattr_getclock(attribute, id)) { + const int error = pthread_condattr_getclock(attribute, id); + + if (error) { + if (error == EINVAL) return F_status_set_error(F_parameter); + return F_status_set_error(F_failure); } return F_none; } -#endif // _di_f_thread_attribute_clock_get_ +#endif // _di_f_thread_attribute_condition_clock_get_ -#ifndef _di_f_thread_attribute_clock_set_ - f_status_t f_thread_attribute_clock_set(const clockid_t id, f_thread_condition_attribute_t * const attribute) { +#ifndef _di_f_thread_attribute_condition_clock_set_ + f_status_t f_thread_attribute_condition_clock_set(const clockid_t id, f_thread_condition_attribute_t * const attribute) { #ifndef _di_level_0_parameter_checking_ if (!attribute) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -109,7 +113,7 @@ extern "C" { return F_none; } -#endif // _di_f_thread_attribute_clock_set_ +#endif // _di_f_thread_attribute_condition_clock_set_ #ifndef _di_f_thread_attribute_condition_shared_get_ f_status_t f_thread_attribute_condition_shared_get(const f_thread_condition_attribute_t * const attribute, int * const shared) { @@ -118,7 +122,11 @@ extern "C" { if (!shared) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (pthread_condattr_getpshared(attribute, shared)) { + const int error = pthread_condattr_getpshared(attribute, shared); + + if (error) { + if (error == EINVAL) return F_status_set_error(F_parameter); + return F_status_set_error(F_failure); } @@ -146,6 +154,9 @@ extern "C" { #ifndef _di_f_thread_attribute_create_ f_status_t f_thread_attribute_create(f_thread_attribute_t * const attribute) { + #ifndef _di_level_0_parameter_checking_ + if (!attribute) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ const int error = pthread_attr_init(attribute); @@ -186,8 +197,8 @@ extern "C" { const int error = pthread_setattr_default_np(attribute); if (error) { - if (error == ENOMEM) return F_status_set_error(F_memory_not); if (error == EINVAL) return F_status_set_error(F_parameter); + if (error == ENOMEM) return F_status_set_error(F_memory_not); return F_status_set_error(F_failure); } @@ -495,101 +506,6 @@ extern "C" { } #endif // _di_f_thread_attribute_stack_size_set_ -#ifndef _di_f_thread_attributes_adjust_ - f_status_t f_thread_attributes_adjust(const f_array_length_t length, f_thread_attributes_t * const 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 * const 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 * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - 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(const f_array_length_t step, f_thread_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && attributes->used + 1 > attributes->size) { - f_array_length_t size = attributes->used + step; - - if (size > F_array_length_t_size_d) { - if (attributes->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - 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 * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->used + amount > attributes->size) { - if (attributes->used + amount > F_array_length_t_size_d) { - 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 * const 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_barrier_attribute_create_ f_status_t f_thread_barrier_attribute_create(f_thread_barrier_attribute_t * const attribute) { @@ -622,7 +538,11 @@ extern "C" { if (!shared) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (pthread_barrierattr_getpshared(attribute, shared)) { + const int error = pthread_barrierattr_getpshared(attribute, shared); + + if (error) { + if (error == EINVAL) return F_status_set_error(F_parameter); + return F_status_set_error(F_failure); } @@ -648,108 +568,15 @@ extern "C" { } #endif // _di_f_thread_barrier_attribute_shared_set_ -#ifndef _di_f_thread_barrier_attributes_adjust_ - f_status_t f_thread_barrier_attributes_adjust(const f_array_length_t length, f_thread_barrier_attributes_t * const 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_barrier_attributes_adjust(length, attributes); - } -#endif // _di_f_thread_barrier_attributes_adjust_ - -#ifndef _di_f_thread_barrier_attributes_decimate_by_ - f_status_t f_thread_barrier_attributes_decimate_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->size - amount > 0) { - return private_f_thread_barrier_attributes_adjust(attributes->size - amount, attributes); - } - - return private_f_thread_barrier_attributes_adjust(0, attributes); - } -#endif // _di_f_thread_barrier_attributes_decimate_by_ - -#ifndef _di_f_thread_barrier_attributes_decrease_by_ - f_status_t f_thread_barrier_attributes_decrease_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->size - amount > 0) { - return private_f_thread_barrier_attributes_resize(attributes->size - amount, attributes); - } - - return private_f_thread_barrier_attributes_resize(0, attributes); - } -#endif // _di_f_thread_barrier_attributes_decrease_by_ - -#ifndef _di_f_thread_barrier_attributes_increase_ - f_status_t f_thread_barrier_attributes_increase(const f_array_length_t step, f_thread_barrier_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && attributes->used + 1 > attributes->size) { - f_array_length_t size = attributes->used + step; - - if (size > F_array_length_t_size_d) { - if (attributes->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_barrier_attributes_resize(size, attributes); - } - - return F_data_not; - } -#endif // _di_f_thread_barrier_attributes_increase_ - -#ifndef _di_f_thread_barrier_attributes_increase_by_ - f_status_t f_thread_barrier_attributes_increase_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->used + amount > attributes->size) { - if (attributes->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_barrier_attributes_resize(attributes->used + amount, attributes); - } - - return F_data_not; - } -#endif // _di_f_thread_barrier_attributes_increase_by_ - -#ifndef _di_f_thread_barrier_attributes_resize_ - f_status_t f_thread_barrier_attributes_resize(const f_array_length_t length, f_thread_barrier_attributes_t * const 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_barrier_attributes_resize(length, attributes); - } -#endif // _di_f_thread_barrier_attributes_resize_ - #ifndef _di_f_thread_barrier_create_ f_status_t f_thread_barrier_create(const unsigned int count, f_thread_barrier_attribute_t * const attribute, f_thread_barrier_t * const barrier) { const int error = pthread_barrier_init(barrier, attribute, count); if (error) { + if (error == EAGAIN) return F_status_set_error(F_resource_not); + if (error == EBUSY) return F_status_set_error(F_busy); + if (error == EINVAL) return F_status_set_error(F_parameter); if (error == ENOMEM) return F_status_set_error(F_memory_not); return F_status_set_error(F_failure); @@ -786,104 +613,9 @@ extern "C" { } #endif // _di_f_thread_barrier_wait_ -#ifndef _di_f_thread_barriers_adjust_ - f_status_t f_thread_barriers_adjust(const f_array_length_t length, f_thread_barriers_t * const barriers) { - #ifndef _di_level_0_parameter_checking_ - if (!barriers) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_barriers_adjust(length, barriers); - } -#endif // _di_f_thread_barriers_adjust_ - -#ifndef _di_f_thread_barriers_decimate_by_ - f_status_t f_thread_barriers_decimate_by(const f_array_length_t amount, f_thread_barriers_t * const barriers) { - #ifndef _di_level_0_parameter_checking_ - if (!barriers) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (barriers->size - amount > 0) { - return private_f_thread_barriers_adjust(barriers->size - amount, barriers); - } - - return private_f_thread_barriers_adjust(0, barriers); - } -#endif // _di_f_thread_barriers_decimate_by_ - -#ifndef _di_f_thread_barriers_decrease_by_ - f_status_t f_thread_barriers_decrease_by(const f_array_length_t amount, f_thread_barriers_t * const barriers) { - #ifndef _di_level_0_parameter_checking_ - if (!barriers) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (barriers->size - amount > 0) { - return private_f_thread_barriers_resize(barriers->size - amount, barriers); - } - - return private_f_thread_barriers_resize(0, barriers); - } -#endif // _di_f_thread_barriers_decrease_by_ - -#ifndef _di_f_thread_barriers_increase_ - f_status_t f_thread_barriers_increase(const f_array_length_t step, f_thread_barriers_t * const barriers) { - #ifndef _di_level_0_parameter_checking_ - if (!barriers) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && barriers->used + 1 > barriers->size) { - f_array_length_t size = barriers->used + step; - - if (size > F_array_length_t_size_d) { - if (barriers->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_barriers_resize(size, barriers); - } - - return F_data_not; - } -#endif // _di_f_thread_barriers_increase_ - -#ifndef _di_f_thread_barriers_increase_by_ - f_status_t f_thread_barriers_increase_by(const f_array_length_t amount, f_thread_barriers_t * const barriers) { - #ifndef _di_level_0_parameter_checking_ - if (!barriers) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (barriers->used + amount > barriers->size) { - if (barriers->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_barriers_resize(barriers->used + amount, barriers); - } - - return F_data_not; - } -#endif // _di_f_thread_barriers_increase_by_ - -#ifndef _di_f_thread_barriers_resize_ - f_status_t f_thread_barriers_resize(const f_array_length_t length, f_thread_barriers_t * const barriers) { - #ifndef _di_level_0_parameter_checking_ - if (!barriers) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_barriers_resize(length, barriers); - } -#endif // _di_f_thread_barriers_resize_ - #ifndef _di_f_thread_caller_ f_thread_id_t f_thread_caller(void) { + return pthread_self(); } #endif // _di_f_thread_caller_ @@ -1036,102 +768,6 @@ extern "C" { } #endif // _di_f_thread_condition_attribute_delete_ -#ifndef _di_f_thread_condition_attributes_adjust_ - f_status_t f_thread_condition_attributes_adjust(const f_array_length_t length, f_thread_condition_attributes_t * const 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_condition_attributes_adjust(length, attributes); - } -#endif // _di_f_thread_condition_attributes_adjust_ - -#ifndef _di_f_thread_condition_attributes_decimate_by_ - f_status_t f_thread_condition_attributes_decimate_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->size - amount > 0) { - return private_f_thread_condition_attributes_adjust(attributes->size - amount, attributes); - } - - return private_f_thread_condition_attributes_adjust(0, attributes); - } -#endif // _di_f_thread_condition_attributes_decimate_by_ - -#ifndef _di_f_thread_condition_attributes_decrease_by_ - f_status_t f_thread_condition_attributes_decrease_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->size - amount > 0) { - return private_f_thread_condition_attributes_resize(attributes->size - amount, attributes); - } - - return private_f_thread_condition_attributes_resize(0, attributes); - } -#endif // _di_f_thread_condition_attributes_decrease_by_ - -#ifndef _di_f_thread_condition_attributes_increase_ - f_status_t f_thread_condition_attributes_increase(const f_array_length_t step, f_thread_condition_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && attributes->used + 1 > attributes->size) { - f_array_length_t size = attributes->used + step; - - if (size > F_array_length_t_size_d) { - if (attributes->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_condition_attributes_resize(size, attributes); - } - - return F_data_not; - } -#endif // _di_f_thread_condition_attributes_increase_ - -#ifndef _di_f_thread_condition_attributes_increase_by_ - f_status_t f_thread_condition_attributes_increase_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->used + amount > attributes->size) { - if (attributes->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_condition_attributes_resize(attributes->used + amount, attributes); - } - - return F_data_not; - } -#endif // _di_f_thread_condition_attributes_increase_by_ - -#ifndef _di_f_thread_condition_attributes_resize_ - f_status_t f_thread_condition_attributes_resize(const f_array_length_t length, f_thread_condition_attributes_t * const 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_condition_attributes_resize(length, attributes); - } -#endif // _di_f_thread_condition_attributes_resize_ - #ifndef _di_f_thread_condition_create_ f_status_t f_thread_condition_create(const f_thread_condition_attribute_t * const attribute, f_thread_condition_t * const condition) { #ifndef _di_level_0_parameter_checking_ @@ -1244,101 +880,6 @@ extern "C" { } #endif // _di_f_thread_condition_wait_timed_ -#ifndef _di_f_thread_conditions_adjust_ - f_status_t f_thread_conditions_adjust(const f_array_length_t length, f_thread_conditions_t * const conditions) { - #ifndef _di_level_0_parameter_checking_ - if (!conditions) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_conditions_adjust(length, conditions); - } -#endif // _di_f_thread_conditions_adjust_ - -#ifndef _di_f_thread_conditions_decimate_by_ - f_status_t f_thread_conditions_decimate_by(const f_array_length_t amount, f_thread_conditions_t * const conditions) { - #ifndef _di_level_0_parameter_checking_ - if (!amount) return F_status_set_error(F_parameter); - if (!conditions) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (conditions->size - amount > 0) { - return private_f_thread_conditions_adjust(conditions->size - amount, conditions); - } - - return private_f_thread_conditions_adjust(0, conditions); - } -#endif // _di_f_thread_conditions_decimate_by_ - -#ifndef _di_f_thread_conditions_decrease_by_ - f_status_t f_thread_conditions_decrease_by(const f_array_length_t amount, f_thread_conditions_t * const conditions) { - #ifndef _di_level_0_parameter_checking_ - if (!conditions) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (conditions->size - amount > 0) { - return private_f_thread_conditions_resize(conditions->size - amount, conditions); - } - - return private_f_thread_conditions_resize(0, conditions); - } -#endif // _di_f_thread_conditions_decrease_by_ - -#ifndef _di_f_thread_conditions_increase_ - f_status_t f_thread_conditions_increase(const f_array_length_t step, f_thread_conditions_t * const conditions) { - #ifndef _di_level_0_parameter_checking_ - if (!conditions) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && conditions->used + 1 > conditions->size) { - f_array_length_t size = conditions->used + step; - - if (size > F_array_length_t_size_d) { - if (conditions->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_conditions_resize(size, conditions); - } - - return F_data_not; - } -#endif // _di_f_thread_conditions_increase_ - -#ifndef _di_f_thread_conditions_increase_by_ - f_status_t f_thread_conditions_increase_by(const f_array_length_t amount, f_thread_conditions_t * const conditions) { - #ifndef _di_level_0_parameter_checking_ - if (!conditions) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (conditions->used + amount > conditions->size) { - if (conditions->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_conditions_resize(conditions->used + amount, conditions); - } - - return F_data_not; - } -#endif // _di_f_thread_conditions_increase_by_ - -#ifndef _di_f_thread_conditions_resize_ - f_status_t f_thread_conditions_resize(const f_array_length_t length, f_thread_conditions_t * const conditions) { - #ifndef _di_level_0_parameter_checking_ - if (!conditions) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_conditions_resize(length, conditions); - } -#endif // _di_f_thread_conditions_resize_ - #ifndef _di_f_thread_create_ f_status_t f_thread_create(const f_thread_attribute_t * const attribute, f_thread_id_t * const id, void *(*routine) (void *), void *argument) { #ifndef _di_level_0_parameter_checking_ @@ -1505,104 +1046,8 @@ extern "C" { } #endif // _di_f_thread_key_set_ -#ifndef _di_f_thread_keys_adjust_ - f_status_t f_thread_keys_adjust(const f_array_length_t length, f_thread_keys_t * const keys) { - #ifndef _di_level_0_parameter_checking_ - if (!keys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_keys_adjust(length, keys); - } -#endif // _di_f_thread_keys_adjust_ - -#ifndef _di_f_thread_keys_decimate_by_ - f_status_t f_thread_keys_decimate_by(const f_array_length_t amount, f_thread_keys_t * const keys) { - #ifndef _di_level_0_parameter_checking_ - if (!keys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (keys->size - amount > 0) { - return private_f_thread_keys_adjust(keys->size - amount, keys); - } - - return private_f_thread_keys_adjust(0, keys); - } -#endif // _di_f_thread_keys_decimate_by_ - -#ifndef _di_f_thread_keys_decrease_by_ - f_status_t f_thread_keys_decrease_by(const f_array_length_t amount, f_thread_keys_t * const keys) { - #ifndef _di_level_0_parameter_checking_ - if (!keys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (keys->size - amount > 0) { - return private_f_thread_keys_resize(keys->size - amount, keys); - } - - return private_f_thread_keys_resize(0, keys); - } -#endif // _di_f_thread_keys_decrease_by_ - -#ifndef _di_f_thread_keys_increase_ - f_status_t f_thread_keys_increase(const f_array_length_t step, f_thread_keys_t * const keys) { - #ifndef _di_level_0_parameter_checking_ - if (!keys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && keys->used + 1 > keys->size) { - f_array_length_t size = keys->used + step; - - if (size > F_array_length_t_size_d) { - if (keys->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_keys_resize(size, keys); - } - - return F_data_not; - } -#endif // _di_f_thread_keys_increase_ - -#ifndef _di_f_thread_keys_increase_by_ - f_status_t f_thread_keys_increase_by(const f_array_length_t amount, f_thread_keys_t * const keys) { - #ifndef _di_level_0_parameter_checking_ - if (!keys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (keys->used + amount > keys->size) { - if (keys->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_keys_resize(keys->used + amount, keys); - } - - return F_data_not; - } -#endif // _di_f_thread_keys_increase_by_ - -#ifndef _di_f_thread_keys_resize_ - f_status_t f_thread_keys_resize(const f_array_length_t length, f_thread_keys_t * const keys) { - #ifndef _di_level_0_parameter_checking_ - if (!keys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_keys_resize(length, keys); - } -#endif // _di_f_thread_keys_resize_ - -#ifndef _di_f_thread_lock_attribute_create_ - f_status_t f_thread_lock_attribute_create(f_thread_lock_attribute_t * const attribute) { +#ifndef _di_f_thread_lock_attribute_create_ + f_status_t f_thread_lock_attribute_create(f_thread_lock_attribute_t * const attribute) { #ifndef _di_level_0_parameter_checking_ if (!attribute) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -1666,102 +1111,6 @@ extern "C" { } #endif // _di_f_thread_lock_attribute_shared_set_ -#ifndef _di_f_thread_lock_attributes_adjust_ - f_status_t f_thread_lock_attributes_adjust(const f_array_length_t length, f_thread_lock_attributes_t * const 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_lock_attributes_adjust(length, attributes); - } -#endif // _di_f_thread_lock_attributes_adjust_ - -#ifndef _di_f_thread_lock_attributes_decimate_by_ - f_status_t f_thread_lock_attributes_decimate_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->size - amount > 0) { - return private_f_thread_lock_attributes_adjust(attributes->size - amount, attributes); - } - - return private_f_thread_lock_attributes_adjust(0, attributes); - } -#endif // _di_f_thread_lock_attributes_decimate_by_ - -#ifndef _di_f_thread_lock_attributes_decrease_by_ - f_status_t f_thread_lock_attributes_decrease_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->size - amount > 0) { - return private_f_thread_lock_attributes_resize(attributes->size - amount, attributes); - } - - return private_f_thread_lock_attributes_resize(0, attributes); - } -#endif // _di_f_thread_lock_attributes_decrease_by_ - -#ifndef _di_f_thread_lock_attributes_increase_ - f_status_t f_thread_lock_attributes_increase(const f_array_length_t step, f_thread_lock_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && attributes->used + 1 > attributes->size) { - f_array_length_t size = attributes->used + step; - - if (size > F_array_length_t_size_d) { - if (attributes->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_lock_attributes_resize(size, attributes); - } - - return F_data_not; - } -#endif // _di_f_thread_lock_attributes_increase_ - -#ifndef _di_f_thread_lock_attributes_increase_by_ - f_status_t f_thread_lock_attributes_increase_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->used + amount > attributes->size) { - if (attributes->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_lock_attributes_resize(attributes->used + amount, attributes); - } - - return F_data_not; - } -#endif // _di_f_thread_lock_attributes_increase_by_ - -#ifndef _di_f_thread_lock_attributes_resize_ - f_status_t f_thread_lock_attributes_resize(const f_array_length_t length, f_thread_lock_attributes_t * const 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_lock_attributes_resize(length, attributes); - } -#endif // _di_f_thread_lock_attributes_resize_ - #ifndef _di_f_thread_lock_create_ f_status_t f_thread_lock_create(const f_thread_lock_attribute_t * const attribute, f_thread_lock_t * const lock) { #ifndef _di_level_0_parameter_checking_ @@ -1915,102 +1264,6 @@ extern "C" { } #endif // _di_f_thread_lock_write_try_ -#ifndef _di_f_thread_locks_adjust_ - f_status_t f_thread_locks_adjust(const f_array_length_t length, f_thread_locks_t * const locks) { - #ifndef _di_level_0_parameter_checking_ - if (!locks) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_locks_adjust(length, locks); - } -#endif // _di_f_thread_locks_adjust_ - -#ifndef _di_f_thread_locks_decimate_by_ - f_status_t f_thread_locks_decimate_by(const f_array_length_t amount, f_thread_locks_t * const locks) { - #ifndef _di_level_0_parameter_checking_ - if (!locks) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (locks->size - amount > 0) { - return private_f_thread_locks_adjust(locks->size - amount, locks); - } - - return private_f_thread_locks_adjust(0, locks); - } -#endif // _di_f_thread_locks_decimate_by_ - -#ifndef _di_f_thread_locks_decrease_by_ - f_status_t f_thread_locks_decrease_by(const f_array_length_t amount, f_thread_locks_t * const locks) { - #ifndef _di_level_0_parameter_checking_ - if (!locks) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (locks->size - amount > 0) { - return private_f_thread_locks_resize(locks->size - amount, locks); - } - - return private_f_thread_locks_resize(0, locks); - } -#endif // _di_f_thread_locks_decrease_by_ - -#ifndef _di_f_thread_locks_increase_ - f_status_t f_thread_locks_increase(const f_array_length_t step, f_thread_locks_t * const locks) { - #ifndef _di_level_0_parameter_checking_ - if (!locks) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && locks->used + 1 > locks->size) { - f_array_length_t size = locks->used + step; - - if (size > F_array_length_t_size_d) { - if (locks->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_locks_resize(size, locks); - } - - return F_data_not; - } -#endif // _di_f_thread_locks_increase_ - -#ifndef _di_f_thread_locks_increase_by_ - f_status_t f_thread_locks_increase_by(const f_array_length_t amount, f_thread_locks_t * const locks) { - #ifndef _di_level_0_parameter_checking_ - if (!locks) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (locks->used + amount > locks->size) { - if (locks->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_locks_resize(locks->used + amount, locks); - } - - return F_data_not; - } -#endif // _di_f_thread_locks_increase_by_ - -#ifndef _di_f_thread_locks_resize_ - f_status_t f_thread_locks_resize(const f_array_length_t length, f_thread_locks_t * const locks) { - #ifndef _di_level_0_parameter_checking_ - if (!locks) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_locks_resize(length, locks); - } -#endif // _di_f_thread_locks_resize_ - #ifndef _di_f_thread_mutex_attribute_create_ f_status_t f_thread_mutex_attribute_create(f_thread_mutex_attribute_t * const attribute) { #ifndef _di_level_0_parameter_checking_ @@ -2188,102 +1441,6 @@ extern "C" { } #endif // _di_f_thread_mutex_attribute_protocol_set_ -#ifndef _di_f_thread_mutex_attributes_adjust_ - f_status_t f_thread_mutex_attributes_adjust(const f_array_length_t length, f_thread_mutex_attributes_t * const 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_mutex_attributes_adjust(length, attributes); - } -#endif // _di_f_thread_mutex_attributes_adjust_ - -#ifndef _di_f_thread_mutex_attributes_decimate_by_ - f_status_t f_thread_mutex_attributes_decimate_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->size - amount > 0) { - return private_f_thread_mutex_attributes_adjust(attributes->size - amount, attributes); - } - - return private_f_thread_mutex_attributes_adjust(0, attributes); - } -#endif // _di_f_thread_mutex_attributes_decimate_by_ - -#ifndef _di_f_thread_mutex_attributes_decrease_by_ - f_status_t f_thread_mutex_attributes_decrease_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->size - amount > 0) { - return private_f_thread_mutex_attributes_resize(attributes->size - amount, attributes); - } - - return private_f_thread_mutex_attributes_resize(0, attributes); - } -#endif // _di_f_thread_mutex_attributes_decrease_by_ - -#ifndef _di_f_thread_mutex_attributes_increase_ - f_status_t f_thread_mutex_attributes_increase(const f_array_length_t step, f_thread_mutex_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && attributes->used + 1 > attributes->size) { - f_array_length_t size = attributes->used + step; - - if (size > F_array_length_t_size_d) { - if (attributes->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_mutex_attributes_resize(size, attributes); - } - - return F_data_not; - } -#endif // _di_f_thread_mutex_attributes_increase_ - -#ifndef _di_f_thread_mutex_attributes_increase_by_ - f_status_t f_thread_mutex_attributes_increase_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes) { - #ifndef _di_level_0_parameter_checking_ - if (!attributes) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (attributes->used + amount > attributes->size) { - if (attributes->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_mutex_attributes_resize(attributes->used + amount, attributes); - } - - return F_data_not; - } -#endif // _di_f_thread_mutex_attributes_increase_by_ - -#ifndef _di_f_thread_mutex_attributes_resize_ - f_status_t f_thread_mutex_attributes_resize(const f_array_length_t length, f_thread_mutex_attributes_t * const 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_mutex_attributes_resize(length, attributes); - } -#endif // _di_f_thread_mutex_attributes_resize_ - #ifndef _di_f_thread_mutex_create_ f_status_t f_thread_mutex_create(f_thread_mutex_attribute_t * const attribute, f_thread_mutex_t * const mutex) { #ifndef _di_level_0_parameter_checking_ @@ -2621,102 +1778,6 @@ 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 * const 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 * const mutexs) { - #ifndef _di_level_0_parameter_checking_ - if (!mutexs) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - 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 * const mutexs) { - #ifndef _di_level_0_parameter_checking_ - if (!mutexs) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - 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(const f_array_length_t step, f_thread_mutexs_t * const mutexs) { - #ifndef _di_level_0_parameter_checking_ - if (!mutexs) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && mutexs->used + 1 > mutexs->size) { - f_array_length_t size = mutexs->used + step; - - if (size > F_array_length_t_size_d) { - if (mutexs->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - 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 * const mutexs) { - #ifndef _di_level_0_parameter_checking_ - if (!mutexs) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (mutexs->used + amount > mutexs->size) { - if (mutexs->used + amount > F_array_length_t_size_d) { - 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 * const 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 * const once) { #ifndef _di_level_0_parameter_checking_ @@ -2792,207 +1853,17 @@ extern "C" { } #endif // _di_f_thread_scheduler_priority_set_ -#ifndef _di_f_thread_semaphores_adjust_ - f_status_t f_thread_semaphores_adjust(const f_array_length_t length, f_thread_semaphores_t * const semaphores) { - #ifndef _di_level_0_parameter_checking_ - if (!semaphores) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_semaphores_adjust(length, semaphores); - } -#endif // _di_f_thread_semaphores_adjust_ - -#ifndef _di_f_thread_semaphores_decimate_by_ - f_status_t f_thread_semaphores_decimate_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores) { - #ifndef _di_level_0_parameter_checking_ - if (!semaphores) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (semaphores->size - amount > 0) { - return private_f_thread_semaphores_adjust(semaphores->size - amount, semaphores); - } - - return private_f_thread_semaphores_adjust(0, semaphores); - } -#endif // _di_f_thread_semaphores_decimate_by_ - -#ifndef _di_f_thread_semaphores_decrease_by_ - f_status_t f_thread_semaphores_decrease_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores) { - #ifndef _di_level_0_parameter_checking_ - if (!semaphores) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (semaphores->size - amount > 0) { - return private_f_thread_semaphores_resize(semaphores->size - amount, semaphores); - } - - return private_f_thread_semaphores_resize(0, semaphores); - } -#endif // _di_f_thread_semaphores_decrease_by_ - -#ifndef _di_f_thread_semaphores_increase_ - f_status_t f_thread_semaphores_increase(const f_array_length_t step, f_thread_semaphores_t * const semaphores) { - #ifndef _di_level_0_parameter_checking_ - if (!semaphores) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && semaphores->used + 1 > semaphores->size) { - f_array_length_t size = semaphores->used + step; - - if (size > F_array_length_t_size_d) { - if (semaphores->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_semaphores_resize(size, semaphores); - } - - return F_data_not; - } -#endif // _di_f_thread_semaphores_increase_ - -#ifndef _di_f_thread_semaphores_increase_by_ - f_status_t f_thread_semaphores_increase_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores) { - #ifndef _di_level_0_parameter_checking_ - if (!semaphores) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (semaphores->used + amount > semaphores->size) { - if (semaphores->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_semaphores_resize(semaphores->used + amount, semaphores); - } - - return F_data_not; - } -#endif // _di_f_thread_semaphores_increase_by_ - -#ifndef _di_f_thread_semaphores_resize_ - f_status_t f_thread_semaphores_resize(const f_array_length_t length, f_thread_semaphores_t * const semaphores) { - #ifndef _di_level_0_parameter_checking_ - if (!semaphores) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_semaphores_resize(length, semaphores); - } -#endif // _di_f_thread_semaphores_resize_ - -#ifndef _di_f_thread_sets_adjust_ - f_status_t f_thread_sets_adjust(const f_array_length_t length, f_thread_sets_t * const 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 * const sets) { - #ifndef _di_level_0_parameter_checking_ - if (!sets) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - 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 * const sets) { - #ifndef _di_level_0_parameter_checking_ - if (!sets) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - 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(const f_array_length_t step, f_thread_sets_t * const sets) { - #ifndef _di_level_0_parameter_checking_ - if (!sets) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && sets->used + 1 > sets->size) { - f_array_length_t size = sets->used + step; - - if (size > F_array_length_t_size_d) { - if (sets->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - 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 * const sets) { - #ifndef _di_level_0_parameter_checking_ - if (!sets) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (sets->used + amount > sets->size) { - if (sets->used + amount > F_array_length_t_size_d) { - 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 * const 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_mask_ f_status_t f_thread_signal_mask(const int how, const sigset_t *next, sigset_t * const current) { #ifndef _di_level_0_parameter_checking_ if (!next && !current) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (pthread_sigmask(how, next, current) < 0) { - if (errno == EFAULT) return F_status_set_error(F_buffer); - if (errno == EINVAL) return F_status_set_error(F_parameter); + const int error = pthread_sigmask(how, next, current); + + if (error) { + if (error == EFAULT) return F_status_set_error(F_buffer); + if (error == EINVAL) return F_status_set_error(F_parameter); return F_status_set_error(F_failure); } @@ -3139,102 +2010,6 @@ extern "C" { } #endif // _di_f_thread_spin_unlock_ -#ifndef _di_f_thread_spins_adjust_ - f_status_t f_thread_spins_adjust(const f_array_length_t length, f_thread_spins_t * const spins) { - #ifndef _di_level_0_parameter_checking_ - if (!spins) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_spins_adjust(length, spins); - } -#endif // _di_f_thread_spins_adjust_ - -#ifndef _di_f_thread_spins_decimate_by_ - f_status_t f_thread_spins_decimate_by(const f_array_length_t amount, f_thread_spins_t * const spins) { - #ifndef _di_level_0_parameter_checking_ - if (!spins) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (spins->size - amount > 0) { - return private_f_thread_spins_adjust(spins->size - amount, spins); - } - - return private_f_thread_spins_adjust(0, spins); - } -#endif // _di_f_thread_spins_decimate_by_ - -#ifndef _di_f_thread_spins_decrease_by_ - f_status_t f_thread_spins_decrease_by(const f_array_length_t amount, f_thread_spins_t * const spins) { - #ifndef _di_level_0_parameter_checking_ - if (!spins) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (spins->size - amount > 0) { - return private_f_thread_spins_resize(spins->size - amount, spins); - } - - return private_f_thread_spins_resize(0, spins); - } -#endif // _di_f_thread_spins_decrease_by_ - -#ifndef _di_f_thread_spins_increase_ - f_status_t f_thread_spins_increase(const f_array_length_t step, f_thread_spins_t * const spins) { - #ifndef _di_level_0_parameter_checking_ - if (!spins) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && spins->used + 1 > spins->size) { - f_array_length_t size = spins->used + step; - - if (size > F_array_length_t_size_d) { - if (spins->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_thread_spins_resize(size, spins); - } - - return F_data_not; - } -#endif // _di_f_thread_spins_increase_ - -#ifndef _di_f_thread_spins_increase_by_ - f_status_t f_thread_spins_increase_by(const f_array_length_t amount, f_thread_spins_t * const spins) { - #ifndef _di_level_0_parameter_checking_ - if (!spins) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (spins->used + amount > spins->size) { - if (spins->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_thread_spins_resize(spins->used + amount, spins); - } - - return F_data_not; - } -#endif // _di_f_thread_spins_increase_by_ - -#ifndef _di_f_thread_spins_resize_ - f_status_t f_thread_spins_resize(const f_array_length_t length, f_thread_spins_t * const spins) { - #ifndef _di_level_0_parameter_checking_ - if (!spins) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_thread_spins_resize(length, spins); - } -#endif // _di_f_thread_spins_resize_ - #ifndef _di_f_thread_unlock_ f_status_t f_thread_unlock(f_thread_lock_t * const lock) { #ifndef _di_level_0_parameter_checking_ diff --git a/level_0/f_thread/c/thread.h b/level_0/f_thread/c/thread.h index 3334c83..260c011 100644 --- a/level_0/f_thread/c/thread.h +++ b/level_0/f_thread/c/thread.h @@ -29,7 +29,21 @@ #include // FLL-0 thread includes. -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef __cplusplus extern "C" { @@ -123,9 +137,9 @@ extern "C" { * * @see pthread_condattr_getclock() */ -#ifndef _di_f_thread_attribute_clock_get_ - extern f_status_t f_thread_attribute_clock_get(const f_thread_condition_attribute_t * const attribute, clockid_t * const id); -#endif // _di_f_thread_attribute_clock_get_ +#ifndef _di_f_thread_attribute_condition_clock_get_ + extern f_status_t f_thread_attribute_condition_clock_get(const f_thread_condition_attribute_t * const attribute, clockid_t * const id); +#endif // _di_f_thread_attribute_condition_clock_get_ /** * Set the clock selection thread condition attribute. @@ -144,9 +158,9 @@ extern "C" { * * @see pthread_condattr_setclock() */ -#ifndef _di_f_thread_attribute_clock_set_ - extern f_status_t f_thread_attribute_clock_set(const clockid_t id, f_thread_condition_attribute_t * const attribute); -#endif // _di_f_thread_attribute_clock_set_ +#ifndef _di_f_thread_attribute_condition_clock_set_ + extern f_status_t f_thread_attribute_condition_clock_set(const clockid_t id, f_thread_condition_attribute_t * const attribute); +#endif // _di_f_thread_attribute_condition_clock_set_ /** * Get the process shared thread condition attribute. @@ -618,136 +632,6 @@ extern "C" { #endif // _di_f_thread_attribute_stack_size_set_ /** - * Resize the thread 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 * const attributes); -#endif // _di_f_thread_attributes_adjust_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * 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 * const attributes); -#endif // _di_f_thread_attributes_decimate_by_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * 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 * const attributes); -#endif // _di_f_thread_attributes_decrease_by_ - -/** - * Increase the size of the thread 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @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(const f_array_length_t step, f_thread_attributes_t * const attributes); -#endif // _di_f_thread_attributes_increase_ - -/** - * Resize the thread attributes array to a larger size. - * - * This will resize making the array 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_d). - * 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_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_by_ - extern f_status_t f_thread_attributes_increase_by(const f_array_length_t amount, f_thread_attributes_t * const attributes); -#endif // _di_f_thread_attributes_increase_by_ - -/** - * Resize the thread 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 * const attributes); -#endif // _di_f_thread_attributes_resize_ - -/** * Create (initialize) a thread barrier attribute structure. * * @param attribute @@ -835,136 +719,6 @@ extern "C" { #endif // _di_f_thread_barrier_attribute_shared_set_ /** - * Resize the thread barrier attributes array. - * - * @param length - * The new size to use. - * @param attributes - * The thread 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_barrier_attributes_adjust_ - extern f_status_t f_thread_barrier_attributes_adjust(const f_array_length_t length, f_thread_barrier_attributes_t * const attributes); -#endif // _di_f_thread_barrier_attributes_adjust_ - -/** - * Resize the thread barrier 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 thread attributes array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_barrier_attributes_decimate_by_ - extern f_status_t f_thread_barrier_attributes_decimate_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes); -#endif // _di_f_thread_barrier_attributes_decimate_by_ - -/** - * Resize the thread barrier 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 thread attributes array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_barrier_attributes_decrease_by_ - extern f_status_t f_thread_barrier_attributes_decrease_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes); -#endif // _di_f_thread_barrier_attributes_decrease_by_ - -/** - * Increase the size of the thread barrier 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param attributes - * The thread 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_barrier_attributes_increase_ - extern f_status_t f_thread_barrier_attributes_increase(const f_array_length_t step, f_thread_barrier_attributes_t * const attributes); -#endif // _di_f_thread_barrier_attributes_increase_ - -/** - * Resize the thread barrier attributes array to a larger size. - * - * This will resize making the array 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_d). - * 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 thread 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_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_barrier_attributes_increase_by_ - extern f_status_t f_thread_barrier_attributes_increase_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes); -#endif // _di_f_thread_barrier_attributes_increase_by_ - -/** - * Resize the thread barrier attributes array. - * - * @param length - * The new size to use. - * @param attributes - * The thread 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_barrier_attributes_resize_ - extern f_status_t f_thread_barrier_attributes_resize(const f_array_length_t length, f_thread_barrier_attributes_t * const attributes); -#endif // _di_f_thread_barrier_attributes_resize_ - -/** * Create (initialize) a thread barrier structure. * * @param barrier @@ -974,8 +728,10 @@ extern "C" { * @return * F_none on success. * - * F_parameter (with error bit) if a parameter is invalid. + * F_busy (with error bit) if barrier is already in use (a re-initialization attempt). * F_memory_not (with error bit) if out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * F_resource_not (with error bit) if necessary resouces to perform create are unavailable. * * F_failure (with error bit) on any other error. * @@ -1030,136 +786,6 @@ extern "C" { #endif // _di_f_thread_barrier_wait_ /** - * Resize the thread barriers array. - * - * @param length - * The new size to use. - * @param barriers - * The thread barriers 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_barriers_adjust_ - extern f_status_t f_thread_barriers_adjust(const f_array_length_t length, f_thread_barriers_t * const barriers); -#endif // _di_f_thread_barriers_adjust_ - -/** - * Resize the thread barriers 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 barriers - * The thread barriers array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_barriers_decimate_by_ - extern f_status_t f_thread_barriers_decimate_by(const f_array_length_t amount, f_thread_barriers_t * const barriers); -#endif // _di_f_thread_barriers_decimate_by_ - -/** - * Resize the thread barriers 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 barriers - * The thread barriers array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_barriers_decrease_by_ - extern f_status_t f_thread_barriers_decrease_by(const f_array_length_t amount, f_thread_barriers_t * const barriers); -#endif // _di_f_thread_barriers_decrease_by_ - -/** - * Increase the size of the thread barriers 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param barriers - * The thread barriers 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_barriers_increase_ - extern f_status_t f_thread_barriers_increase(const f_array_length_t step, f_thread_barriers_t * const barriers); -#endif // _di_f_thread_barriers_increase_ - -/** - * Resize the thread barriers array to a larger size. - * - * This will resize making the array 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_d). - * 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 barriers - * The thread barriers 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_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_barriers_increase_by_ - extern f_status_t f_thread_barriers_increase_by(const f_array_length_t amount, f_thread_barriers_t * const barriers); -#endif // _di_f_thread_barriers_increase_by_ - -/** - * Resize the thread barriers array. - * - * @param length - * The new size to use. - * @param barriers - * The thread barriers 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_barriers_resize_ - extern f_status_t f_thread_barriers_resize(const f_array_length_t length, f_thread_barriers_t * const barriers); -#endif // _di_f_thread_barriers_resize_ - -/** * Get the ID of the calling thread. * * @return @@ -1377,136 +1003,6 @@ extern "C" { #endif // _di_f_thread_condition_attribute_delete_ /** - * Resize the thread 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_condition_attributes_adjust_ - extern f_status_t f_thread_condition_attributes_adjust(const f_array_length_t length, f_thread_condition_attributes_t * const attributes); -#endif // _di_f_thread_condition_attributes_adjust_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_condition_attributes_decimate_by_ - extern f_status_t f_thread_condition_attributes_decimate_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes); -#endif // _di_f_thread_condition_attributes_decimate_by_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_condition_attributes_decrease_by_ - extern f_status_t f_thread_condition_attributes_decrease_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes); -#endif // _di_f_thread_condition_attributes_decrease_by_ - -/** - * Increase the size of the thread 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @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_condition_attributes_increase_ - extern f_status_t f_thread_condition_attributes_increase(const f_array_length_t step, f_thread_condition_attributes_t * const attributes); -#endif // _di_f_thread_condition_attributes_increase_ - -/** - * Resize the thread attributes array to a larger size. - * - * This will resize making the array 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_d). - * 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_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_condition_attributes_increase_by_ - extern f_status_t f_thread_condition_attributes_increase_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes); -#endif // _di_f_thread_condition_attributes_increase_by_ - -/** - * Resize the thread 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_condition_attributes_resize_ - extern f_status_t f_thread_condition_attributes_resize(const f_array_length_t length, f_thread_condition_attributes_t * const attributes); -#endif // _di_f_thread_condition_attributes_resize_ - -/** * Initialize a condition. * * @param attribute @@ -1648,136 +1144,6 @@ extern "C" { #endif // _di_f_thread_condition_wait_timed_ /** - * Resize the thread conditions array. - * - * @param length - * The new size to use. - * @param conditions - * The string conditions 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_conditions_adjust_ - extern f_status_t f_thread_conditions_adjust(const f_array_length_t length, f_thread_conditions_t * const conditions); -#endif // _di_f_thread_conditions_adjust_ - -/** - * Resize the thread conditions 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 conditions - * The string conditions array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_conditions_decimate_by_ - extern f_status_t f_thread_conditions_decimate_by(const f_array_length_t amount, f_thread_conditions_t * const conditions); -#endif // _di_f_thread_conditions_decimate_by_ - -/** - * Resize the thread conditions 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 conditions - * The string conditions array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_conditions_decrease_by_ - extern f_status_t f_thread_conditions_decrease_by(const f_array_length_t amount, f_thread_conditions_t * const conditions); -#endif // _di_f_thread_conditions_decrease_by_ - -/** - * Increase the size of the thread conditions 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param conditions - * The string conditions 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_conditions_increase_ - extern f_status_t f_thread_conditions_increase(const f_array_length_t step, f_thread_conditions_t * const conditions); -#endif // _di_f_thread_conditions_increase_ - -/** - * Resize the thread conditions array to a larger size. - * - * This will resize making the array 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_d). - * 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 conditions - * The string conditions 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_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_conditions_increase_by_ - extern f_status_t f_thread_conditions_increase_by(const f_array_length_t amount, f_thread_conditions_t * const conditions); -#endif // _di_f_thread_conditions_increase_by_ - -/** - * Resize the thread conditions array. - * - * @param length - * The new size to use. - * @param conditions - * The string conditions 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_conditions_resize_ - extern f_status_t f_thread_conditions_resize(const f_array_length_t length, f_thread_conditions_t * const conditions); -#endif // _di_f_thread_conditions_resize_ - -/** * Create a thread. * * @param attribute @@ -2027,136 +1393,6 @@ extern "C" { #endif // _di_f_thread_key_set_ /** - * Resize the thread keys array. - * - * @param length - * The new size to use. - * @param keys - * The string keys 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_keys_adjust_ - extern f_status_t f_thread_keys_adjust(const f_array_length_t length, f_thread_keys_t * const keys); -#endif // _di_f_thread_keys_adjust_ - -/** - * Resize the thread keys 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 keys - * The string keys array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_keys_decimate_by_ - extern f_status_t f_thread_keys_decimate_by(const f_array_length_t amount, f_thread_keys_t * const keys); -#endif // _di_f_thread_keys_decimate_by_ - -/** - * Resize the thread keys 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 keys - * The string keys array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_keys_decrease_by_ - extern f_status_t f_thread_keys_decrease_by(const f_array_length_t amount, f_thread_keys_t * const keys); -#endif // _di_f_thread_keys_decrease_by_ - -/** - * Increase the size of the thread keys 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param keys - * The string keys 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_keys_increase_ - extern f_status_t f_thread_keys_increase(const f_array_length_t step, f_thread_keys_t * const keys); -#endif // _di_f_thread_keys_increase_ - -/** - * Resize the thread keys array to a larger size. - * - * This will resize making the array 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_d). - * 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 keys - * The string keys 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_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_keys_increase_by_ - extern f_status_t f_thread_keys_increase_by(const f_array_length_t amount, f_thread_keys_t * const keys); -#endif // _di_f_thread_keys_increase_by_ - -/** - * Resize the thread keys array. - * - * @param length - * The new size to use. - * @param keys - * The string keys 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_keys_resize_ - extern f_status_t f_thread_keys_resize(const f_array_length_t length, f_thread_keys_t * const keys); -#endif // _di_f_thread_keys_resize_ - -/** * Create a thread lock attribute. * * @param attribute @@ -2245,136 +1481,6 @@ extern "C" { #endif // _di_f_thread_lock_attribute_shared_set_ /** - * Resize the thread 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_lock_attributes_adjust_ - extern f_status_t f_thread_lock_attributes_adjust(const f_array_length_t length, f_thread_lock_attributes_t * const attributes); -#endif // _di_f_thread_lock_attributes_adjust_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_lock_attributes_decimate_by_ - extern f_status_t f_thread_lock_attributes_decimate_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes); -#endif // _di_f_thread_lock_attributes_decimate_by_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_lock_attributes_decrease_by_ - extern f_status_t f_thread_lock_attributes_decrease_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes); -#endif // _di_f_thread_lock_attributes_decrease_by_ - -/** - * Increase the size of the thread 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @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_lock_attributes_increase_ - extern f_status_t f_thread_lock_attributes_increase(const f_array_length_t step, f_thread_lock_attributes_t * const attributes); -#endif // _di_f_thread_lock_attributes_increase_ - -/** - * Resize the thread attributes array to a larger size. - * - * This will resize making the array 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_d). - * 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_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_lock_attributes_increase_by_ - extern f_status_t f_thread_lock_attributes_increase_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes); -#endif // _di_f_thread_lock_attributes_increase_by_ - -/** - * Resize the thread 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_lock_attributes_resize_ - extern f_status_t f_thread_lock_attributes_resize(const f_array_length_t length, f_thread_lock_attributes_t * const attributes); -#endif // _di_f_thread_lock_attributes_resize_ - -/** * Create a thread read/write lock. * * @param attribute @@ -2572,136 +1678,6 @@ extern "C" { #endif // _di_f_thread_lock_write_try_ /** - * Resize the read/write locks array. - * - * @param length - * The new size to use. - * @param locks - * The string locks 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_locks_adjust_ - extern f_status_t f_thread_locks_adjust(const f_array_length_t length, f_thread_locks_t * const locks); -#endif // _di_f_thread_locks_adjust_ - -/** - * Resize the read/write locks 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 locks - * The string locks array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_locks_decimate_by_ - extern f_status_t f_thread_locks_decimate_by(const f_array_length_t amount, f_thread_locks_t * const locks); -#endif // _di_f_thread_locks_decimate_by_ - -/** - * Resize the read/write locks 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 locks - * The string locks array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_locks_decrease_by_ - extern f_status_t f_thread_locks_decrease_by(const f_array_length_t amount, f_thread_locks_t * const locks); -#endif // _di_f_thread_locks_decrease_by_ - -/** - * Increase the size of the read/write 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param locks - * The string locks 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_locks_increase_ - extern f_status_t f_thread_locks_increase(const f_array_length_t step, f_thread_locks_t * const locks); -#endif // _di_f_thread_locks_increase_ - -/** - * Resize the read/write locks array to a larger size. - * - * This will resize making the array 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_d). - * 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 locks - * The string locks 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_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_locks_increase_by_ - extern f_status_t f_thread_locks_increase_by(const f_array_length_t amount, f_thread_locks_t * const locks); -#endif // _di_f_thread_locks_increase_by_ - -/** - * Resize the read/write locks array. - * - * @param length - * The new size to use. - * @param locks - * The string locks 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_locks_resize_ - extern f_status_t f_thread_locks_resize(const f_array_length_t length, f_thread_locks_t * const locks); -#endif // _di_f_thread_locks_resize_ - -/** * Create a thread mutex attribute. * * @param attribute @@ -2874,175 +1850,45 @@ extern "C" { * * @param attribute * The thread mutex attribute. - * @param protocol - * The protocol. - * - * @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. - * - * F_failure (with error bit) on any other error. - * - * @see pthread_mutexattr_getprotocol() - */ -#ifndef _di_f_thread_mutex_attribute_protocol_get_ - extern f_status_t f_thread_mutex_attribute_protocol_get(const f_thread_mutex_attribute_t * const attribute, int * const protocol); -#endif // _di_f_thread_mutex_attribute_protocol_get_ - -/** - * Set the mutex attribute protocol. - * - * @param protocol - * The protocol. - * @param attribute - * The thread mutex attribute. - * - * @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. - * F_supported_not (with error bit) if the protocol is not supported. - * - * F_failure (with error bit) on any other error. - * - * @see pthread_mutexattr_setprotocol() - */ -#ifndef _di_f_thread_mutex_attribute_protocol_set_ - extern f_status_t f_thread_mutex_attribute_protocol_set(const int protocol, f_thread_mutex_attribute_t * const attribute); -#endif // _di_f_thread_mutex_attribute_protocol_set_ - -/** - * Resize the thread 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_mutex_attributes_adjust_ - extern f_status_t f_thread_mutex_attributes_adjust(const f_array_length_t length, f_thread_mutex_attributes_t * const attributes); -#endif // _di_f_thread_mutex_attributes_adjust_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_mutex_attributes_decimate_by_ - extern f_status_t f_thread_mutex_attributes_decimate_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes); -#endif // _di_f_thread_mutex_attributes_decimate_by_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_mutex_attributes_decrease_by_ - extern f_status_t f_thread_mutex_attributes_decrease_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes); -#endif // _di_f_thread_mutex_attributes_decrease_by_ - -/** - * Increase the size of the thread 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @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_mutex_attributes_increase_ - extern f_status_t f_thread_mutex_attributes_increase(const f_array_length_t step, f_thread_mutex_attributes_t * const attributes); -#endif // _di_f_thread_mutex_attributes_increase_ - -/** - * Resize the thread attributes array to a larger size. - * - * This will resize making the array 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_d). - * 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. + * @param protocol + * The protocol. * * @return * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= 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. + * F_prohibited (with error bit) if not allowed to perform the operation. + * + * F_failure (with error bit) on any other error. + * + * @see pthread_mutexattr_getprotocol() */ -#ifndef _di_f_thread_mutex_attributes_increase_by_ - extern f_status_t f_thread_mutex_attributes_increase_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes); -#endif // _di_f_thread_mutex_attributes_increase_by_ +#ifndef _di_f_thread_mutex_attribute_protocol_get_ + extern f_status_t f_thread_mutex_attribute_protocol_get(const f_thread_mutex_attribute_t * const attribute, int * const protocol); +#endif // _di_f_thread_mutex_attribute_protocol_get_ /** - * Resize the thread attributes array. + * Set the mutex attribute protocol. * - * @param length - * The new size to use. - * @param attributes - * The string attributes array to adjust. + * @param protocol + * The protocol. + * @param attribute + * The thread mutex attribute. * * @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. + * F_prohibited (with error bit) if not allowed to perform the operation. + * F_supported_not (with error bit) if the protocol is not supported. + * + * F_failure (with error bit) on any other error. + * + * @see pthread_mutexattr_setprotocol() */ -#ifndef _di_f_thread_mutex_attributes_resize_ - extern f_status_t f_thread_mutex_attributes_resize(const f_array_length_t length, f_thread_mutex_attributes_t * const attributes); -#endif // _di_f_thread_mutex_attributes_resize_ +#ifndef _di_f_thread_mutex_attribute_protocol_set_ + extern f_status_t f_thread_mutex_attribute_protocol_set(const int protocol, f_thread_mutex_attribute_t * const attribute); +#endif // _di_f_thread_mutex_attribute_protocol_set_ /** * Create a thread mutex. @@ -3245,136 +2091,6 @@ extern "C" { #endif // _di_f_thread_mutex_unlock_ /** - * Resize the thread 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 * const mutexs); -#endif // _di_f_thread_mutexs_adjust_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * 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 * const mutexs); -#endif // _di_f_thread_mutexs_decimate_by_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * 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 * const mutexs); -#endif // _di_f_thread_mutexs_decrease_by_ - -/** - * Increase the size of the thread 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @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(const f_array_length_t step, f_thread_mutexs_t * const mutexs); -#endif // _di_f_thread_mutexs_increase_ - -/** - * Resize the thread mutexs array to a larger size. - * - * This will resize making the array 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_d). - * 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_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_by_ - extern f_status_t f_thread_mutexs_increase_by(const f_array_length_t amount, f_thread_mutexs_t * const mutexs); -#endif // _di_f_thread_mutexs_increase_by_ - -/** - * Resize the thread 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 * const 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. @@ -3723,266 +2439,6 @@ extern "C" { #endif // _di_f_thread_semaphore_value_get_ /** - * Resize the thread semaphores array. - * - * @param length - * The new size to use. - * @param semaphores - * The string semaphores 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_semaphores_adjust_ - extern f_status_t f_thread_semaphores_adjust(const f_array_length_t length, f_thread_semaphores_t * const semaphores); -#endif // _di_f_thread_semaphores_adjust_ - -/** - * Resize the thread semaphores 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 semaphores - * The string semaphores array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_semaphores_decimate_by_ - extern f_status_t f_thread_semaphores_decimate_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores); -#endif // _di_f_thread_semaphores_decimate_by_ - -/** - * Resize the thread semaphores 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 semaphores - * The string semaphores array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_semaphores_decrease_by_ - extern f_status_t f_thread_semaphores_decrease_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores); -#endif // _di_f_thread_semaphores_decrease_by_ - -/** - * Increase the size of the thread semaphores 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param semaphores - * The string semaphores 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_semaphores_increase_ - extern f_status_t f_thread_semaphores_increase(const f_array_length_t step, f_thread_semaphores_t * const semaphores); -#endif // _di_f_thread_semaphores_increase_ - -/** - * Resize the thread semaphores array to a larger size. - * - * This will resize making the array 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_d). - * 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 semaphores - * The string semaphores 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_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_semaphores_increase_by_ - extern f_status_t f_thread_semaphores_increase_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores); -#endif // _di_f_thread_semaphores_increase_by_ - -/** - * Resize the thread semaphores array. - * - * @param length - * The new size to use. - * @param semaphores - * The string semaphores 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_semaphores_resize_ - extern f_status_t f_thread_semaphores_resize(const f_array_length_t length, f_thread_semaphores_t * const semaphores); -#endif // _di_f_thread_semaphores_resize_ - -/** - * Resize the thread 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 * const sets); -#endif // _di_f_thread_sets_adjust_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * 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 * const sets); -#endif // _di_f_thread_sets_decimate_by_ - -/** - * Resize the thread 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_data_not if amount is 0. - * - * 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 * const sets); -#endif // _di_f_thread_sets_decrease_by_ - -/** - * Increase the size of the thread 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @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(const f_array_length_t step, f_thread_sets_t * const sets); -#endif // _di_f_thread_sets_increase_ - -/** - * Resize the thread sets array to a larger size. - * - * This will resize making the array 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_d). - * 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_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_by_ - extern f_status_t f_thread_sets_increase_by(const f_array_length_t amount, f_thread_sets_t * const sets); -#endif // _di_f_thread_sets_increase_by_ - -/** - * Resize the thread 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 * const sets); -#endif // _di_f_thread_sets_resize_ - -/** * Get or assign the current signal set in use. * * Either set or previous may be NULL but not both (at least one is required). @@ -4175,136 +2631,6 @@ extern "C" { #endif // _di_f_thread_spin_unlock_ /** - * Resize the thread spin locks array. - * - * @param length - * The new size to use. - * @param spins - * The string spins 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_spins_adjust_ - extern f_status_t f_thread_spins_adjust(const f_array_length_t length, f_thread_spins_t * const spins); -#endif // _di_f_thread_spins_adjust_ - -/** - * Resize the thread spin locks 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 spins - * The string spins array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_spins_decimate_by_ - extern f_status_t f_thread_spins_decimate_by(const f_array_length_t amount, f_thread_spins_t * const spins); -#endif // _di_f_thread_spins_decimate_by_ - -/** - * Resize the thread spin locks 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 spins - * The string spins array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_thread_spins_decrease_by_ - extern f_status_t f_thread_spins_decrease_by(const f_array_length_t amount, f_thread_spins_t * const spins); -#endif // _di_f_thread_spins_decrease_by_ - -/** - * Increase the size of the thread spin locks 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param spins - * The string spins 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_spins_increase_ - extern f_status_t f_thread_spins_increase(const f_array_length_t step, f_thread_spins_t * const spins); -#endif // _di_f_thread_spins_increase_ - -/** - * Resize the thread spin locks array to a larger size. - * - * This will resize making the array 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_d). - * 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 spins - * The string spins 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_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_spins_increase_by_ - extern f_status_t f_thread_spins_increase_by(const f_array_length_t amount, f_thread_spins_t * const spins); -#endif // _di_f_thread_spins_increase_by_ - -/** - * Resize the thread spin locks array. - * - * @param length - * The new size to use. - * @param spins - * The string spins 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_spins_resize_ - extern f_status_t f_thread_spins_resize(const f_array_length_t length, f_thread_spins_t * const spins); -#endif // _di_f_thread_spins_resize_ - -/** * Unlock the read/write lock. * * @param lock diff --git a/level_0/f_thread/c/thread/attribute.c b/level_0/f_thread/c/thread/attribute.c new file mode 100644 index 0000000..837929b --- /dev/null +++ b/level_0/f_thread/c/thread/attribute.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "attribute.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_attributes_adjust_ + f_status_t f_thread_attributes_adjust(const f_array_length_t length, f_thread_attributes_t * const 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 * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + 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 * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + 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(const f_array_length_t step, f_thread_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && attributes->used + 1 > attributes->size) { + f_array_length_t size = attributes->used + step; + + if (size > F_array_length_t_size_d) { + if (attributes->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + 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 * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->used + amount > attributes->size) { + if (attributes->used + amount > F_array_length_t_size_d) { + 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 * const 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_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/attribute.h b/level_0/f_thread/c/thread/attribute.h new file mode 100644 index 0000000..684f500 --- /dev/null +++ b/level_0/f_thread/c/thread/attribute.h @@ -0,0 +1,203 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_attribute_h +#define _F_thread_attribute_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_attr_t. + */ +#ifndef _di_f_thread_attribute_t_ + typedef pthread_attr_t f_thread_attribute_t; + + #define f_thread_attribute_t_initialize { 0 } + + #define macro_f_thread_attribute_t_initialize(attribute) attribute + + // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). + #define macro_f_thread_attribute_t_clear(attribute) attribute.__align = 0; + + #define macro_f_thread_attribute_t_delete_simple(attribute) f_thread_attribute_delete(&attribute); +#endif // _di_f_thread_attribute_t_ + +/** + * An array of f_thread_attribute_t. + * + * array: The array of f_thread_attribute_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_attributes_t_ + typedef struct { + f_thread_attribute_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_attributes_t; + + #define f_thread_attributes_t_initialize { 0, 0, 0 } + + #define macro_f_thread_attributes_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_attributes_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_attributes_t_clear(attributes) macro_f_memory_structure_clear(attributes) + + #define macro_f_thread_attributes_t_resize(status, attributes, length) status = f_thread_attributes_resize(length, &attributes); + #define macro_f_thread_attributes_t_adjust(status, attributes, length) status = f_thread_attributes_adjust(length, &attributes); + + #define macro_f_thread_attributes_t_delete_simple(attributes) f_thread_attributes_resize(0, &attributes); + #define macro_f_thread_attributes_t_destroy_simple(attributes) f_thread_attributes_adjust(0, &attributes); + + #define macro_f_thread_attributes_t_increase(status, step, attributes) status = f_thread_attributes_increase(step, attributes); + #define macro_f_thread_attributes_t_increase_by(status, attributes, amount) status = f_thread_attributes_increase_by(amount, attributes); + #define macro_f_thread_attributes_t_decrease_by(status, attributes, amount) status = f_thread_attributes_decrease_by(amount, attributes); + #define macro_f_thread_attributes_t_decimate_by(status, attributes, amount) status = f_thread_attributes_decimate_by(amount, attributes); +#endif // _di_f_thread_attributes_t_ + +/** + * Resize the thread 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 * const attributes); +#endif // _di_f_thread_attributes_adjust_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * 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 * const attributes); +#endif // _di_f_thread_attributes_decimate_by_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * 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 * const attributes); +#endif // _di_f_thread_attributes_decrease_by_ + +/** + * Increase the size of the thread 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @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(const f_array_length_t step, f_thread_attributes_t * const attributes); +#endif // _di_f_thread_attributes_increase_ + +/** + * Resize the thread attributes array to a larger size. + * + * This will resize making the array 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_d). + * 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_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_by_ + extern f_status_t f_thread_attributes_increase_by(const f_array_length_t amount, f_thread_attributes_t * const attributes); +#endif // _di_f_thread_attributes_increase_by_ + +/** + * Resize the thread 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 * const attributes); +#endif // _di_f_thread_attributes_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_attribute_h diff --git a/level_0/f_thread/c/thread/barrier.c b/level_0/f_thread/c/thread/barrier.c new file mode 100644 index 0000000..d741bbb --- /dev/null +++ b/level_0/f_thread/c/thread/barrier.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "barrier.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_barriers_adjust_ + f_status_t f_thread_barriers_adjust(const f_array_length_t length, f_thread_barriers_t * const barriers) { + #ifndef _di_level_0_parameter_checking_ + if (!barriers) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_barriers_adjust(length, barriers); + } +#endif // _di_f_thread_barriers_adjust_ + +#ifndef _di_f_thread_barriers_decimate_by_ + f_status_t f_thread_barriers_decimate_by(const f_array_length_t amount, f_thread_barriers_t * const barriers) { + #ifndef _di_level_0_parameter_checking_ + if (!barriers) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (barriers->size - amount > 0) { + return private_f_thread_barriers_adjust(barriers->size - amount, barriers); + } + + return private_f_thread_barriers_adjust(0, barriers); + } +#endif // _di_f_thread_barriers_decimate_by_ + +#ifndef _di_f_thread_barriers_decrease_by_ + f_status_t f_thread_barriers_decrease_by(const f_array_length_t amount, f_thread_barriers_t * const barriers) { + #ifndef _di_level_0_parameter_checking_ + if (!barriers) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (barriers->size - amount > 0) { + return private_f_thread_barriers_resize(barriers->size - amount, barriers); + } + + return private_f_thread_barriers_resize(0, barriers); + } +#endif // _di_f_thread_barriers_decrease_by_ + +#ifndef _di_f_thread_barriers_increase_ + f_status_t f_thread_barriers_increase(const f_array_length_t step, f_thread_barriers_t * const barriers) { + #ifndef _di_level_0_parameter_checking_ + if (!barriers) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && barriers->used + 1 > barriers->size) { + f_array_length_t size = barriers->used + step; + + if (size > F_array_length_t_size_d) { + if (barriers->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_barriers_resize(size, barriers); + } + + return F_data_not; + } +#endif // _di_f_thread_barriers_increase_ + +#ifndef _di_f_thread_barriers_increase_by_ + f_status_t f_thread_barriers_increase_by(const f_array_length_t amount, f_thread_barriers_t * const barriers) { + #ifndef _di_level_0_parameter_checking_ + if (!barriers) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (barriers->used + amount > barriers->size) { + if (barriers->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_barriers_resize(barriers->used + amount, barriers); + } + + return F_data_not; + } +#endif // _di_f_thread_barriers_increase_by_ + +#ifndef _di_f_thread_barriers_resize_ + f_status_t f_thread_barriers_resize(const f_array_length_t length, f_thread_barriers_t * const barriers) { + #ifndef _di_level_0_parameter_checking_ + if (!barriers) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_barriers_resize(length, barriers); + } +#endif // _di_f_thread_barriers_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/barrier.h b/level_0/f_thread/c/thread/barrier.h new file mode 100644 index 0000000..524f829 --- /dev/null +++ b/level_0/f_thread/c/thread/barrier.h @@ -0,0 +1,202 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_barrier_h +#define _F_thread_barrier_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_barrier_t. + */ +#ifndef _di_f_thread_barrier_t_ + typedef pthread_barrier_t f_thread_barrier_t; + + #define f_thread_barrier_t_initialize { 0 } + + #define macro_f_thread_barrier_t_initialize(barrier) barrier + + #define macro_f_thread_barrier_t_clear(barrier) barrier = 0; + + #define macro_f_thread_barrier_t_delete_simple(barrier) f_thread_barrier_delete(&barrier); +#endif // _di_f_thread_barrier_t_ + +/** + * An array of f_thread_barrier_t. + * + * array: The array of f_thread_barrier_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_barriers_t_ + typedef struct { + f_thread_barrier_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_barriers_t; + + #define f_thread_barriers_t_initialize { 0, 0, 0 } + + #define macro_f_thread_barriers_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_barriers_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_barriers_t_clear(barriers) macro_f_memory_structure_clear(barriers) + + #define macro_f_thread_barriers_t_resize(status, barriers, length) status = f_thread_barriers_resize(length, &barriers); + #define macro_f_thread_barriers_t_adjust(status, barriers, length) status = f_thread_barriers_adjust(length, &barriers); + + #define macro_f_thread_barriers_t_delete_simple(barriers) f_thread_barriers_resize(0, &barriers); + #define macro_f_thread_barriers_t_destroy_simple(barriers) f_thread_barriers_adjust(0, &barriers); + + #define macro_f_thread_barriers_t_increase(status, step, barriers) status = f_thread_barriers_increase(step, barriers); + #define macro_f_thread_barriers_t_increase_by(status, barriers, amount) status = f_thread_barriers_increase_by(amount, barriers); + #define macro_f_thread_barriers_t_decrease_by(status, barriers, amount) status = f_thread_barriers_decrease_by(amount, barriers); + #define macro_f_thread_barriers_t_decimate_by(status, barriers, amount) status = f_thread_barriers_decimate_by(amount, barriers); +#endif // _di_f_thread_barriers_t_ + +/** + * Resize the thread barriers array. + * + * @param length + * The new size to use. + * @param barriers + * The thread barriers 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_barriers_adjust_ + extern f_status_t f_thread_barriers_adjust(const f_array_length_t length, f_thread_barriers_t * const barriers); +#endif // _di_f_thread_barriers_adjust_ + +/** + * Resize the thread barriers 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 barriers + * The thread barriers array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_barriers_decimate_by_ + extern f_status_t f_thread_barriers_decimate_by(const f_array_length_t amount, f_thread_barriers_t * const barriers); +#endif // _di_f_thread_barriers_decimate_by_ + +/** + * Resize the thread barriers 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 barriers + * The thread barriers array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_barriers_decrease_by_ + extern f_status_t f_thread_barriers_decrease_by(const f_array_length_t amount, f_thread_barriers_t * const barriers); +#endif // _di_f_thread_barriers_decrease_by_ + +/** + * Increase the size of the thread barriers 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param barriers + * The thread barriers 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_barriers_increase_ + extern f_status_t f_thread_barriers_increase(const f_array_length_t step, f_thread_barriers_t * const barriers); +#endif // _di_f_thread_barriers_increase_ + +/** + * Resize the thread barriers array to a larger size. + * + * This will resize making the array 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_d). + * 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 barriers + * The thread barriers 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_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_barriers_increase_by_ + extern f_status_t f_thread_barriers_increase_by(const f_array_length_t amount, f_thread_barriers_t * const barriers); +#endif // _di_f_thread_barriers_increase_by_ + +/** + * Resize the thread barriers array. + * + * @param length + * The new size to use. + * @param barriers + * The thread barriers 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_barriers_resize_ + extern f_status_t f_thread_barriers_resize(const f_array_length_t length, f_thread_barriers_t * const barriers); +#endif // _di_f_thread_barriers_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_barrier_h diff --git a/level_0/f_thread/c/thread/barrier_attribute.c b/level_0/f_thread/c/thread/barrier_attribute.c new file mode 100644 index 0000000..5ecebb6 --- /dev/null +++ b/level_0/f_thread/c/thread/barrier_attribute.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "barrier_attribute.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_barrier_attributes_adjust_ + f_status_t f_thread_barrier_attributes_adjust(const f_array_length_t length, f_thread_barrier_attributes_t * const 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_barrier_attributes_adjust(length, attributes); + } +#endif // _di_f_thread_barrier_attributes_adjust_ + +#ifndef _di_f_thread_barrier_attributes_decimate_by_ + f_status_t f_thread_barrier_attributes_decimate_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->size - amount > 0) { + return private_f_thread_barrier_attributes_adjust(attributes->size - amount, attributes); + } + + return private_f_thread_barrier_attributes_adjust(0, attributes); + } +#endif // _di_f_thread_barrier_attributes_decimate_by_ + +#ifndef _di_f_thread_barrier_attributes_decrease_by_ + f_status_t f_thread_barrier_attributes_decrease_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->size - amount > 0) { + return private_f_thread_barrier_attributes_resize(attributes->size - amount, attributes); + } + + return private_f_thread_barrier_attributes_resize(0, attributes); + } +#endif // _di_f_thread_barrier_attributes_decrease_by_ + +#ifndef _di_f_thread_barrier_attributes_increase_ + f_status_t f_thread_barrier_attributes_increase(const f_array_length_t step, f_thread_barrier_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && attributes->used + 1 > attributes->size) { + f_array_length_t size = attributes->used + step; + + if (size > F_array_length_t_size_d) { + if (attributes->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_barrier_attributes_resize(size, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_barrier_attributes_increase_ + +#ifndef _di_f_thread_barrier_attributes_increase_by_ + f_status_t f_thread_barrier_attributes_increase_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->used + amount > attributes->size) { + if (attributes->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_barrier_attributes_resize(attributes->used + amount, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_barrier_attributes_increase_by_ + +#ifndef _di_f_thread_barrier_attributes_resize_ + f_status_t f_thread_barrier_attributes_resize(const f_array_length_t length, f_thread_barrier_attributes_t * const 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_barrier_attributes_resize(length, attributes); + } +#endif // _di_f_thread_barrier_attributes_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/barrier_attribute.h b/level_0/f_thread/c/thread/barrier_attribute.h new file mode 100644 index 0000000..b99f40a --- /dev/null +++ b/level_0/f_thread/c/thread/barrier_attribute.h @@ -0,0 +1,203 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_barrier_attribute_h +#define _F_thread_barrier_attribute_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_barrierattr_t. + */ +#ifndef _di_f_thread_barrier_attribute_t_ + typedef pthread_barrierattr_t f_thread_barrier_attribute_t; + + #define f_thread_barrier_attribute_t_initialize { 0 } + + #define macro_f_thread_barrier_attribute_t_initialize(attribute) attribute + + // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). + #define macro_f_thread_barrier_attribute_t_clear(attribute) attribute.__align = 0; + + #define macro_f_thread_barrier_attribute_t_delete_simple(attribute) f_thread_barrier_attribute_delete(&attribute); +#endif // _di_f_thread_barrier_attribute_t_ + +/** + * An array of f_thread_barrier_attribute_t. + * + * array: The array of f_thread_barrier_attribute_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_barrier_attributes_t_ + typedef struct { + f_thread_barrier_attribute_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_barrier_attributes_t; + + #define f_thread_barrier_attributes_t_initialize { 0, 0, 0 } + + #define macro_f_thread_barrier_attributes_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_barrier_attributes_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_barrier_attributes_t_clear(barrier_attributes) macro_f_memory_structure_clear(barrier_attributes) + + #define macro_f_thread_barrier_attributes_t_resize(status, barrier_attributes, length) status = f_thread_barrier_attributes_resize(length, &barrier_attributes); + #define macro_f_thread_barrier_attributes_t_adjust(status, barrier_attributes, length) status = f_thread_barrier_attributes_adjust(length, &barrier_attributes); + + #define macro_f_thread_barrier_attributes_t_delete_simple(barrier_attributes) f_thread_barrier_attributes_resize(0, &barrier_attributes); + #define macro_f_thread_barrier_attributes_t_destroy_simple(barrier_attributes) f_thread_barrier_attributes_adjust(0, &barrier_attributes); + + #define macro_f_thread_barrier_attributes_t_increase(status, step, barrier_attributes) status = f_thread_barrier_attributes_increase(step, barrier_attributes); + #define macro_f_thread_barrier_attributes_t_increase_by(status, barrier_attributes, amount) status = f_thread_barrier_attributes_increase_by(amount, barrier_attributes); + #define macro_f_thread_barrier_attributes_t_decrease_by(status, barrier_attributes, amount) status = f_thread_barrier_attributes_decrease_by(amount, barrier_attributes); + #define macro_f_thread_barrier_attributes_t_decimate_by(status, barrier_attributes, amount) status = f_thread_barrier_attributes_decimate_by(amount, barrier_attributes); +#endif // _di_f_thread_barrier_attributes_t_ + +/** + * Resize the thread barrier attributes array. + * + * @param length + * The new size to use. + * @param attributes + * The thread 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_barrier_attributes_adjust_ + extern f_status_t f_thread_barrier_attributes_adjust(const f_array_length_t length, f_thread_barrier_attributes_t * const attributes); +#endif // _di_f_thread_barrier_attributes_adjust_ + +/** + * Resize the thread barrier 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 thread attributes array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_barrier_attributes_decimate_by_ + extern f_status_t f_thread_barrier_attributes_decimate_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes); +#endif // _di_f_thread_barrier_attributes_decimate_by_ + +/** + * Resize the thread barrier 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 thread attributes array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_barrier_attributes_decrease_by_ + extern f_status_t f_thread_barrier_attributes_decrease_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes); +#endif // _di_f_thread_barrier_attributes_decrease_by_ + +/** + * Increase the size of the thread barrier 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param attributes + * The thread 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_barrier_attributes_increase_ + extern f_status_t f_thread_barrier_attributes_increase(const f_array_length_t step, f_thread_barrier_attributes_t * const attributes); +#endif // _di_f_thread_barrier_attributes_increase_ + +/** + * Resize the thread barrier attributes array to a larger size. + * + * This will resize making the array 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_d). + * 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 thread 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_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_barrier_attributes_increase_by_ + extern f_status_t f_thread_barrier_attributes_increase_by(const f_array_length_t amount, f_thread_barrier_attributes_t * const attributes); +#endif // _di_f_thread_barrier_attributes_increase_by_ + +/** + * Resize the thread barrier attributes array. + * + * @param length + * The new size to use. + * @param attributes + * The thread 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_barrier_attributes_resize_ + extern f_status_t f_thread_barrier_attributes_resize(const f_array_length_t length, f_thread_barrier_attributes_t * const attributes); +#endif // _di_f_thread_barrier_attributes_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_barrier_attribute_h diff --git a/level_0/f_thread/c/thread/common.h b/level_0/f_thread/c/thread/common.h deleted file mode 100644 index 8e0d984..0000000 --- a/level_0/f_thread/c/thread/common.h +++ /dev/null @@ -1,771 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Thread - * API Version: 0.5 - * Licenses: lgpl-2.1-or-later - * - * Defines common data to be used for/by POSIX thread related functionality. - * - * This is auto-included by thread.h and should not need to be explicitly included. - */ -#ifndef _F_thread_common_h -#define _F_thread_common_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * A typedef representing pthread_attr_t. - */ -#ifndef _di_f_thread_attribute_t_ - typedef pthread_attr_t f_thread_attribute_t; - - #define f_thread_attribute_t_initialize { 0 } - - #define macro_f_thread_attribute_t_initialize(attribute) attribute - - // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). - #define macro_f_thread_attribute_t_clear(attribute) attribute.__align = 0; - - #define macro_f_thread_attribute_t_delete_simple(attribute) f_thread_attribute_delete(&attribute); -#endif // _di_f_thread_attribute_t_ - -/** - * An array of f_thread_attribute_t. - * - * array: The array of f_thread_attribute_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_attributes_t_ - typedef struct { - f_thread_attribute_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_attributes_t; - - #define f_thread_attributes_t_initialize { 0, 0, 0 } - - #define macro_f_thread_attributes_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_attributes_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_attributes_t_clear(attributes) macro_f_memory_structure_clear(attributes) - - #define macro_f_thread_attributes_t_resize(status, attributes, length) status = f_thread_attributes_resize(length, &attributes); - #define macro_f_thread_attributes_t_adjust(status, attributes, length) status = f_thread_attributes_adjust(length, &attributes); - - #define macro_f_thread_attributes_t_delete_simple(attributes) f_thread_attributes_resize(0, &attributes); - #define macro_f_thread_attributes_t_destroy_simple(attributes) f_thread_attributes_adjust(0, &attributes); - - #define macro_f_thread_attributes_t_increase(status, step, attributes) status = f_thread_attributes_increase(step, attributes); - #define macro_f_thread_attributes_t_increase_by(status, attributes, amount) status = f_thread_attributes_increase_by(amount, attributes); - #define macro_f_thread_attributes_t_decrease_by(status, attributes, amount) status = f_thread_attributes_decrease_by(amount, attributes); - #define macro_f_thread_attributes_t_decimate_by(status, attributes, amount) status = f_thread_attributes_decimate_by(amount, attributes); -#endif // _di_f_thread_attributes_t_ - -/** - * A typedef representing pthread_barrier_t. - */ -#ifndef _di_f_thread_barrier_t_ - typedef pthread_barrier_t f_thread_barrier_t; - - #define f_thread_barrier_t_initialize { 0 } - - #define macro_f_thread_barrier_t_initialize(barrier) barrier - - #define macro_f_thread_barrier_t_clear(barrier) barrier = 0; - - #define macro_f_thread_barrier_t_delete_simple(barrier) f_thread_barrier_delete(&barrier); -#endif // _di_f_thread_barrier_t_ - -/** - * An array of f_thread_barrier_t. - * - * array: The array of f_thread_barrier_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_barriers_t_ - typedef struct { - f_thread_barrier_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_barriers_t; - - #define f_thread_barriers_t_initialize { 0, 0, 0 } - - #define macro_f_thread_barriers_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_barriers_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_barriers_t_clear(barriers) macro_f_memory_structure_clear(barriers) - - #define macro_f_thread_barriers_t_resize(status, barriers, length) status = f_thread_barriers_resize(length, &barriers); - #define macro_f_thread_barriers_t_adjust(status, barriers, length) status = f_thread_barriers_adjust(length, &barriers); - - #define macro_f_thread_barriers_t_delete_simple(barriers) f_thread_barriers_resize(0, &barriers); - #define macro_f_thread_barriers_t_destroy_simple(barriers) f_thread_barriers_adjust(0, &barriers); - - #define macro_f_thread_barriers_t_increase(status, step, barriers) status = f_thread_barriers_increase(step, barriers); - #define macro_f_thread_barriers_t_increase_by(status, barriers, amount) status = f_thread_barriers_increase_by(amount, barriers); - #define macro_f_thread_barriers_t_decrease_by(status, barriers, amount) status = f_thread_barriers_decrease_by(amount, barriers); - #define macro_f_thread_barriers_t_decimate_by(status, barriers, amount) status = f_thread_barriers_decimate_by(amount, barriers); -#endif // _di_f_thread_barriers_t_ - -/** - * A typedef representing pthread_barrierattr_t. - */ -#ifndef _di_f_thread_barrier_attribute_t_ - typedef pthread_barrierattr_t f_thread_barrier_attribute_t; - - #define f_thread_barrier_attribute_t_initialize { 0 } - - #define macro_f_thread_barrier_attribute_t_initialize(attribute) attribute - - // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). - #define macro_f_thread_barrier_attribute_t_clear(attribute) attribute.__align = 0; - - #define macro_f_thread_barrier_attribute_t_delete_simple(attribute) f_thread_barrier_attribute_delete(&attribute); -#endif // _di_f_thread_barrier_attribute_t_ - -/** - * An array of f_thread_barrier_attribute_t. - * - * array: The array of f_thread_barrier_attribute_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_barrier_attributes_t_ - typedef struct { - f_thread_barrier_attribute_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_barrier_attributes_t; - - #define f_thread_barrier_attributes_t_initialize { 0, 0, 0 } - - #define macro_f_thread_barrier_attributes_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_barrier_attributes_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_barrier_attributes_t_clear(barrier_attributes) macro_f_memory_structure_clear(barrier_attributes) - - #define macro_f_thread_barrier_attributes_t_resize(status, barrier_attributes, length) status = f_thread_barrier_attributes_resize(length, &barrier_attributes); - #define macro_f_thread_barrier_attributes_t_adjust(status, barrier_attributes, length) status = f_thread_barrier_attributes_adjust(length, &barrier_attributes); - - #define macro_f_thread_barrier_attributes_t_delete_simple(barrier_attributes) f_thread_barrier_attributes_resize(0, &barrier_attributes); - #define macro_f_thread_barrier_attributes_t_destroy_simple(barrier_attributes) f_thread_barrier_attributes_adjust(0, &barrier_attributes); - - #define macro_f_thread_barrier_attributes_t_increase(status, step, barrier_attributes) status = f_thread_barrier_attributes_increase(step, barrier_attributes); - #define macro_f_thread_barrier_attributes_t_increase_by(status, barrier_attributes, amount) status = f_thread_barrier_attributes_increase_by(amount, barrier_attributes); - #define macro_f_thread_barrier_attributes_t_decrease_by(status, barrier_attributes, amount) status = f_thread_barrier_attributes_decrease_by(amount, barrier_attributes); - #define macro_f_thread_barrier_attributes_t_decimate_by(status, barrier_attributes, amount) status = f_thread_barrier_attributes_decimate_by(amount, barrier_attributes); -#endif // _di_f_thread_barrier_attributes_t_ - -/** - * A typedef representing pthread_cond_t. - * - * This must be dynamically initialized using f_thread_condition_create(). - * In some cases, they can be utilized statically, in which case only f_thread_condition_t_initialize is needed. - */ -#ifndef _di_f_thread_condition_t_ - typedef pthread_cond_t f_thread_condition_t; - - #define f_thread_condition_t_initialize PTHREAD_COND_INITIALIZER - - #define macro_f_thread_condition_t_initialize(condition) { condition } - - #define macro_f_thread_condition_t_delete_simple(condition) f_thread_condition_delete(&condition); -#endif // _di_f_thread_condition_t_ - -/** - * An array of thread conditions. - * - * array: The array of f_thread_condition_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_conditions_t_ - typedef struct { - f_thread_condition_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_conditions_t; - - #define f_thread_conditions_t_initialize { 0, 0, 0 } - - #define macro_f_thread_conditions_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_conditions_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_conditions_t_clear(conditions) macro_f_memory_structure_clear(conditions) - - #define macro_f_thread_conditions_t_resize(status, conditions, length) status = f_thread_conditions_resize(length, &conditions); - #define macro_f_thread_conditions_t_adjust(status, conditions, length) status = f_thread_conditions_adjust(length, &conditions); - - #define macro_f_thread_conditions_t_delete_simple(conditions) f_thread_conditions_resize(0, &conditions); - #define macro_f_thread_conditions_t_destroy_simple(conditions) f_thread_conditions_adjust(0, &conditions); - - #define macro_f_thread_conditions_t_increase(status, step, conditions) status = f_thread_conditions_increase(step, conditions); - #define macro_f_thread_conditions_t_increase_by(status, conditions, amount) status = f_thread_conditions_increase_by(amount, conditions); - #define macro_f_thread_conditions_t_decrease_by(status, conditions, amount) status = f_thread_conditions_decrease_by(amount, conditions); - #define macro_f_thread_conditions_t_decimate_by(status, conditions, amount) status = f_thread_conditions_decimate_by(amount, conditions); -#endif // _di_f_thread_conditions_t_ - -/** - * A typedef representing pthread_cond_t. - */ -#ifndef _di_f_thread_condition_attribute_t_ - typedef pthread_condattr_t f_thread_condition_attribute_t; - - #define f_thread_condition_attribute_t_initialize { 0 }; - - #define macro_f_thread_condition_attribute_t_initialize(array, size, used) attribute - - // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). - #define macro_f_thread_condition_attribute_t_clear(attribute) attribute.__align = 0; - - #define macro_f_thread_condition_attribute_t_delete_simple(attribute) f_thread_condition_attribute_delete(&attribute); -#endif // _di_f_thread_condition_attribute_t_ - -/** - * An array of thread condition attributes. - * - * array: The array of f_thread_condition_attribute_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_condition_attributes_t_ - typedef struct { - f_thread_condition_attribute_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_condition_attributes_t; - - #define f_thread_condition_attributes_t_initialize { 0, 0, 0 } - - #define macro_f_thread_condition_attributes_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_condition_attributes_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_condition_attributes_t_clear(attributes) macro_f_memory_structure_clear(attributes) - - #define macro_f_thread_condition_attributes_t_resize(status, attributes, length) status = f_thread_condition_attributes_resize(length, &attributes); - #define macro_f_thread_condition_attributes_t_adjust(status, attributes, length) status = f_thread_condition_attributes_adjust(length, &attributes); - - #define macro_f_thread_condition_attributes_t_delete_simple(attributes) f_thread_condition_attributes_resize(0, &condition_attributes); - #define macro_f_thread_condition_attributes_t_destroy_simple(attributes) f_thread_condition_attributes_adjust(0, &condition_attributes); - - #define macro_f_thread_condition_attributes_t_increase(status, step, attributes) status = f_thread_condition_attributes_increase(step, attributes); - #define macro_f_thread_condition_attributes_t_increase_by(status, attributes, amount) status = f_thread_condition_attributes_increase_by(amount, attributes); - #define macro_f_thread_condition_attributes_t_decrease_by(status, attributes, amount) status = f_thread_condition_attributes_decrease_by(amount, attributes); - #define macro_f_thread_condition_attributes_t_decimate_by(status, attributes, amount) status = f_thread_condition_attributes_decimate_by(amount, attributes); -#endif // _di_f_thread_condition_attributes_t_ - -/** - * A typedef representing pthread_t. - */ -#ifndef _di_f_thread_id_t_ - typedef pthread_t f_thread_id_t; - - #define f_thread_id_t_initialize 0 - - #define macro_f_thread_id_t_clear(id) id = 0; -#endif // _di_f_thread_id_t_ - -/** - * An array of thread IDs. - * - * array: The array of f_thread_id_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_ids_t_ - typedef struct { - f_thread_id_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_ids_t; - - #define f_thread_ids_t_initialize { 0, 0, 0 } - - #define macro_f_thread_ids_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_ids_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_ids_t_resize(status, ids, length) macro_f_memory_structure_resize(status, ids, f_thread_id_t, length) - #define macro_f_thread_ids_t_adjust(status, ids, length) macro_f_memory_structure_adjust(status, ids, f_thread_id_t, length) - - #define macro_f_thread_ids_t_delete_simple(ids) macro_f_memory_structure_delete_simple(ids, f_thread_id_t) - #define macro_f_thread_ids_t_destroy_simple(ids) macro_f_memory_structure_destroy_simple(ids, f_thread_id_t) - - #define macro_f_thread_ids_t_increase(status, step, ids) macro_f_memory_structure_increase(status, step, ids, f_thread_id_t) - #define macro_f_thread_ids_t_increase_by(status, ids, amount) macro_f_memory_structure_increase_by(status, ids, f_thread_id_t, amount) - #define macro_f_thread_ids_t_decrease_by(status, ids, amount) macro_f_memory_structure_decrease_by(status, ids, f_thread_id_t, amount) - #define macro_f_thread_ids_t_decimate_by(status, ids, amount) macro_f_memory_structure_decimate_by(status, ids, f_thread_id_t, amount) -#endif // _di_f_thread_ids_t_ - -/** - * A typedef representing pthread_key_t. - */ -#ifndef _di_f_thread_key_t_ - typedef pthread_key_t f_thread_key_t; - - #define f_thread_key_t_initialize 0 - - #define macro_f_thread_key_t_initialize(key) key - - #define macro_f_thread_key_t_clear(key) key = 0; - - #define macro_f_thread_key_t_delete_simple(key) f_thread_key_delete(&key); -#endif // _di_f_thread_key_t_ - -/** - * An array of thread keys. - * - * array: The array of f_thread_key_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_keys_t_ - typedef struct { - f_thread_key_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_keys_t; - - #define f_thread_keys_t_initialize { 0, 0, 0 } - - #define macro_f_thread_keys_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_keys_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_keys_t_clear(keys) macro_f_memory_structure_clear(keys) - - #define macro_f_thread_keys_t_resize(status, keys, length) status = f_thread_keys_resize(length, &keys); - #define macro_f_thread_keys_t_adjust(status, keys, length) status = f_thread_keys_adjust(length, &keys); - - #define macro_f_thread_keys_t_delete_simple(keys) f_thread_keys_resize(0, &keys); - #define macro_f_thread_keys_t_destroy_simple(keys) f_thread_keys_adjust(0, &keys); - - #define macro_f_thread_keys_t_increase(status, step, keys) status = f_thread_keys_increase(step, keys); - #define macro_f_thread_keys_t_increase_by(status, keys, amount) status = f_thread_keys_increase_by(amount, keys); - #define macro_f_thread_keys_t_decrease_by(status, keys, amount) status = f_thread_keys_decrease_by(amount, keys); - #define macro_f_thread_keys_t_decimate_by(status, keys, amount) status = f_thread_keys_decimate_by(amount, keys); -#endif // _di_f_thread_keys_t_ - -/** - * A typedef representing pthread_rwlock_t (read/write lock). - * - * This must be dynamically initialized using f_thread_lock_create(). - * In some cases, they can be utilized statically, in which case only f_thread_lock_t_initialize is needed. - */ -#ifndef _di_f_thread_lock_t_ - typedef pthread_rwlock_t f_thread_lock_t; - - #define f_thread_lock_t_initialize PTHREAD_RWLOCK_INITIALIZER - - #define macro_f_thread_lock_t_initialize(lock) lock - - #define macro_f_thread_lock_t_delete_simple(lock) f_thread_lock_delete(&lock); -#endif // _di_f_thread_lock_t_ - -/** - * An array of thread locks. - * - * array: The array of f_thread_lock_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_locks_t_ - typedef struct { - f_thread_lock_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_locks_t; - - #define f_thread_locks_t_initialize { 0, 0, 0 } - - #define macro_f_thread_locks_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_locks_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_locks_t_resize(status, locks, length) macro_f_memory_structure_resize(status, locks, f_thread_lock_t, length) - #define macro_f_thread_locks_t_adjust(status, locks, length) macro_f_memory_structure_adjust(status, locks, f_thread_lock_t, length) - - #define macro_f_thread_locks_t_delete_simple(locks) macro_f_memory_structure_delete_simple(locks, f_thread_lock_t) - #define macro_f_thread_locks_t_destroy_simple(locks) macro_f_memory_structure_destroy_simple(locks, f_thread_lock_t) - - #define macro_f_thread_locks_t_increase(status, step, locks) macro_f_memory_structure_increase(status, step, locks, f_thread_lock_t) - #define macro_f_thread_locks_t_increase_by(status, locks, amount) macro_f_memory_structure_increase_by(status, locks, f_thread_lock_t, amount) - #define macro_f_thread_locks_t_decrease_by(status, locks, amount) macro_f_memory_structure_decrease_by(status, locks, f_thread_lock_t, amount) - #define macro_f_thread_locks_t_decimate_by(status, locks, amount) macro_f_memory_structure_decimate_by(status, locks, f_thread_lock_t, amount) -#endif // _di_f_thread_locks_t_ - -/** - * A typedef representing pthread_rwlockattr_t. - */ -#ifndef _di_f_thread_lock_attribute_t_ - typedef pthread_rwlockattr_t f_thread_lock_attribute_t; - - #define f_thread_lock_attribute_t_initialize { 0 } - - #define macro_f_thread_lock_attribute_t_initialize(attribute) attribute - - // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). - #define macro_f_thread_lock_attribute_t_clear(attribute) attribute.__align = 0; - - #define macro_f_thread_lock_attribute_t_delete_simple(attribute) f_thread_lock_attribute_delete(&attribute); -#endif // _di_f_thread_lock_attribute_t_ - -/** - * An array of read/write lock attributees. - * - * array: The array of f_thread_lock_attribute_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_lock_attributes_t_ - typedef struct { - f_thread_lock_attribute_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_lock_attributes_t; - - #define f_thread_lock_attributes_t_initialize { 0, 0, 0 } - - #define macro_f_thread_lock_attributes_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_lock_attributes_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_lock_attributes_t_clear(attributes) macro_f_memory_structure_clear(attributes) - - #define macro_f_thread_lock_attributes_t_resize(status, attributes, length) status = f_thread_lock_attributes_resize(length, &attributes); - #define macro_f_thread_lock_attributes_t_adjust(status, attributes, length) status = f_thread_lock_attributes_adjust(length, &attributes); - - #define macro_f_thread_lock_attributes_t_delete_simple(attributes) f_thread_lock_attributes_resize(0, &attributes); - #define macro_f_thread_lock_attributes_t_destroy_simple(attributes) f_thread_lock_attributes_adjust(0, &attributes); - - #define macro_f_thread_lock_attributes_t_increase(status, step, attributes) status = f_thread_lock_attributes_increase(step, attributes); - #define macro_f_thread_lock_attributes_t_increase_by(status, attributes, amount) status = f_thread_lock_attributes_increase_by(amount, attributes); - #define macro_f_thread_lock_attributes_t_decrease_by(status, attributes, amount) status = f_thread_lock_attributes_decrease_by(amount, attributes); - #define macro_f_thread_lock_attributes_t_decimate_by(status, attributes, amount) status = f_thread_lock_attributes_decimate_by(amount, attributes); -#endif // _di_f_thread_lock_attributes_t_ - -/** - * A typedef representing pthread_mutex_t. - * - * This variable cannot be cleared by setting value to 0, so there is no clear macro provided. - * - * This must be dynamically initialized using f_thread_mutex_create(). - * In some cases, they can be utilized statically, in which case only f_thread_mutex_t_initialize is needed. - */ -#ifndef _di_f_thread_mutex_t_ - typedef pthread_mutex_t f_thread_mutex_t; - - #define f_thread_mutex_t_initialize PTHREAD_MUTEX_INITIALIZER - - #define macro_f_thread_mutex_t_initialize(mutex) mutex - - #define macro_f_thread_mutex_t_delete_simple(mutex) f_thread_mutex_delete(&mutex); -#endif // _di_f_thread_mutex_t_ - -/** - * An array of thread mutexes. - * - * array: The array of f_thread_mutex_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_mutexs_t_ - typedef struct { - f_thread_mutex_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_mutexs_t; - - #define f_thread_mutexs_t_initialize { 0, 0, 0 } - - #define macro_f_thread_mutexs_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_mutexs_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_mutexs_t_clear(mutexs) macro_f_memory_structure_clear(mutexs) - - #define macro_f_thread_mutexs_t_resize(status, mutexs, length) status = f_thread_mutexs_resize(length, &mutexs); - #define macro_f_thread_mutexs_t_adjust(status, mutexs, length) status = f_thread_mutexs_adjust(length, &mutexs); - - #define macro_f_thread_mutexs_t_delete_simple(mutexs) f_thread_mutexs_resize(0, &mutexs); - #define macro_f_thread_mutexs_t_destroy_simple(mutexs) f_thread_mutexs_adjust(0, &mutexs); - - #define macro_f_thread_mutexs_t_increase(status, step, mutexs) status = f_thread_mutexs_increase(step, mutexs); - #define macro_f_thread_mutexs_t_increase_by(status, mutexs, amount) status = f_thread_mutexs_increase_by(amount, mutexs); - #define macro_f_thread_mutexs_t_decrease_by(status, mutexs, amount) status = f_thread_mutexs_decrease_by(amount, mutexs); - #define macro_f_thread_mutexs_t_decimate_by(status, mutexs, amount) status = f_thread_mutexs_decimate_by(amount, mutexs); -#endif // _di_f_thread_mutexs_t_ - -/** - * A typedef representing pthread_mutex_attribute_t. - */ -#ifndef _di_f_thread_mutex_attribute_t_ - typedef pthread_mutexattr_t f_thread_mutex_attribute_t; - - #define f_thread_mutex_attribute_t_initialize { 0 } - - #define macro_f_thread_mutex_attribute_t_initialize(attribute) attribute - - // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). - #define macro_f_thread_mutex_attribute_t_clear(attribute) attribute.__align = 0; - - #define macro_f_thread_mutex_attribute_t_delete_simple(attribute) f_thread_mutex_attribute_delete(&attribute); -#endif // _di_f_thread_mutex_attribute_t_ - -/** - * An array of thread mutex_attributees. - * - * array: The array of f_thread_mutex_attribute_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_mutex_attributes_t_ - typedef struct { - f_thread_mutex_attribute_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_mutex_attributes_t; - - #define f_thread_mutex_attributes_t_initialize { 0, 0, 0 } - - #define macro_f_thread_mutex_attributes_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_mutex_attributes_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_mutex_attributes_t_clear(attributes) macro_f_memory_structure_clear(attributes) - - #define macro_f_thread_mutex_attributes_t_resize(status, attributes, length) status = f_thread_mutex_attributes_resize(length, &attributes); - #define macro_f_thread_mutex_attributes_t_adjust(status, attributes, length) status = f_thread_mutex_attributes_adjust(length, &attributes); - - #define macro_f_thread_mutex_attributes_t_delete_simple(attributes) f_thread_mutex_attributes_resize(0, &attributes); - #define macro_f_thread_mutex_attributes_t_destroy_simple(attributes) f_thread_mutex_attributes_adjust(0, &attributes); - - #define macro_f_thread_mutex_attributes_t_increase(status, step, attributes) status = f_thread_mutex_attributes_increase(step, attributes); - #define macro_f_thread_mutex_attributes_t_increase_by(status, attributes, amount) status = f_thread_mutex_attributes_increase_by(amount, attributes); - #define macro_f_thread_mutex_attributes_t_decrease_by(status, attributes, amount) status = f_thread_mutex_attributes_decrease_by(amount, attributes); - #define macro_f_thread_mutex_attributes_t_decimate_by(status, attributes, amount) status = f_thread_mutex_attributes_decimate_by(amount, attributes); -#endif // _di_f_thread_mutex_attributes_t_ - -/** - * A typedef representing pthread_once_t. - * - * There are no delete functions and therefore no delete macros. - */ -#ifndef _di_f_thread_once_t_ - typedef pthread_once_t f_thread_once_t; - - #define f_thread_once_t_initialize PTHREAD_ONCE_INIT - - #define macro_f_thread_once_t_initialize(once) once -#endif // _di_f_thread_once_t_ - -/** - * An array of thread onces. - * - * array: The array of f_thread_once_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_onces_t_ - typedef struct { - f_thread_once_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_onces_t; - - #define f_thread_onces_t_initialize { 0, 0, 0 } - - #define macro_f_thread_onces_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_onces_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_onces_t_clear(onces) macro_f_memory_structure_clear(onces) - - #define macro_f_thread_onces_t_resize(status, onces, length) macro_f_memory_structure_resize(status, onces, f_thread_once_t, length) - #define macro_f_thread_onces_t_adjust(status, onces, length) macro_f_memory_structure_adjust(status, onces, f_thread_once_t, length) - - #define macro_f_thread_onces_t_delete_simple(onces) macro_f_memory_structure_delete_simple(onces, f_thread_once_t) - #define macro_f_thread_onces_t_destroy_simple(onces) macro_f_memory_structure_destroy_simple(onces, f_thread_once_t) - - #define macro_f_thread_onces_t_increase(status, step, onces) macro_f_memory_structure_increase(status, step, onces, f_thread_once_t) - #define macro_f_thread_onces_t_increase_by(status, onces, amount) macro_f_memory_structure_increase_by(status, onces, f_thread_once_t, amount) - #define macro_f_thread_onces_t_decrease_by(status, onces, amount) macro_f_memory_structure_decrease_by(status, onces, f_thread_once_t, amount) - #define macro_f_thread_onces_t_decimate_by(status, onces, amount) macro_f_memory_structure_decimate_by(status, onces, f_thread_once_t, amount) -#endif // _di_f_thread_onces_t_ - -/** - * A typedef representing sem_t. - * - * This variable cannot be cleared by setting value to 0, so there is no clear macro provided. - * - * This must be dynamically initialized using f_thread_semaphore_create(). - */ -#ifndef _di_f_thread_semaphore_t_ - typedef sem_t f_thread_semaphore_t; - - #define f_thread_semaphore_t_initialize 0 - - #define macro_f_thread_semaphore_t_initialize(semaphore) semaphore - - #define macro_f_thread_semaphore_t_delete_simple(semaphore) f_thread_semaphore_delete(&semaphore); -#endif // _di_f_thread_semaphore_t_ - -/** - * An array of thread semaphorees. - * - * array: The array of f_thread_semaphore_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_semaphores_t_ - typedef struct { - f_thread_semaphore_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_semaphores_t; - - #define f_thread_semaphores_t_initialize { 0, 0, 0 } - - #define macro_f_thread_semaphores_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_semaphores_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_semaphores_t_clear(semaphores) macro_f_memory_structure_clear(semaphores) - - #define macro_f_thread_semaphores_t_resize(status, semaphores, length) status = f_thread_semaphores_resize(length, &semaphores); - #define macro_f_thread_semaphores_t_adjust(status, semaphores, length) status = f_thread_semaphores_adjust(length, &semaphores); - - #define macro_f_thread_semaphores_t_delete_simple(semaphores) f_thread_semaphores_resize(0, &semaphores); - #define macro_f_thread_semaphores_t_destroy_simple(semaphores) f_thread_semaphores_adjust(0, &semaphores); - - #define macro_f_thread_semaphores_t_increase(status, step, semaphores) status = f_thread_semaphores_increase(step, semaphores); - #define macro_f_thread_semaphores_t_increase_by(status, semaphores, amount) status = f_thread_semaphores_increase_by(amount, semaphores); - #define macro_f_thread_semaphores_t_decrease_by(status, semaphores, amount) status = f_thread_semaphores_decrease_by(amount, semaphores); - #define macro_f_thread_semaphores_t_decimate_by(status, semaphores, amount) status = f_thread_semaphores_decimate_by(amount, semaphores); -#endif // _di_f_thread_semaphores_t_ - -/** - * A structure containing basic thread information. - * - * 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 attribute; - f_thread_id_t id; - int result; - } f_thread_set_t; - - #define f_thread_set_t_initialize { f_thread_attribute_t_initialize, f_thread_id_t_initialize, 0 } - - #define macro_f_thread_set_t_initialize(attribute, id, result) { attribute, id, result } - - #define macro_f_thread_set_t_clear(thread) \ - macro_f_thread_attribute_t_clear(thread.attribute) \ - macro_f_thread_id_t_clear(thread.id) \ - result = 0; - - #define macro_f_thread_set_t_delete_simple(set) macro_f_thread_attribute_t_delete_simple(set.attribute) -#endif // _di_f_thread_set_t_ - -/** - * An array of f_thread_set_t. - * - * array: The array of f_thread_set_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_sets_t_ - typedef struct { - f_thread_set_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_sets_t; - - #define f_thread_sets_t_initialize { 0, 0, 0 } - - #define macro_f_thread_sets_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_sets_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_sets_t_clear(sets) macro_f_memory_structure_clear(sets) - - #define macro_f_thread_sets_t_resize(status, sets, length) status = f_thread_sets_resize(length, &sets); - #define macro_f_thread_sets_t_adjust(status, sets, length) status = f_thread_sets_adjust(length, &sets); - - #define macro_f_thread_sets_t_delete_simple(sets) f_thread_sets_resize(0, &sets); - #define macro_f_thread_sets_t_destroy_simple(sets) f_thread_sets_adjust(0, &sets); - - #define macro_f_thread_sets_t_increase(status, step, sets) status = f_thread_sets_increase(step, sets); - #define macro_f_thread_sets_t_increase_by(status, sets, amount) status = f_thread_sets_increase_by(amount, sets); - #define macro_f_thread_sets_t_decrease_by(status, sets, amount) status = f_thread_sets_decrease_by(amount, sets); - #define macro_f_thread_sets_t_decimate_by(status, sets, amount) status = f_thread_sets_decimate_by(amount, sets); -#endif // _di_f_thread_sets_t_ - -/** - * A typedef representing pthread_spinlock_t. - * - * Note: There appears to be no pthread init macro for spinlock, so initialize manually similarly to how the other inits work. - */ -#ifndef _di_f_thread_spin_t_ - typedef pthread_spinlock_t f_thread_spin_t; - - #define f_thread_spin_t_initialize ((pthread_spinlock_t) 0xFFFFFFFF) - - #define macro_f_thread_spin_t_initialize(spin) spin - - #define macro_f_thread_spin_t_delete_simple(spin) f_thread_spin_delete(&spin); -#endif // _di_f_thread_spin_t_ - -/** - * An array of thread spins. - * - * array: The array of f_thread_spin_t. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_thread_spins_t_ - typedef struct { - f_thread_spin_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_thread_spins_t; - - #define f_thread_spins_t_initialize { 0, 0, 0 } - - #define macro_f_thread_spins_t_initialize(array, size, used) { array, size, used } - #define macro_f_thread_spins_t_initialize2(array, length) { array, length, length } - - #define macro_f_thread_spins_t_clear(spins) macro_f_memory_structure_clear(spins) - - #define macro_f_thread_spins_t_resize(status, spins, length) status = f_thread_spins_resize(length, &spins); - #define macro_f_thread_spins_t_adjust(status, spins, length) status = f_thread_spins_adjust(length, &spins); - - #define macro_f_thread_spins_t_delete_simple(spins) f_thread_spins_resize(0, &spins); - #define macro_f_thread_spins_t_destroy_simple(spins) f_thread_spins_adjust(0, &spins); - - #define macro_f_thread_spins_t_increase(status, step, spins) status = f_thread_spins_increase(step, spins); - #define macro_f_thread_spins_t_increase_by(status, spins, amount) status = f_thread_spins_increase_by(amount, spins); - #define macro_f_thread_spins_t_decrease_by(status, spins, amount) status = f_thread_spins_decrease_by(amount, spins); - #define macro_f_thread_spins_t_decimate_by(status, spins, amount) status = f_thread_spins_decimate_by(amount, spins); -#endif // _di_f_thread_spins_t_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _F_thread_common_h diff --git a/level_0/f_thread/c/thread/condition.c b/level_0/f_thread/c/thread/condition.c new file mode 100644 index 0000000..9c3631f --- /dev/null +++ b/level_0/f_thread/c/thread/condition.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "condition.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_conditions_adjust_ + f_status_t f_thread_conditions_adjust(const f_array_length_t length, f_thread_conditions_t * const conditions) { + #ifndef _di_level_0_parameter_checking_ + if (!conditions) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_conditions_adjust(length, conditions); + } +#endif // _di_f_thread_conditions_adjust_ + +#ifndef _di_f_thread_conditions_decimate_by_ + f_status_t f_thread_conditions_decimate_by(const f_array_length_t amount, f_thread_conditions_t * const conditions) { + #ifndef _di_level_0_parameter_checking_ + if (!conditions) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (conditions->size - amount > 0) { + return private_f_thread_conditions_adjust(conditions->size - amount, conditions); + } + + return private_f_thread_conditions_adjust(0, conditions); + } +#endif // _di_f_thread_conditions_decimate_by_ + +#ifndef _di_f_thread_conditions_decrease_by_ + f_status_t f_thread_conditions_decrease_by(const f_array_length_t amount, f_thread_conditions_t * const conditions) { + #ifndef _di_level_0_parameter_checking_ + if (!conditions) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (conditions->size - amount > 0) { + return private_f_thread_conditions_resize(conditions->size - amount, conditions); + } + + return private_f_thread_conditions_resize(0, conditions); + } +#endif // _di_f_thread_conditions_decrease_by_ + +#ifndef _di_f_thread_conditions_increase_ + f_status_t f_thread_conditions_increase(const f_array_length_t step, f_thread_conditions_t * const conditions) { + #ifndef _di_level_0_parameter_checking_ + if (!conditions) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && conditions->used + 1 > conditions->size) { + f_array_length_t size = conditions->used + step; + + if (size > F_array_length_t_size_d) { + if (conditions->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_conditions_resize(size, conditions); + } + + return F_data_not; + } +#endif // _di_f_thread_conditions_increase_ + +#ifndef _di_f_thread_conditions_increase_by_ + f_status_t f_thread_conditions_increase_by(const f_array_length_t amount, f_thread_conditions_t * const conditions) { + #ifndef _di_level_0_parameter_checking_ + if (!conditions) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (conditions->used + amount > conditions->size) { + if (conditions->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_conditions_resize(conditions->used + amount, conditions); + } + + return F_data_not; + } +#endif // _di_f_thread_conditions_increase_by_ + +#ifndef _di_f_thread_conditions_resize_ + f_status_t f_thread_conditions_resize(const f_array_length_t length, f_thread_conditions_t * const conditions) { + #ifndef _di_level_0_parameter_checking_ + if (!conditions) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_conditions_resize(length, conditions); + } +#endif // _di_f_thread_conditions_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/condition.h b/level_0/f_thread/c/thread/condition.h new file mode 100644 index 0000000..fba0360 --- /dev/null +++ b/level_0/f_thread/c/thread/condition.h @@ -0,0 +1,203 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_condition_h +#define _F_thread_condition_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_cond_t. + * + * This must be dynamically initialized using f_thread_condition_create(). + * In some cases, they can be utilized statically, in which case only f_thread_condition_t_initialize is needed. + */ +#ifndef _di_f_thread_condition_t_ + typedef pthread_cond_t f_thread_condition_t; + + #define f_thread_condition_t_initialize PTHREAD_COND_INITIALIZER + + #define macro_f_thread_condition_t_initialize(condition) { condition } + + #define macro_f_thread_condition_t_delete_simple(condition) f_thread_condition_delete(&condition); +#endif // _di_f_thread_condition_t_ + +/** + * An array of thread conditions. + * + * array: The array of f_thread_condition_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_conditions_t_ + typedef struct { + f_thread_condition_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_conditions_t; + + #define f_thread_conditions_t_initialize { 0, 0, 0 } + + #define macro_f_thread_conditions_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_conditions_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_conditions_t_clear(conditions) macro_f_memory_structure_clear(conditions) + + #define macro_f_thread_conditions_t_resize(status, conditions, length) status = f_thread_conditions_resize(length, &conditions); + #define macro_f_thread_conditions_t_adjust(status, conditions, length) status = f_thread_conditions_adjust(length, &conditions); + + #define macro_f_thread_conditions_t_delete_simple(conditions) f_thread_conditions_resize(0, &conditions); + #define macro_f_thread_conditions_t_destroy_simple(conditions) f_thread_conditions_adjust(0, &conditions); + + #define macro_f_thread_conditions_t_increase(status, step, conditions) status = f_thread_conditions_increase(step, conditions); + #define macro_f_thread_conditions_t_increase_by(status, conditions, amount) status = f_thread_conditions_increase_by(amount, conditions); + #define macro_f_thread_conditions_t_decrease_by(status, conditions, amount) status = f_thread_conditions_decrease_by(amount, conditions); + #define macro_f_thread_conditions_t_decimate_by(status, conditions, amount) status = f_thread_conditions_decimate_by(amount, conditions); +#endif // _di_f_thread_conditions_t_ + +/** + * Resize the thread conditions array. + * + * @param length + * The new size to use. + * @param conditions + * The string conditions 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_conditions_adjust_ + extern f_status_t f_thread_conditions_adjust(const f_array_length_t length, f_thread_conditions_t * const conditions); +#endif // _di_f_thread_conditions_adjust_ + +/** + * Resize the thread conditions 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 conditions + * The string conditions array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_conditions_decimate_by_ + extern f_status_t f_thread_conditions_decimate_by(const f_array_length_t amount, f_thread_conditions_t * const conditions); +#endif // _di_f_thread_conditions_decimate_by_ + +/** + * Resize the thread conditions 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 conditions + * The string conditions array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_conditions_decrease_by_ + extern f_status_t f_thread_conditions_decrease_by(const f_array_length_t amount, f_thread_conditions_t * const conditions); +#endif // _di_f_thread_conditions_decrease_by_ + +/** + * Increase the size of the thread conditions 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param conditions + * The string conditions 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_conditions_increase_ + extern f_status_t f_thread_conditions_increase(const f_array_length_t step, f_thread_conditions_t * const conditions); +#endif // _di_f_thread_conditions_increase_ + +/** + * Resize the thread conditions array to a larger size. + * + * This will resize making the array 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_d). + * 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 conditions + * The string conditions 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_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_conditions_increase_by_ + extern f_status_t f_thread_conditions_increase_by(const f_array_length_t amount, f_thread_conditions_t * const conditions); +#endif // _di_f_thread_conditions_increase_by_ + +/** + * Resize the thread conditions array. + * + * @param length + * The new size to use. + * @param conditions + * The string conditions 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_conditions_resize_ + extern f_status_t f_thread_conditions_resize(const f_array_length_t length, f_thread_conditions_t * const conditions); +#endif // _di_f_thread_conditions_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_condition_h diff --git a/level_0/f_thread/c/thread/condition_attribute.c b/level_0/f_thread/c/thread/condition_attribute.c new file mode 100644 index 0000000..da8409b --- /dev/null +++ b/level_0/f_thread/c/thread/condition_attribute.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "condition_attribute.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_condition_attributes_adjust_ + f_status_t f_thread_condition_attributes_adjust(const f_array_length_t length, f_thread_condition_attributes_t * const 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_condition_attributes_adjust(length, attributes); + } +#endif // _di_f_thread_condition_attributes_adjust_ + +#ifndef _di_f_thread_condition_attributes_decimate_by_ + f_status_t f_thread_condition_attributes_decimate_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->size - amount > 0) { + return private_f_thread_condition_attributes_adjust(attributes->size - amount, attributes); + } + + return private_f_thread_condition_attributes_adjust(0, attributes); + } +#endif // _di_f_thread_condition_attributes_decimate_by_ + +#ifndef _di_f_thread_condition_attributes_decrease_by_ + f_status_t f_thread_condition_attributes_decrease_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->size - amount > 0) { + return private_f_thread_condition_attributes_resize(attributes->size - amount, attributes); + } + + return private_f_thread_condition_attributes_resize(0, attributes); + } +#endif // _di_f_thread_condition_attributes_decrease_by_ + +#ifndef _di_f_thread_condition_attributes_increase_ + f_status_t f_thread_condition_attributes_increase(const f_array_length_t step, f_thread_condition_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && attributes->used + 1 > attributes->size) { + f_array_length_t size = attributes->used + step; + + if (size > F_array_length_t_size_d) { + if (attributes->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_condition_attributes_resize(size, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_condition_attributes_increase_ + +#ifndef _di_f_thread_condition_attributes_increase_by_ + f_status_t f_thread_condition_attributes_increase_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->used + amount > attributes->size) { + if (attributes->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_condition_attributes_resize(attributes->used + amount, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_condition_attributes_increase_by_ + +#ifndef _di_f_thread_condition_attributes_resize_ + f_status_t f_thread_condition_attributes_resize(const f_array_length_t length, f_thread_condition_attributes_t * const 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_condition_attributes_resize(length, attributes); + } +#endif // _di_f_thread_condition_attributes_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/condition_attribute.h b/level_0/f_thread/c/thread/condition_attribute.h new file mode 100644 index 0000000..2f357d6 --- /dev/null +++ b/level_0/f_thread/c/thread/condition_attribute.h @@ -0,0 +1,203 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_condition_attribute_h +#define _F_thread_condition_attribute_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_cond_t. + */ +#ifndef _di_f_thread_condition_attribute_t_ + typedef pthread_condattr_t f_thread_condition_attribute_t; + + #define f_thread_condition_attribute_t_initialize { 0 }; + + #define macro_f_thread_condition_attribute_t_initialize(array, size, used) attribute + + // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). + #define macro_f_thread_condition_attribute_t_clear(attribute) attribute.__align = 0; + + #define macro_f_thread_condition_attribute_t_delete_simple(attribute) f_thread_condition_attribute_delete(&attribute); +#endif // _di_f_thread_condition_attribute_t_ + +/** + * An array of thread condition attributes. + * + * array: The array of f_thread_condition_attribute_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_condition_attributes_t_ + typedef struct { + f_thread_condition_attribute_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_condition_attributes_t; + + #define f_thread_condition_attributes_t_initialize { 0, 0, 0 } + + #define macro_f_thread_condition_attributes_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_condition_attributes_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_condition_attributes_t_clear(attributes) macro_f_memory_structure_clear(attributes) + + #define macro_f_thread_condition_attributes_t_resize(status, attributes, length) status = f_thread_condition_attributes_resize(length, &attributes); + #define macro_f_thread_condition_attributes_t_adjust(status, attributes, length) status = f_thread_condition_attributes_adjust(length, &attributes); + + #define macro_f_thread_condition_attributes_t_delete_simple(attributes) f_thread_condition_attributes_resize(0, &condition_attributes); + #define macro_f_thread_condition_attributes_t_destroy_simple(attributes) f_thread_condition_attributes_adjust(0, &condition_attributes); + + #define macro_f_thread_condition_attributes_t_increase(status, step, attributes) status = f_thread_condition_attributes_increase(step, attributes); + #define macro_f_thread_condition_attributes_t_increase_by(status, attributes, amount) status = f_thread_condition_attributes_increase_by(amount, attributes); + #define macro_f_thread_condition_attributes_t_decrease_by(status, attributes, amount) status = f_thread_condition_attributes_decrease_by(amount, attributes); + #define macro_f_thread_condition_attributes_t_decimate_by(status, attributes, amount) status = f_thread_condition_attributes_decimate_by(amount, attributes); +#endif // _di_f_thread_condition_attributes_t_ + +/** + * Resize the thread 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_condition_attributes_adjust_ + extern f_status_t f_thread_condition_attributes_adjust(const f_array_length_t length, f_thread_condition_attributes_t * const attributes); +#endif // _di_f_thread_condition_attributes_adjust_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_condition_attributes_decimate_by_ + extern f_status_t f_thread_condition_attributes_decimate_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes); +#endif // _di_f_thread_condition_attributes_decimate_by_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_condition_attributes_decrease_by_ + extern f_status_t f_thread_condition_attributes_decrease_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes); +#endif // _di_f_thread_condition_attributes_decrease_by_ + +/** + * Increase the size of the thread 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @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_condition_attributes_increase_ + extern f_status_t f_thread_condition_attributes_increase(const f_array_length_t step, f_thread_condition_attributes_t * const attributes); +#endif // _di_f_thread_condition_attributes_increase_ + +/** + * Resize the thread attributes array to a larger size. + * + * This will resize making the array 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_d). + * 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_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_condition_attributes_increase_by_ + extern f_status_t f_thread_condition_attributes_increase_by(const f_array_length_t amount, f_thread_condition_attributes_t * const attributes); +#endif // _di_f_thread_condition_attributes_increase_by_ + +/** + * Resize the thread 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_condition_attributes_resize_ + extern f_status_t f_thread_condition_attributes_resize(const f_array_length_t length, f_thread_condition_attributes_t * const attributes); +#endif // _di_f_thread_condition_attributes_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_condition_attribute_h diff --git a/level_0/f_thread/c/thread/id.c b/level_0/f_thread/c/thread/id.c new file mode 100644 index 0000000..a9442ee --- /dev/null +++ b/level_0/f_thread/c/thread/id.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "id.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_ids_adjust_ + f_status_t f_thread_ids_adjust(const f_array_length_t length, f_thread_ids_t * const ids) { + #ifndef _di_level_0_parameter_checking_ + if (!ids) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_ids_adjust(length, ids); + } +#endif // _di_f_thread_ids_adjust_ + +#ifndef _di_f_thread_ids_decimate_by_ + f_status_t f_thread_ids_decimate_by(const f_array_length_t amount, f_thread_ids_t * const ids) { + #ifndef _di_level_0_parameter_checking_ + if (!ids) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (ids->size - amount > 0) { + return private_f_thread_ids_adjust(ids->size - amount, ids); + } + + return private_f_thread_ids_adjust(0, ids); + } +#endif // _di_f_thread_ids_decimate_by_ + +#ifndef _di_f_thread_ids_decrease_by_ + f_status_t f_thread_ids_decrease_by(const f_array_length_t amount, f_thread_ids_t * const ids) { + #ifndef _di_level_0_parameter_checking_ + if (!ids) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (ids->size - amount > 0) { + return private_f_thread_ids_resize(ids->size - amount, ids); + } + + return private_f_thread_ids_resize(0, ids); + } +#endif // _di_f_thread_ids_decrease_by_ + +#ifndef _di_f_thread_ids_increase_ + f_status_t f_thread_ids_increase(const f_array_length_t step, f_thread_ids_t * const ids) { + #ifndef _di_level_0_parameter_checking_ + if (!ids) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && ids->used + 1 > ids->size) { + f_array_length_t size = ids->used + step; + + if (size > F_array_length_t_size_d) { + if (ids->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_ids_resize(size, ids); + } + + return F_data_not; + } +#endif // _di_f_thread_ids_increase_ + +#ifndef _di_f_thread_ids_increase_by_ + f_status_t f_thread_ids_increase_by(const f_array_length_t amount, f_thread_ids_t * const ids) { + #ifndef _di_level_0_parameter_checking_ + if (!ids) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (ids->used + amount > ids->size) { + if (ids->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_ids_resize(ids->used + amount, ids); + } + + return F_data_not; + } +#endif // _di_f_thread_ids_increase_by_ + +#ifndef _di_f_thread_ids_resize_ + f_status_t f_thread_ids_resize(const f_array_length_t length, f_thread_ids_t * const ids) { + #ifndef _di_level_0_parameter_checking_ + if (!ids) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_ids_resize(length, ids); + } +#endif // _di_f_thread_ids_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/id.h b/level_0/f_thread/c/thread/id.h new file mode 100644 index 0000000..2409614 --- /dev/null +++ b/level_0/f_thread/c/thread/id.h @@ -0,0 +1,198 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_id_h +#define _F_thread_id_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_t. + */ +#ifndef _di_f_thread_id_t_ + typedef pthread_t f_thread_id_t; + + #define f_thread_id_t_initialize 0 + + #define macro_f_thread_id_t_clear(id) id = 0; +#endif // _di_f_thread_id_t_ + +/** + * An array of thread IDs. + * + * array: The array of f_thread_id_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_ids_t_ + typedef struct { + f_thread_id_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_ids_t; + + #define f_thread_ids_t_initialize { 0, 0, 0 } + + #define macro_f_thread_ids_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_ids_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_ids_t_clear(attributes) macro_f_memory_structure_clear(attributes) + + #define macro_f_thread_ids_t_resize(status, attributes, length) status = f_thread_ids_resize(length, &attributes); + #define macro_f_thread_ids_t_adjust(status, attributes, length) status = f_thread_ids_adjust(length, &attributes); + + #define macro_f_thread_ids_t_delete_simple(attributes) f_thread_ids_resize(0, &ids); + #define macro_f_thread_ids_t_destroy_simple(attributes) f_thread_ids_adjust(0, &ids); + + #define macro_f_thread_ids_t_increase(status, step, attributes) status = f_thread_ids_increase(step, attributes); + #define macro_f_thread_ids_t_increase_by(status, attributes, amount) status = f_thread_ids_increase_by(amount, attributes); + #define macro_f_thread_ids_t_decrease_by(status, attributes, amount) status = f_thread_ids_decrease_by(amount, attributes); + #define macro_f_thread_ids_t_decimate_by(status, attributes, amount) status = f_thread_ids_decimate_by(amount, attributes); +#endif // _di_f_thread_ids_t_ + +/** + * Resize the thread ids array. + * + * @param length + * The new size to use. + * @param ids + * The thread ids 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_ids_adjust_ + extern f_status_t f_thread_ids_adjust(const f_array_length_t length, f_thread_ids_t * const ids); +#endif // _di_f_thread_ids_adjust_ + +/** + * Resize the thread ids 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 ids + * The thread ids array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_ids_decimate_by_ + extern f_status_t f_thread_ids_decimate_by(const f_array_length_t amount, f_thread_ids_t * const ids); +#endif // _di_f_thread_ids_decimate_by_ + +/** + * Resize the thread ids 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 ids + * The thread ids array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_ids_decrease_by_ + extern f_status_t f_thread_ids_decrease_by(const f_array_length_t amount, f_thread_ids_t * const ids); +#endif // _di_f_thread_ids_decrease_by_ + +/** + * Increase the size of the thread ids 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param ids + * The thread ids 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_ids_increase_ + extern f_status_t f_thread_ids_increase(const f_array_length_t step, f_thread_ids_t * const ids); +#endif // _di_f_thread_ids_increase_ + +/** + * Resize the thread ids array to a larger size. + * + * This will resize making the array 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_d). + * 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 ids + * The thread ids 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_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_ids_increase_by_ + extern f_status_t f_thread_ids_increase_by(const f_array_length_t amount, f_thread_ids_t * const ids); +#endif // _di_f_thread_ids_increase_by_ + +/** + * Resize the thread ids array. + * + * @param length + * The new size to use. + * @param ids + * The thread ids 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_ids_resize_ + extern f_status_t f_thread_ids_resize(const f_array_length_t length, f_thread_ids_t * const ids); +#endif // _di_f_thread_ids_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_id_h diff --git a/level_0/f_thread/c/thread/key.c b/level_0/f_thread/c/thread/key.c new file mode 100644 index 0000000..de8134a --- /dev/null +++ b/level_0/f_thread/c/thread/key.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "key.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_keys_adjust_ + f_status_t f_thread_keys_adjust(const f_array_length_t length, f_thread_keys_t * const keys) { + #ifndef _di_level_0_parameter_checking_ + if (!keys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_keys_adjust(length, keys); + } +#endif // _di_f_thread_keys_adjust_ + +#ifndef _di_f_thread_keys_decimate_by_ + f_status_t f_thread_keys_decimate_by(const f_array_length_t amount, f_thread_keys_t * const keys) { + #ifndef _di_level_0_parameter_checking_ + if (!keys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (keys->size - amount > 0) { + return private_f_thread_keys_adjust(keys->size - amount, keys); + } + + return private_f_thread_keys_adjust(0, keys); + } +#endif // _di_f_thread_keys_decimate_by_ + +#ifndef _di_f_thread_keys_decrease_by_ + f_status_t f_thread_keys_decrease_by(const f_array_length_t amount, f_thread_keys_t * const keys) { + #ifndef _di_level_0_parameter_checking_ + if (!keys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (keys->size - amount > 0) { + return private_f_thread_keys_resize(keys->size - amount, keys); + } + + return private_f_thread_keys_resize(0, keys); + } +#endif // _di_f_thread_keys_decrease_by_ + +#ifndef _di_f_thread_keys_increase_ + f_status_t f_thread_keys_increase(const f_array_length_t step, f_thread_keys_t * const keys) { + #ifndef _di_level_0_parameter_checking_ + if (!keys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && keys->used + 1 > keys->size) { + f_array_length_t size = keys->used + step; + + if (size > F_array_length_t_size_d) { + if (keys->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_keys_resize(size, keys); + } + + return F_data_not; + } +#endif // _di_f_thread_keys_increase_ + +#ifndef _di_f_thread_keys_increase_by_ + f_status_t f_thread_keys_increase_by(const f_array_length_t amount, f_thread_keys_t * const keys) { + #ifndef _di_level_0_parameter_checking_ + if (!keys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (keys->used + amount > keys->size) { + if (keys->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_keys_resize(keys->used + amount, keys); + } + + return F_data_not; + } +#endif // _di_f_thread_keys_increase_by_ + +#ifndef _di_f_thread_keys_resize_ + f_status_t f_thread_keys_resize(const f_array_length_t length, f_thread_keys_t * const keys) { + #ifndef _di_level_0_parameter_checking_ + if (!keys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_keys_resize(length, keys); + } +#endif // _di_f_thread_keys_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/key.h b/level_0/f_thread/c/thread/key.h new file mode 100644 index 0000000..08c3fa0 --- /dev/null +++ b/level_0/f_thread/c/thread/key.h @@ -0,0 +1,202 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_key_h +#define _F_thread_key_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_key_t. + */ +#ifndef _di_f_thread_key_t_ + typedef pthread_key_t f_thread_key_t; + + #define f_thread_key_t_initialize 0 + + #define macro_f_thread_key_t_initialize(key) key + + #define macro_f_thread_key_t_clear(key) key = 0; + + #define macro_f_thread_key_t_delete_simple(key) f_thread_key_delete(&key); +#endif // _di_f_thread_key_t_ + +/** + * An array of thread keys. + * + * array: The array of f_thread_key_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_keys_t_ + typedef struct { + f_thread_key_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_keys_t; + + #define f_thread_keys_t_initialize { 0, 0, 0 } + + #define macro_f_thread_keys_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_keys_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_keys_t_clear(keys) macro_f_memory_structure_clear(keys) + + #define macro_f_thread_keys_t_resize(status, keys, length) status = f_thread_keys_resize(length, &keys); + #define macro_f_thread_keys_t_adjust(status, keys, length) status = f_thread_keys_adjust(length, &keys); + + #define macro_f_thread_keys_t_delete_simple(keys) f_thread_keys_resize(0, &keys); + #define macro_f_thread_keys_t_destroy_simple(keys) f_thread_keys_adjust(0, &keys); + + #define macro_f_thread_keys_t_increase(status, step, keys) status = f_thread_keys_increase(step, keys); + #define macro_f_thread_keys_t_increase_by(status, keys, amount) status = f_thread_keys_increase_by(amount, keys); + #define macro_f_thread_keys_t_decrease_by(status, keys, amount) status = f_thread_keys_decrease_by(amount, keys); + #define macro_f_thread_keys_t_decimate_by(status, keys, amount) status = f_thread_keys_decimate_by(amount, keys); +#endif // _di_f_thread_keys_t_ + +/** + * Resize the thread keys array. + * + * @param length + * The new size to use. + * @param keys + * The string keys 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_keys_adjust_ + extern f_status_t f_thread_keys_adjust(const f_array_length_t length, f_thread_keys_t * const keys); +#endif // _di_f_thread_keys_adjust_ + +/** + * Resize the thread keys 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 keys + * The string keys array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_keys_decimate_by_ + extern f_status_t f_thread_keys_decimate_by(const f_array_length_t amount, f_thread_keys_t * const keys); +#endif // _di_f_thread_keys_decimate_by_ + +/** + * Resize the thread keys 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 keys + * The string keys array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_keys_decrease_by_ + extern f_status_t f_thread_keys_decrease_by(const f_array_length_t amount, f_thread_keys_t * const keys); +#endif // _di_f_thread_keys_decrease_by_ + +/** + * Increase the size of the thread keys 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param keys + * The string keys 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_keys_increase_ + extern f_status_t f_thread_keys_increase(const f_array_length_t step, f_thread_keys_t * const keys); +#endif // _di_f_thread_keys_increase_ + +/** + * Resize the thread keys array to a larger size. + * + * This will resize making the array 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_d). + * 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 keys + * The string keys 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_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_keys_increase_by_ + extern f_status_t f_thread_keys_increase_by(const f_array_length_t amount, f_thread_keys_t * const keys); +#endif // _di_f_thread_keys_increase_by_ + +/** + * Resize the thread keys array. + * + * @param length + * The new size to use. + * @param keys + * The string keys 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_keys_resize_ + extern f_status_t f_thread_keys_resize(const f_array_length_t length, f_thread_keys_t * const keys); +#endif // _di_f_thread_keys_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_key_h diff --git a/level_0/f_thread/c/thread/lock.c b/level_0/f_thread/c/thread/lock.c new file mode 100644 index 0000000..425a2ab --- /dev/null +++ b/level_0/f_thread/c/thread/lock.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "lock.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_locks_adjust_ + f_status_t f_thread_locks_adjust(const f_array_length_t length, f_thread_locks_t * const locks) { + #ifndef _di_level_0_parameter_checking_ + if (!locks) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_locks_adjust(length, locks); + } +#endif // _di_f_thread_locks_adjust_ + +#ifndef _di_f_thread_locks_decimate_by_ + f_status_t f_thread_locks_decimate_by(const f_array_length_t amount, f_thread_locks_t * const locks) { + #ifndef _di_level_0_parameter_checking_ + if (!locks) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (locks->size - amount > 0) { + return private_f_thread_locks_adjust(locks->size - amount, locks); + } + + return private_f_thread_locks_adjust(0, locks); + } +#endif // _di_f_thread_locks_decimate_by_ + +#ifndef _di_f_thread_locks_decrease_by_ + f_status_t f_thread_locks_decrease_by(const f_array_length_t amount, f_thread_locks_t * const locks) { + #ifndef _di_level_0_parameter_checking_ + if (!locks) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (locks->size - amount > 0) { + return private_f_thread_locks_resize(locks->size - amount, locks); + } + + return private_f_thread_locks_resize(0, locks); + } +#endif // _di_f_thread_locks_decrease_by_ + +#ifndef _di_f_thread_locks_increase_ + f_status_t f_thread_locks_increase(const f_array_length_t step, f_thread_locks_t * const locks) { + #ifndef _di_level_0_parameter_checking_ + if (!locks) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && locks->used + 1 > locks->size) { + f_array_length_t size = locks->used + step; + + if (size > F_array_length_t_size_d) { + if (locks->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_locks_resize(size, locks); + } + + return F_data_not; + } +#endif // _di_f_thread_locks_increase_ + +#ifndef _di_f_thread_locks_increase_by_ + f_status_t f_thread_locks_increase_by(const f_array_length_t amount, f_thread_locks_t * const locks) { + #ifndef _di_level_0_parameter_checking_ + if (!locks) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (locks->used + amount > locks->size) { + if (locks->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_locks_resize(locks->used + amount, locks); + } + + return F_data_not; + } +#endif // _di_f_thread_locks_increase_by_ + +#ifndef _di_f_thread_locks_resize_ + f_status_t f_thread_locks_resize(const f_array_length_t length, f_thread_locks_t * const locks) { + #ifndef _di_level_0_parameter_checking_ + if (!locks) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_locks_resize(length, locks); + } +#endif // _di_f_thread_locks_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/lock.h b/level_0/f_thread/c/thread/lock.h new file mode 100644 index 0000000..afa7651 --- /dev/null +++ b/level_0/f_thread/c/thread/lock.h @@ -0,0 +1,201 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_lock_h +#define _F_thread_lock_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_rwlock_t (read/write lock). + * + * This must be dynamically initialized using f_thread_lock_create(). + * In some cases, they can be utilized statically, in which case only f_thread_lock_t_initialize is needed. + */ +#ifndef _di_f_thread_lock_t_ + typedef pthread_rwlock_t f_thread_lock_t; + + #define f_thread_lock_t_initialize PTHREAD_RWLOCK_INITIALIZER + + #define macro_f_thread_lock_t_initialize(lock) lock + + #define macro_f_thread_lock_t_delete_simple(lock) f_thread_lock_delete(&lock); +#endif // _di_f_thread_lock_t_ + +/** + * An array of thread locks. + * + * array: The array of f_thread_lock_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_locks_t_ + typedef struct { + f_thread_lock_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_locks_t; + + #define f_thread_locks_t_initialize { 0, 0, 0 } + + #define macro_f_thread_locks_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_locks_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_locks_t_resize(status, locks, length) macro_f_memory_structure_resize(status, locks, f_thread_lock_t, length) + #define macro_f_thread_locks_t_adjust(status, locks, length) macro_f_memory_structure_adjust(status, locks, f_thread_lock_t, length) + + #define macro_f_thread_locks_t_delete_simple(locks) macro_f_memory_structure_delete_simple(locks, f_thread_lock_t) + #define macro_f_thread_locks_t_destroy_simple(locks) macro_f_memory_structure_destroy_simple(locks, f_thread_lock_t) + + #define macro_f_thread_locks_t_increase(status, step, locks) macro_f_memory_structure_increase(status, step, locks, f_thread_lock_t) + #define macro_f_thread_locks_t_increase_by(status, locks, amount) macro_f_memory_structure_increase_by(status, locks, f_thread_lock_t, amount) + #define macro_f_thread_locks_t_decrease_by(status, locks, amount) macro_f_memory_structure_decrease_by(status, locks, f_thread_lock_t, amount) + #define macro_f_thread_locks_t_decimate_by(status, locks, amount) macro_f_memory_structure_decimate_by(status, locks, f_thread_lock_t, amount) +#endif // _di_f_thread_locks_t_ + +/** + * Resize the read/write locks array. + * + * @param length + * The new size to use. + * @param locks + * The string locks 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_locks_adjust_ + extern f_status_t f_thread_locks_adjust(const f_array_length_t length, f_thread_locks_t * const locks); +#endif // _di_f_thread_locks_adjust_ + +/** + * Resize the read/write locks 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 locks + * The string locks array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_locks_decimate_by_ + extern f_status_t f_thread_locks_decimate_by(const f_array_length_t amount, f_thread_locks_t * const locks); +#endif // _di_f_thread_locks_decimate_by_ + +/** + * Resize the read/write locks 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 locks + * The string locks array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_locks_decrease_by_ + extern f_status_t f_thread_locks_decrease_by(const f_array_length_t amount, f_thread_locks_t * const locks); +#endif // _di_f_thread_locks_decrease_by_ + +/** + * Increase the size of the read/write 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param locks + * The string locks 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_locks_increase_ + extern f_status_t f_thread_locks_increase(const f_array_length_t step, f_thread_locks_t * const locks); +#endif // _di_f_thread_locks_increase_ + +/** + * Resize the read/write locks array to a larger size. + * + * This will resize making the array 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_d). + * 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 locks + * The string locks 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_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_locks_increase_by_ + extern f_status_t f_thread_locks_increase_by(const f_array_length_t amount, f_thread_locks_t * const locks); +#endif // _di_f_thread_locks_increase_by_ + +/** + * Resize the read/write locks array. + * + * @param length + * The new size to use. + * @param locks + * The string locks 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_locks_resize_ + extern f_status_t f_thread_locks_resize(const f_array_length_t length, f_thread_locks_t * const locks); +#endif // _di_f_thread_locks_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_lock_h diff --git a/level_0/f_thread/c/thread/lock_attribute.c b/level_0/f_thread/c/thread/lock_attribute.c new file mode 100644 index 0000000..8c15452 --- /dev/null +++ b/level_0/f_thread/c/thread/lock_attribute.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "lock_attribute.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_lock_attributes_adjust_ + f_status_t f_thread_lock_attributes_adjust(const f_array_length_t length, f_thread_lock_attributes_t * const 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_lock_attributes_adjust(length, attributes); + } +#endif // _di_f_thread_lock_attributes_adjust_ + +#ifndef _di_f_thread_lock_attributes_decimate_by_ + f_status_t f_thread_lock_attributes_decimate_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->size - amount > 0) { + return private_f_thread_lock_attributes_adjust(attributes->size - amount, attributes); + } + + return private_f_thread_lock_attributes_adjust(0, attributes); + } +#endif // _di_f_thread_lock_attributes_decimate_by_ + +#ifndef _di_f_thread_lock_attributes_decrease_by_ + f_status_t f_thread_lock_attributes_decrease_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->size - amount > 0) { + return private_f_thread_lock_attributes_resize(attributes->size - amount, attributes); + } + + return private_f_thread_lock_attributes_resize(0, attributes); + } +#endif // _di_f_thread_lock_attributes_decrease_by_ + +#ifndef _di_f_thread_lock_attributes_increase_ + f_status_t f_thread_lock_attributes_increase(const f_array_length_t step, f_thread_lock_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && attributes->used + 1 > attributes->size) { + f_array_length_t size = attributes->used + step; + + if (size > F_array_length_t_size_d) { + if (attributes->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_lock_attributes_resize(size, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_lock_attributes_increase_ + +#ifndef _di_f_thread_lock_attributes_increase_by_ + f_status_t f_thread_lock_attributes_increase_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->used + amount > attributes->size) { + if (attributes->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_lock_attributes_resize(attributes->used + amount, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_lock_attributes_increase_by_ + +#ifndef _di_f_thread_lock_attributes_resize_ + f_status_t f_thread_lock_attributes_resize(const f_array_length_t length, f_thread_lock_attributes_t * const 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_lock_attributes_resize(length, attributes); + } +#endif // _di_f_thread_lock_attributes_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/lock_attribute.h b/level_0/f_thread/c/thread/lock_attribute.h new file mode 100644 index 0000000..e1165ff --- /dev/null +++ b/level_0/f_thread/c/thread/lock_attribute.h @@ -0,0 +1,203 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_lock_attribute_h +#define _F_thread_lock_attribute_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_rwlockattr_t. + */ +#ifndef _di_f_thread_lock_attribute_t_ + typedef pthread_rwlockattr_t f_thread_lock_attribute_t; + + #define f_thread_lock_attribute_t_initialize { 0 } + + #define macro_f_thread_lock_attribute_t_initialize(attribute) attribute + + // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). + #define macro_f_thread_lock_attribute_t_clear(attribute) attribute.__align = 0; + + #define macro_f_thread_lock_attribute_t_delete_simple(attribute) f_thread_lock_attribute_delete(&attribute); +#endif // _di_f_thread_lock_attribute_t_ + +/** + * An array of read/write lock attributees. + * + * array: The array of f_thread_lock_attribute_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_lock_attributes_t_ + typedef struct { + f_thread_lock_attribute_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_lock_attributes_t; + + #define f_thread_lock_attributes_t_initialize { 0, 0, 0 } + + #define macro_f_thread_lock_attributes_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_lock_attributes_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_lock_attributes_t_clear(attributes) macro_f_memory_structure_clear(attributes) + + #define macro_f_thread_lock_attributes_t_resize(status, attributes, length) status = f_thread_lock_attributes_resize(length, &attributes); + #define macro_f_thread_lock_attributes_t_adjust(status, attributes, length) status = f_thread_lock_attributes_adjust(length, &attributes); + + #define macro_f_thread_lock_attributes_t_delete_simple(attributes) f_thread_lock_attributes_resize(0, &attributes); + #define macro_f_thread_lock_attributes_t_destroy_simple(attributes) f_thread_lock_attributes_adjust(0, &attributes); + + #define macro_f_thread_lock_attributes_t_increase(status, step, attributes) status = f_thread_lock_attributes_increase(step, attributes); + #define macro_f_thread_lock_attributes_t_increase_by(status, attributes, amount) status = f_thread_lock_attributes_increase_by(amount, attributes); + #define macro_f_thread_lock_attributes_t_decrease_by(status, attributes, amount) status = f_thread_lock_attributes_decrease_by(amount, attributes); + #define macro_f_thread_lock_attributes_t_decimate_by(status, attributes, amount) status = f_thread_lock_attributes_decimate_by(amount, attributes); +#endif // _di_f_thread_lock_attributes_t_ + +/** + * Resize the thread 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_lock_attributes_adjust_ + extern f_status_t f_thread_lock_attributes_adjust(const f_array_length_t length, f_thread_lock_attributes_t * const attributes); +#endif // _di_f_thread_lock_attributes_adjust_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_lock_attributes_decimate_by_ + extern f_status_t f_thread_lock_attributes_decimate_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes); +#endif // _di_f_thread_lock_attributes_decimate_by_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_lock_attributes_decrease_by_ + extern f_status_t f_thread_lock_attributes_decrease_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes); +#endif // _di_f_thread_lock_attributes_decrease_by_ + +/** + * Increase the size of the thread 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @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_lock_attributes_increase_ + extern f_status_t f_thread_lock_attributes_increase(const f_array_length_t step, f_thread_lock_attributes_t * const attributes); +#endif // _di_f_thread_lock_attributes_increase_ + +/** + * Resize the thread attributes array to a larger size. + * + * This will resize making the array 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_d). + * 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_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_lock_attributes_increase_by_ + extern f_status_t f_thread_lock_attributes_increase_by(const f_array_length_t amount, f_thread_lock_attributes_t * const attributes); +#endif // _di_f_thread_lock_attributes_increase_by_ + +/** + * Resize the thread 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_lock_attributes_resize_ + extern f_status_t f_thread_lock_attributes_resize(const f_array_length_t length, f_thread_lock_attributes_t * const attributes); +#endif // _di_f_thread_lock_attributes_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_lock_attribute_h diff --git a/level_0/f_thread/c/thread/mutex.c b/level_0/f_thread/c/thread/mutex.c new file mode 100644 index 0000000..8d19bce --- /dev/null +++ b/level_0/f_thread/c/thread/mutex.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "mutex.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_mutexs_adjust_ + f_status_t f_thread_mutexs_adjust(const f_array_length_t length, f_thread_mutexs_t * const 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 * const mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + 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 * const mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + 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(const f_array_length_t step, f_thread_mutexs_t * const mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && mutexs->used + 1 > mutexs->size) { + f_array_length_t size = mutexs->used + step; + + if (size > F_array_length_t_size_d) { + if (mutexs->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + 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 * const mutexs) { + #ifndef _di_level_0_parameter_checking_ + if (!mutexs) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (mutexs->used + amount > mutexs->size) { + if (mutexs->used + amount > F_array_length_t_size_d) { + 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 * const 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_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/mutex.h b/level_0/f_thread/c/thread/mutex.h new file mode 100644 index 0000000..6411d22 --- /dev/null +++ b/level_0/f_thread/c/thread/mutex.h @@ -0,0 +1,205 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_mutex_h +#define _F_thread_mutex_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_mutex_t. + * + * This variable cannot be cleared by setting value to 0, so there is no clear macro provided. + * + * This must be dynamically initialized using f_thread_mutex_create(). + * In some cases, they can be utilized statically, in which case only f_thread_mutex_t_initialize is needed. + */ +#ifndef _di_f_thread_mutex_t_ + typedef pthread_mutex_t f_thread_mutex_t; + + #define f_thread_mutex_t_initialize PTHREAD_MUTEX_INITIALIZER + + #define macro_f_thread_mutex_t_initialize(mutex) mutex + + #define macro_f_thread_mutex_t_delete_simple(mutex) f_thread_mutex_delete(&mutex); +#endif // _di_f_thread_mutex_t_ + +/** + * An array of thread mutexes. + * + * array: The array of f_thread_mutex_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_mutexs_t_ + typedef struct { + f_thread_mutex_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_mutexs_t; + + #define f_thread_mutexs_t_initialize { 0, 0, 0 } + + #define macro_f_thread_mutexs_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_mutexs_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_mutexs_t_clear(mutexs) macro_f_memory_structure_clear(mutexs) + + #define macro_f_thread_mutexs_t_resize(status, mutexs, length) status = f_thread_mutexs_resize(length, &mutexs); + #define macro_f_thread_mutexs_t_adjust(status, mutexs, length) status = f_thread_mutexs_adjust(length, &mutexs); + + #define macro_f_thread_mutexs_t_delete_simple(mutexs) f_thread_mutexs_resize(0, &mutexs); + #define macro_f_thread_mutexs_t_destroy_simple(mutexs) f_thread_mutexs_adjust(0, &mutexs); + + #define macro_f_thread_mutexs_t_increase(status, step, mutexs) status = f_thread_mutexs_increase(step, mutexs); + #define macro_f_thread_mutexs_t_increase_by(status, mutexs, amount) status = f_thread_mutexs_increase_by(amount, mutexs); + #define macro_f_thread_mutexs_t_decrease_by(status, mutexs, amount) status = f_thread_mutexs_decrease_by(amount, mutexs); + #define macro_f_thread_mutexs_t_decimate_by(status, mutexs, amount) status = f_thread_mutexs_decimate_by(amount, mutexs); +#endif // _di_f_thread_mutexs_t_ + +/** + * Resize the thread 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 * const mutexs); +#endif // _di_f_thread_mutexs_adjust_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * 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 * const mutexs); +#endif // _di_f_thread_mutexs_decimate_by_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * 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 * const mutexs); +#endif // _di_f_thread_mutexs_decrease_by_ + +/** + * Increase the size of the thread 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @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(const f_array_length_t step, f_thread_mutexs_t * const mutexs); +#endif // _di_f_thread_mutexs_increase_ + +/** + * Resize the thread mutexs array to a larger size. + * + * This will resize making the array 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_d). + * 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_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_by_ + extern f_status_t f_thread_mutexs_increase_by(const f_array_length_t amount, f_thread_mutexs_t * const mutexs); +#endif // _di_f_thread_mutexs_increase_by_ + +/** + * Resize the thread 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 * const mutexs); +#endif // _di_f_thread_mutexs_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_mutex_h diff --git a/level_0/f_thread/c/thread/mutex_attribute.c b/level_0/f_thread/c/thread/mutex_attribute.c new file mode 100644 index 0000000..0ec9cc1 --- /dev/null +++ b/level_0/f_thread/c/thread/mutex_attribute.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "mutex_attribute.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_mutex_attributes_adjust_ + f_status_t f_thread_mutex_attributes_adjust(const f_array_length_t length, f_thread_mutex_attributes_t * const 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_mutex_attributes_adjust(length, attributes); + } +#endif // _di_f_thread_mutex_attributes_adjust_ + +#ifndef _di_f_thread_mutex_attributes_decimate_by_ + f_status_t f_thread_mutex_attributes_decimate_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->size - amount > 0) { + return private_f_thread_mutex_attributes_adjust(attributes->size - amount, attributes); + } + + return private_f_thread_mutex_attributes_adjust(0, attributes); + } +#endif // _di_f_thread_mutex_attributes_decimate_by_ + +#ifndef _di_f_thread_mutex_attributes_decrease_by_ + f_status_t f_thread_mutex_attributes_decrease_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->size - amount > 0) { + return private_f_thread_mutex_attributes_resize(attributes->size - amount, attributes); + } + + return private_f_thread_mutex_attributes_resize(0, attributes); + } +#endif // _di_f_thread_mutex_attributes_decrease_by_ + +#ifndef _di_f_thread_mutex_attributes_increase_ + f_status_t f_thread_mutex_attributes_increase(const f_array_length_t step, f_thread_mutex_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && attributes->used + 1 > attributes->size) { + f_array_length_t size = attributes->used + step; + + if (size > F_array_length_t_size_d) { + if (attributes->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_mutex_attributes_resize(size, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_mutex_attributes_increase_ + +#ifndef _di_f_thread_mutex_attributes_increase_by_ + f_status_t f_thread_mutex_attributes_increase_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes) { + #ifndef _di_level_0_parameter_checking_ + if (!attributes) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (attributes->used + amount > attributes->size) { + if (attributes->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_mutex_attributes_resize(attributes->used + amount, attributes); + } + + return F_data_not; + } +#endif // _di_f_thread_mutex_attributes_increase_by_ + +#ifndef _di_f_thread_mutex_attributes_resize_ + f_status_t f_thread_mutex_attributes_resize(const f_array_length_t length, f_thread_mutex_attributes_t * const 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_mutex_attributes_resize(length, attributes); + } +#endif // _di_f_thread_mutex_attributes_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/mutex_attribute.h b/level_0/f_thread/c/thread/mutex_attribute.h new file mode 100644 index 0000000..f90dc58 --- /dev/null +++ b/level_0/f_thread/c/thread/mutex_attribute.h @@ -0,0 +1,203 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_mutex_attribute_h +#define _F_thread_mutex_attribute_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_mutex_attribute_t. + */ +#ifndef _di_f_thread_mutex_attribute_t_ + typedef pthread_mutexattr_t f_thread_mutex_attribute_t; + + #define f_thread_mutex_attribute_t_initialize { 0 } + + #define macro_f_thread_mutex_attribute_t_initialize(attribute) attribute + + // This does not clear the thread.attributes.__size array (may need to memset() against a sizeof(pthread_attr_t)). + #define macro_f_thread_mutex_attribute_t_clear(attribute) attribute.__align = 0; + + #define macro_f_thread_mutex_attribute_t_delete_simple(attribute) f_thread_mutex_attribute_delete(&attribute); +#endif // _di_f_thread_mutex_attribute_t_ + +/** + * An array of thread mutex_attributees. + * + * array: The array of f_thread_mutex_attribute_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_mutex_attributes_t_ + typedef struct { + f_thread_mutex_attribute_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_mutex_attributes_t; + + #define f_thread_mutex_attributes_t_initialize { 0, 0, 0 } + + #define macro_f_thread_mutex_attributes_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_mutex_attributes_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_mutex_attributes_t_clear(attributes) macro_f_memory_structure_clear(attributes) + + #define macro_f_thread_mutex_attributes_t_resize(status, attributes, length) status = f_thread_mutex_attributes_resize(length, &attributes); + #define macro_f_thread_mutex_attributes_t_adjust(status, attributes, length) status = f_thread_mutex_attributes_adjust(length, &attributes); + + #define macro_f_thread_mutex_attributes_t_delete_simple(attributes) f_thread_mutex_attributes_resize(0, &attributes); + #define macro_f_thread_mutex_attributes_t_destroy_simple(attributes) f_thread_mutex_attributes_adjust(0, &attributes); + + #define macro_f_thread_mutex_attributes_t_increase(status, step, attributes) status = f_thread_mutex_attributes_increase(step, attributes); + #define macro_f_thread_mutex_attributes_t_increase_by(status, attributes, amount) status = f_thread_mutex_attributes_increase_by(amount, attributes); + #define macro_f_thread_mutex_attributes_t_decrease_by(status, attributes, amount) status = f_thread_mutex_attributes_decrease_by(amount, attributes); + #define macro_f_thread_mutex_attributes_t_decimate_by(status, attributes, amount) status = f_thread_mutex_attributes_decimate_by(amount, attributes); +#endif // _di_f_thread_mutex_attributes_t_ + +/** + * Resize the thread attributes array. + * + * @param length + * The new size to use. + * @param attributes + * The thread mutex 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_mutex_attributes_adjust_ + extern f_status_t f_thread_mutex_attributes_adjust(const f_array_length_t length, f_thread_mutex_attributes_t * const attributes); +#endif // _di_f_thread_mutex_attributes_adjust_ + +/** + * Resize the thread 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 thread mutex attributes array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_mutex_attributes_decimate_by_ + extern f_status_t f_thread_mutex_attributes_decimate_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes); +#endif // _di_f_thread_mutex_attributes_decimate_by_ + +/** + * Resize the thread 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 thread mutex attributes array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_mutex_attributes_decrease_by_ + extern f_status_t f_thread_mutex_attributes_decrease_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes); +#endif // _di_f_thread_mutex_attributes_decrease_by_ + +/** + * Increase the size of the thread 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param attributes + * The thread mutex 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_mutex_attributes_increase_ + extern f_status_t f_thread_mutex_attributes_increase(const f_array_length_t step, f_thread_mutex_attributes_t * const attributes); +#endif // _di_f_thread_mutex_attributes_increase_ + +/** + * Resize the thread attributes array to a larger size. + * + * This will resize making the array 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_d). + * 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 thread mutex 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_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_mutex_attributes_increase_by_ + extern f_status_t f_thread_mutex_attributes_increase_by(const f_array_length_t amount, f_thread_mutex_attributes_t * const attributes); +#endif // _di_f_thread_mutex_attributes_increase_by_ + +/** + * Resize the thread attributes array. + * + * @param length + * The new size to use. + * @param attributes + * The thread mutex 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_mutex_attributes_resize_ + extern f_status_t f_thread_mutex_attributes_resize(const f_array_length_t length, f_thread_mutex_attributes_t * const attributes); +#endif // _di_f_thread_mutex_attributes_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_mutex_attribute_h diff --git a/level_0/f_thread/c/thread/once.c b/level_0/f_thread/c/thread/once.c new file mode 100644 index 0000000..5a63091 --- /dev/null +++ b/level_0/f_thread/c/thread/once.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "once.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_onces_adjust_ + f_status_t f_thread_onces_adjust(const f_array_length_t length, f_thread_onces_t * const onces) { + #ifndef _di_level_0_parameter_checking_ + if (!onces) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_onces_adjust(length, onces); + } +#endif // _di_f_thread_onces_adjust_ + +#ifndef _di_f_thread_onces_decimate_by_ + f_status_t f_thread_onces_decimate_by(const f_array_length_t amount, f_thread_onces_t * const onces) { + #ifndef _di_level_0_parameter_checking_ + if (!onces) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (onces->size - amount > 0) { + return private_f_thread_onces_adjust(onces->size - amount, onces); + } + + return private_f_thread_onces_adjust(0, onces); + } +#endif // _di_f_thread_onces_decimate_by_ + +#ifndef _di_f_thread_onces_decrease_by_ + f_status_t f_thread_onces_decrease_by(const f_array_length_t amount, f_thread_onces_t * const onces) { + #ifndef _di_level_0_parameter_checking_ + if (!onces) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (onces->size - amount > 0) { + return private_f_thread_onces_resize(onces->size - amount, onces); + } + + return private_f_thread_onces_resize(0, onces); + } +#endif // _di_f_thread_onces_decrease_by_ + +#ifndef _di_f_thread_onces_increase_ + f_status_t f_thread_onces_increase(const f_array_length_t step, f_thread_onces_t * const onces) { + #ifndef _di_level_0_parameter_checking_ + if (!onces) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && onces->used + 1 > onces->size) { + f_array_length_t size = onces->used + step; + + if (size > F_array_length_t_size_d) { + if (onces->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_onces_resize(size, onces); + } + + return F_data_not; + } +#endif // _di_f_thread_onces_increase_ + +#ifndef _di_f_thread_onces_increase_by_ + f_status_t f_thread_onces_increase_by(const f_array_length_t amount, f_thread_onces_t * const onces) { + #ifndef _di_level_0_parameter_checking_ + if (!onces) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (onces->used + amount > onces->size) { + if (onces->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_onces_resize(onces->used + amount, onces); + } + + return F_data_not; + } +#endif // _di_f_thread_onces_increase_by_ + +#ifndef _di_f_thread_onces_resize_ + f_status_t f_thread_onces_resize(const f_array_length_t length, f_thread_onces_t * const onces) { + #ifndef _di_level_0_parameter_checking_ + if (!onces) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_onces_resize(length, onces); + } +#endif // _di_f_thread_onces_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/once.h b/level_0/f_thread/c/thread/once.h new file mode 100644 index 0000000..a14d720 --- /dev/null +++ b/level_0/f_thread/c/thread/once.h @@ -0,0 +1,203 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_once_h +#define _F_thread_once_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_once_t. + * + * There are no delete functions and therefore no delete macros. + */ +#ifndef _di_f_thread_once_t_ + typedef pthread_once_t f_thread_once_t; + + #define f_thread_once_t_initialize PTHREAD_ONCE_INIT + + #define macro_f_thread_once_t_initialize(once) once +#endif // _di_f_thread_once_t_ + +/** + * An array of thread onces. + * + * array: The array of f_thread_once_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_onces_t_ + typedef struct { + f_thread_once_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_onces_t; + + #define f_thread_onces_t_initialize { 0, 0, 0 } + + #define macro_f_thread_onces_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_onces_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_onces_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_onces_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_onces_t_clear(onces) macro_f_memory_structure_clear(onces) + + #define macro_f_thread_onces_t_resize(status, onces, length) status = f_thread_onces_resize(length, &onces); + #define macro_f_thread_onces_t_adjust(status, onces, length) status = f_thread_onces_adjust(length, &onces); + + #define macro_f_thread_onces_t_delete_simple(onces) f_thread_onces_resize(0, &onces); + #define macro_f_thread_onces_t_destroy_simple(onces) f_thread_onces_adjust(0, &onces); + + #define macro_f_thread_onces_t_increase(status, step, onces) status = f_thread_onces_increase(step, onces); + #define macro_f_thread_onces_t_increase_by(status, onces, amount) status = f_thread_onces_increase_by(amount, onces); + #define macro_f_thread_onces_t_decrease_by(status, onces, amount) status = f_thread_onces_decrease_by(amount, onces); + #define macro_f_thread_onces_t_decimate_by(status, onces, amount) status = f_thread_onces_decimate_by(amount, onces); +#endif // _di_f_thread_onces_t_ + +/** + * Resize the thread onces array. + * + * @param length + * The new size to use. + * @param onces + * The thread onces 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_onces_adjust_ + extern f_status_t f_thread_onces_adjust(const f_array_length_t length, f_thread_onces_t * const onces); +#endif // _di_f_thread_onces_adjust_ + +/** + * Resize the thread onces 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 onces + * The thread onces array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_onces_decimate_by_ + extern f_status_t f_thread_onces_decimate_by(const f_array_length_t amount, f_thread_onces_t * const onces); +#endif // _di_f_thread_onces_decimate_by_ + +/** + * Resize the thread onces 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 onces + * The thread onces array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_onces_decrease_by_ + extern f_status_t f_thread_onces_decrease_by(const f_array_length_t amount, f_thread_onces_t * const onces); +#endif // _di_f_thread_onces_decrease_by_ + +/** + * Increase the size of the thread onces 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param onces + * The thread onces 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_onces_increase_ + extern f_status_t f_thread_onces_increase(const f_array_length_t step, f_thread_onces_t * const onces); +#endif // _di_f_thread_onces_increase_ + +/** + * Resize the thread onces array to a larger size. + * + * This will resize making the array 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_d). + * 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 onces + * The thread onces 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_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_onces_increase_by_ + extern f_status_t f_thread_onces_increase_by(const f_array_length_t amount, f_thread_onces_t * const onces); +#endif // _di_f_thread_onces_increase_by_ + +/** + * Resize the thread onces array. + * + * @param length + * The new size to use. + * @param onces + * The thread onces 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_onces_resize_ + extern f_status_t f_thread_onces_resize(const f_array_length_t length, f_thread_onces_t * const onces); +#endif // _di_f_thread_onces_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_once_h diff --git a/level_0/f_thread/c/thread/semaphore.c b/level_0/f_thread/c/thread/semaphore.c new file mode 100644 index 0000000..1f5907a --- /dev/null +++ b/level_0/f_thread/c/thread/semaphore.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "semaphore.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_semaphores_adjust_ + f_status_t f_thread_semaphores_adjust(const f_array_length_t length, f_thread_semaphores_t * const semaphores) { + #ifndef _di_level_0_parameter_checking_ + if (!semaphores) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_semaphores_adjust(length, semaphores); + } +#endif // _di_f_thread_semaphores_adjust_ + +#ifndef _di_f_thread_semaphores_decimate_by_ + f_status_t f_thread_semaphores_decimate_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores) { + #ifndef _di_level_0_parameter_checking_ + if (!semaphores) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (semaphores->size - amount > 0) { + return private_f_thread_semaphores_adjust(semaphores->size - amount, semaphores); + } + + return private_f_thread_semaphores_adjust(0, semaphores); + } +#endif // _di_f_thread_semaphores_decimate_by_ + +#ifndef _di_f_thread_semaphores_decrease_by_ + f_status_t f_thread_semaphores_decrease_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores) { + #ifndef _di_level_0_parameter_checking_ + if (!semaphores) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (semaphores->size - amount > 0) { + return private_f_thread_semaphores_resize(semaphores->size - amount, semaphores); + } + + return private_f_thread_semaphores_resize(0, semaphores); + } +#endif // _di_f_thread_semaphores_decrease_by_ + +#ifndef _di_f_thread_semaphores_increase_ + f_status_t f_thread_semaphores_increase(const f_array_length_t step, f_thread_semaphores_t * const semaphores) { + #ifndef _di_level_0_parameter_checking_ + if (!semaphores) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && semaphores->used + 1 > semaphores->size) { + f_array_length_t size = semaphores->used + step; + + if (size > F_array_length_t_size_d) { + if (semaphores->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_semaphores_resize(size, semaphores); + } + + return F_data_not; + } +#endif // _di_f_thread_semaphores_increase_ + +#ifndef _di_f_thread_semaphores_increase_by_ + f_status_t f_thread_semaphores_increase_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores) { + #ifndef _di_level_0_parameter_checking_ + if (!semaphores) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (semaphores->used + amount > semaphores->size) { + if (semaphores->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_semaphores_resize(semaphores->used + amount, semaphores); + } + + return F_data_not; + } +#endif // _di_f_thread_semaphores_increase_by_ + +#ifndef _di_f_thread_semaphores_resize_ + f_status_t f_thread_semaphores_resize(const f_array_length_t length, f_thread_semaphores_t * const semaphores) { + #ifndef _di_level_0_parameter_checking_ + if (!semaphores) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_semaphores_resize(length, semaphores); + } +#endif // _di_f_thread_semaphores_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/semaphore.h b/level_0/f_thread/c/thread/semaphore.h new file mode 100644 index 0000000..61e4b4b --- /dev/null +++ b/level_0/f_thread/c/thread/semaphore.h @@ -0,0 +1,204 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_semaphore_h +#define _F_thread_semaphore_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing sem_t. + * + * This variable cannot be cleared by setting value to 0, so there is no clear macro provided. + * + * This must be dynamically initialized using f_thread_semaphore_create(). + */ +#ifndef _di_f_thread_semaphore_t_ + typedef sem_t f_thread_semaphore_t; + + #define f_thread_semaphore_t_initialize 0 + + #define macro_f_thread_semaphore_t_initialize(semaphore) semaphore + + #define macro_f_thread_semaphore_t_delete_simple(semaphore) f_thread_semaphore_delete(&semaphore); +#endif // _di_f_thread_semaphore_t_ + +/** + * An array of thread semaphorees. + * + * array: The array of f_thread_semaphore_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_semaphores_t_ + typedef struct { + f_thread_semaphore_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_semaphores_t; + + #define f_thread_semaphores_t_initialize { 0, 0, 0 } + + #define macro_f_thread_semaphores_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_semaphores_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_semaphores_t_clear(semaphores) macro_f_memory_structure_clear(semaphores) + + #define macro_f_thread_semaphores_t_resize(status, semaphores, length) status = f_thread_semaphores_resize(length, &semaphores); + #define macro_f_thread_semaphores_t_adjust(status, semaphores, length) status = f_thread_semaphores_adjust(length, &semaphores); + + #define macro_f_thread_semaphores_t_delete_simple(semaphores) f_thread_semaphores_resize(0, &semaphores); + #define macro_f_thread_semaphores_t_destroy_simple(semaphores) f_thread_semaphores_adjust(0, &semaphores); + + #define macro_f_thread_semaphores_t_increase(status, step, semaphores) status = f_thread_semaphores_increase(step, semaphores); + #define macro_f_thread_semaphores_t_increase_by(status, semaphores, amount) status = f_thread_semaphores_increase_by(amount, semaphores); + #define macro_f_thread_semaphores_t_decrease_by(status, semaphores, amount) status = f_thread_semaphores_decrease_by(amount, semaphores); + #define macro_f_thread_semaphores_t_decimate_by(status, semaphores, amount) status = f_thread_semaphores_decimate_by(amount, semaphores); +#endif // _di_f_thread_semaphores_t_ + +/** + * Resize the thread semaphores array. + * + * @param length + * The new size to use. + * @param semaphores + * The string semaphores 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_semaphores_adjust_ + extern f_status_t f_thread_semaphores_adjust(const f_array_length_t length, f_thread_semaphores_t * const semaphores); +#endif // _di_f_thread_semaphores_adjust_ + +/** + * Resize the thread semaphores 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 semaphores + * The string semaphores array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_semaphores_decimate_by_ + extern f_status_t f_thread_semaphores_decimate_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores); +#endif // _di_f_thread_semaphores_decimate_by_ + +/** + * Resize the thread semaphores 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 semaphores + * The string semaphores array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_semaphores_decrease_by_ + extern f_status_t f_thread_semaphores_decrease_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores); +#endif // _di_f_thread_semaphores_decrease_by_ + +/** + * Increase the size of the thread semaphores 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param semaphores + * The string semaphores 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_semaphores_increase_ + extern f_status_t f_thread_semaphores_increase(const f_array_length_t step, f_thread_semaphores_t * const semaphores); +#endif // _di_f_thread_semaphores_increase_ + +/** + * Resize the thread semaphores array to a larger size. + * + * This will resize making the array 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_d). + * 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 semaphores + * The string semaphores 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_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_semaphores_increase_by_ + extern f_status_t f_thread_semaphores_increase_by(const f_array_length_t amount, f_thread_semaphores_t * const semaphores); +#endif // _di_f_thread_semaphores_increase_by_ + +/** + * Resize the thread semaphores array. + * + * @param length + * The new size to use. + * @param semaphores + * The string semaphores 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_semaphores_resize_ + extern f_status_t f_thread_semaphores_resize(const f_array_length_t length, f_thread_semaphores_t * const semaphores); +#endif // _di_f_thread_semaphores_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_semaphore_h diff --git a/level_0/f_thread/c/thread/set.c b/level_0/f_thread/c/thread/set.c new file mode 100644 index 0000000..59eaf2b --- /dev/null +++ b/level_0/f_thread/c/thread/set.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_sets_adjust_ + f_status_t f_thread_sets_adjust(const f_array_length_t length, f_thread_sets_t * const 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 * const sets) { + #ifndef _di_level_0_parameter_checking_ + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + 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 * const sets) { + #ifndef _di_level_0_parameter_checking_ + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + 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(const f_array_length_t step, f_thread_sets_t * const sets) { + #ifndef _di_level_0_parameter_checking_ + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && sets->used + 1 > sets->size) { + f_array_length_t size = sets->used + step; + + if (size > F_array_length_t_size_d) { + if (sets->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + 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 * const sets) { + #ifndef _di_level_0_parameter_checking_ + if (!sets) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (sets->used + amount > sets->size) { + if (sets->used + amount > F_array_length_t_size_d) { + 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 * const 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_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/set.h b/level_0/f_thread/c/thread/set.h new file mode 100644 index 0000000..6593cb3 --- /dev/null +++ b/level_0/f_thread/c/thread/set.h @@ -0,0 +1,213 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_set_h +#define _F_thread_set_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A structure containing basic thread information. + * + * 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 attribute; + f_thread_id_t id; + int result; + } f_thread_set_t; + + #define f_thread_set_t_initialize { f_thread_attribute_t_initialize, f_thread_id_t_initialize, 0 } + + #define macro_f_thread_set_t_initialize(attribute, id, result) { attribute, id, result } + + #define macro_f_thread_set_t_clear(thread) \ + macro_f_thread_attribute_t_clear(thread.attribute) \ + macro_f_thread_id_t_clear(thread.id) \ + result = 0; + + #define macro_f_thread_set_t_delete_simple(set) macro_f_thread_attribute_t_delete_simple(set.attribute) +#endif // _di_f_thread_set_t_ + +/** + * An array of f_thread_set_t. + * + * array: The array of f_thread_set_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_sets_t_ + typedef struct { + f_thread_set_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_sets_t; + + #define f_thread_sets_t_initialize { 0, 0, 0 } + + #define macro_f_thread_sets_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_sets_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_sets_t_clear(sets) macro_f_memory_structure_clear(sets) + + #define macro_f_thread_sets_t_resize(status, sets, length) status = f_thread_sets_resize(length, &sets); + #define macro_f_thread_sets_t_adjust(status, sets, length) status = f_thread_sets_adjust(length, &sets); + + #define macro_f_thread_sets_t_delete_simple(sets) f_thread_sets_resize(0, &sets); + #define macro_f_thread_sets_t_destroy_simple(sets) f_thread_sets_adjust(0, &sets); + + #define macro_f_thread_sets_t_increase(status, step, sets) status = f_thread_sets_increase(step, sets); + #define macro_f_thread_sets_t_increase_by(status, sets, amount) status = f_thread_sets_increase_by(amount, sets); + #define macro_f_thread_sets_t_decrease_by(status, sets, amount) status = f_thread_sets_decrease_by(amount, sets); + #define macro_f_thread_sets_t_decimate_by(status, sets, amount) status = f_thread_sets_decimate_by(amount, sets); +#endif // _di_f_thread_sets_t_ + +/** + * Resize the thread 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 * const sets); +#endif // _di_f_thread_sets_adjust_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * 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 * const sets); +#endif // _di_f_thread_sets_decimate_by_ + +/** + * Resize the thread 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_data_not if amount is 0. + * + * 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 * const sets); +#endif // _di_f_thread_sets_decrease_by_ + +/** + * Increase the size of the thread 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @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(const f_array_length_t step, f_thread_sets_t * const sets); +#endif // _di_f_thread_sets_increase_ + +/** + * Resize the thread sets array to a larger size. + * + * This will resize making the array 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_d). + * 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_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_by_ + extern f_status_t f_thread_sets_increase_by(const f_array_length_t amount, f_thread_sets_t * const sets); +#endif // _di_f_thread_sets_increase_by_ + +/** + * Resize the thread 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 * const sets); +#endif // _di_f_thread_sets_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_set_h diff --git a/level_0/f_thread/c/thread/spin.c b/level_0/f_thread/c/thread/spin.c new file mode 100644 index 0000000..b2a6c40 --- /dev/null +++ b/level_0/f_thread/c/thread/spin.c @@ -0,0 +1,107 @@ +#include "../thread.h" +#include "../private-thread.h" +#include "spin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_thread_spins_adjust_ + f_status_t f_thread_spins_adjust(const f_array_length_t length, f_thread_spins_t * const spins) { + #ifndef _di_level_0_parameter_checking_ + if (!spins) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_spins_adjust(length, spins); + } +#endif // _di_f_thread_spins_adjust_ + +#ifndef _di_f_thread_spins_decimate_by_ + f_status_t f_thread_spins_decimate_by(const f_array_length_t amount, f_thread_spins_t * const spins) { + #ifndef _di_level_0_parameter_checking_ + if (!spins) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (spins->size - amount > 0) { + return private_f_thread_spins_adjust(spins->size - amount, spins); + } + + return private_f_thread_spins_adjust(0, spins); + } +#endif // _di_f_thread_spins_decimate_by_ + +#ifndef _di_f_thread_spins_decrease_by_ + f_status_t f_thread_spins_decrease_by(const f_array_length_t amount, f_thread_spins_t * const spins) { + #ifndef _di_level_0_parameter_checking_ + if (!spins) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (spins->size - amount > 0) { + return private_f_thread_spins_resize(spins->size - amount, spins); + } + + return private_f_thread_spins_resize(0, spins); + } +#endif // _di_f_thread_spins_decrease_by_ + +#ifndef _di_f_thread_spins_increase_ + f_status_t f_thread_spins_increase(const f_array_length_t step, f_thread_spins_t * const spins) { + #ifndef _di_level_0_parameter_checking_ + if (!spins) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && spins->used + 1 > spins->size) { + f_array_length_t size = spins->used + step; + + if (size > F_array_length_t_size_d) { + if (spins->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_thread_spins_resize(size, spins); + } + + return F_data_not; + } +#endif // _di_f_thread_spins_increase_ + +#ifndef _di_f_thread_spins_increase_by_ + f_status_t f_thread_spins_increase_by(const f_array_length_t amount, f_thread_spins_t * const spins) { + #ifndef _di_level_0_parameter_checking_ + if (!spins) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (spins->used + amount > spins->size) { + if (spins->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_thread_spins_resize(spins->used + amount, spins); + } + + return F_data_not; + } +#endif // _di_f_thread_spins_increase_by_ + +#ifndef _di_f_thread_spins_resize_ + f_status_t f_thread_spins_resize(const f_array_length_t length, f_thread_spins_t * const spins) { + #ifndef _di_level_0_parameter_checking_ + if (!spins) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_thread_spins_resize(length, spins); + } +#endif // _di_f_thread_spins_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/c/thread/spin.h b/level_0/f_thread/c/thread/spin.h new file mode 100644 index 0000000..2f8e0b6 --- /dev/null +++ b/level_0/f_thread/c/thread/spin.h @@ -0,0 +1,202 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by POSIX thread related functionality. + * + * This is auto-included by thread.h and should not need to be explicitly included. + */ +#ifndef _F_thread_spin_h +#define _F_thread_spin_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A typedef representing pthread_spinlock_t. + * + * Note: There appears to be no pthread init macro for spinlock, so initialize manually similarly to how the other inits work. + */ +#ifndef _di_f_thread_spin_t_ + typedef pthread_spinlock_t f_thread_spin_t; + + #define f_thread_spin_t_initialize ((pthread_spinlock_t) 0xFFFFFFFF) + + #define macro_f_thread_spin_t_initialize(spin) spin + + #define macro_f_thread_spin_t_delete_simple(spin) f_thread_spin_delete(&spin); +#endif // _di_f_thread_spin_t_ + +/** + * An array of thread spins. + * + * array: The array of f_thread_spin_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_thread_spins_t_ + typedef struct { + f_thread_spin_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_thread_spins_t; + + #define f_thread_spins_t_initialize { 0, 0, 0 } + + #define macro_f_thread_spins_t_initialize(array, size, used) { array, size, used } + #define macro_f_thread_spins_t_initialize2(array, length) { array, length, length } + + #define macro_f_thread_spins_t_clear(spins) macro_f_memory_structure_clear(spins) + + #define macro_f_thread_spins_t_resize(status, spins, length) status = f_thread_spins_resize(length, &spins); + #define macro_f_thread_spins_t_adjust(status, spins, length) status = f_thread_spins_adjust(length, &spins); + + #define macro_f_thread_spins_t_delete_simple(spins) f_thread_spins_resize(0, &spins); + #define macro_f_thread_spins_t_destroy_simple(spins) f_thread_spins_adjust(0, &spins); + + #define macro_f_thread_spins_t_increase(status, step, spins) status = f_thread_spins_increase(step, spins); + #define macro_f_thread_spins_t_increase_by(status, spins, amount) status = f_thread_spins_increase_by(amount, spins); + #define macro_f_thread_spins_t_decrease_by(status, spins, amount) status = f_thread_spins_decrease_by(amount, spins); + #define macro_f_thread_spins_t_decimate_by(status, spins, amount) status = f_thread_spins_decimate_by(amount, spins); +#endif // _di_f_thread_spins_t_ + +/** + * Resize the thread spin locks array. + * + * @param length + * The new size to use. + * @param spins + * The string spins 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_spins_adjust_ + extern f_status_t f_thread_spins_adjust(const f_array_length_t length, f_thread_spins_t * const spins); +#endif // _di_f_thread_spins_adjust_ + +/** + * Resize the thread spin locks 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 spins + * The string spins array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_spins_decimate_by_ + extern f_status_t f_thread_spins_decimate_by(const f_array_length_t amount, f_thread_spins_t * const spins); +#endif // _di_f_thread_spins_decimate_by_ + +/** + * Resize the thread spin locks 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 spins + * The string spins array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_thread_spins_decrease_by_ + extern f_status_t f_thread_spins_decrease_by(const f_array_length_t amount, f_thread_spins_t * const spins); +#endif // _di_f_thread_spins_decrease_by_ + +/** + * Increase the size of the thread spin locks 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param spins + * The string spins 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_spins_increase_ + extern f_status_t f_thread_spins_increase(const f_array_length_t step, f_thread_spins_t * const spins); +#endif // _di_f_thread_spins_increase_ + +/** + * Resize the thread spin locks array to a larger size. + * + * This will resize making the array 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_d). + * 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 spins + * The string spins 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_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_spins_increase_by_ + extern f_status_t f_thread_spins_increase_by(const f_array_length_t amount, f_thread_spins_t * const spins); +#endif // _di_f_thread_spins_increase_by_ + +/** + * Resize the thread spin locks array. + * + * @param length + * The new size to use. + * @param spins + * The string spins 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_spins_resize_ + extern f_status_t f_thread_spins_resize(const f_array_length_t length, f_thread_spins_t * const spins); +#endif // _di_f_thread_spins_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_thread_spin_h diff --git a/level_0/f_thread/data/build/settings b/level_0/f_thread/data/build/settings index 5cbb3e7..0ba954b 100644 --- a/level_0/f_thread/data/build/settings +++ b/level_0/f_thread/data/build/settings @@ -20,9 +20,9 @@ build_language c build_libraries -pthread -lc build_libraries-individual -lf_memory -lf_string -build_sources_library thread.c private-thread.c +build_sources_library thread.c private-thread.c thread/attribute.c thread/barrier.c thread/barrier_attribute.c thread/condition.c thread/condition_attribute.c thread/id.c thread/key.c thread/lock.c thread/lock_attribute.c thread/mutex.c thread/mutex_attribute.c thread/once.c thread/semaphore.c thread/set.c thread/spin.c -build_sources_headers thread.h thread/common.h +build_sources_headers thread.h thread/attribute.h thread/barrier.h thread/barrier_attribute.h thread/condition.h thread/condition_attribute.h thread/id.h thread/key.h thread/lock.h thread/lock_attribute.h thread/mutex.h thread/mutex_attribute.h thread/once.h thread/semaphore.h thread/set.h thread/spin.h build_script yes build_shared yes