From e8019cb0cb5accf34d518be4a4113bc3f0f0cee2 Mon Sep 17 00:00:00 2001 From: MacroModel Date: Tue, 23 Dec 2025 05:56:19 +0000 Subject: [PATCH 1/4] Enhance fast_io module by adding new data structures and improving existing functionality. Introduced list, queue, and stack containers, and added various utility functions across core, device, and hosted files. Updated includes and namespaces for better organization and accessibility. --- share/fast_io/fast_io.cppm | 34 ++++++----- share/fast_io/fast_io_inc/core.inc | 37 ++++++++++++ share/fast_io/fast_io_inc/device.inc | 2 + share/fast_io/fast_io_inc/dsal/list.inc | 14 +++++ share/fast_io/fast_io_inc/dsal/queue.inc | 14 +++++ share/fast_io/fast_io_inc/dsal/stack.inc | 14 +++++ .../fast_io/fast_io_inc/dsal/string_view.inc | 2 + share/fast_io/fast_io_inc/dsal/tuple.inc | 1 + share/fast_io/fast_io_inc/freestanding.inc | 3 + share/fast_io/fast_io_inc/host/nt.inc | 27 +++++++++ share/fast_io/fast_io_inc/host/posix.inc | 14 +++++ share/fast_io/fast_io_inc/host/win32.inc | 37 ++++++++++++ share/fast_io/fast_io_inc/hosted.inc | 60 +++++++++++++++++++ 13 files changed, 245 insertions(+), 14 deletions(-) create mode 100644 share/fast_io/fast_io_inc/dsal/list.inc create mode 100644 share/fast_io/fast_io_inc/dsal/queue.inc create mode 100644 share/fast_io/fast_io_inc/dsal/stack.inc diff --git a/share/fast_io/fast_io.cppm b/share/fast_io/fast_io.cppm index 04e09f514..594f9aa43 100644 --- a/share/fast_io/fast_io.cppm +++ b/share/fast_io/fast_io.cppm @@ -7,12 +7,15 @@ #include #include #include +#include +#include +#include -#if !(((__STDC_HOSTED__ == 1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED == 1) && !defined(_LIBCPP_FREESTANDING)) || \ - defined(FAST_IO_ENABLE_HOSTED_FEATURES))) -# ifndef FAST_IO_FREESTANDING -# define FAST_IO_FREESTANDING -# endif +#if !(((__STDC_HOSTED__ == 1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED == 1) && !defined(_LIBCPP_FREESTANDING)) || \ + defined(FAST_IO_ENABLE_HOSTED_FEATURES))) +#ifndef FAST_IO_FREESTANDING +#define FAST_IO_FREESTANDING +#endif #endif export module fast_io; @@ -23,18 +26,18 @@ export module fast_io; #include "fast_io_inc/intrinsics.inc" #ifndef FAST_IO_FREESTANDING -# include "fast_io_inc/hosted.inc" +#include "fast_io_inc/hosted.inc" -# include "fast_io_inc/host/posix.inc" +#include "fast_io_inc/host/posix.inc" -# if defined(_WIN32) || defined(__CYGWIN__) -# include "fast_io_inc/host/nt.inc" -# include "fast_io_inc/host/win32.inc" -# endif +#if defined(_WIN32) || defined(__CYGWIN__) +#include "fast_io_inc/host/nt.inc" +#include "fast_io_inc/host/win32.inc" +#endif -# include "fast_io_inc/legacy/c.inc" -# include "fast_io_inc/device.inc" -# include "fast_io_inc/io_buffer.inc" +#include "fast_io_inc/legacy/c.inc" +#include "fast_io_inc/device.inc" +#include "fast_io_inc/io_buffer.inc" #endif /* @@ -50,6 +53,9 @@ containers #include "fast_io_inc/dsal/vector.inc" #include "fast_io_inc/dsal/string_view.inc" #include "fast_io_inc/dsal/string.inc" +#include "fast_io_inc/dsal/list.inc" +#include "fast_io_inc/dsal/queue.inc" +#include "fast_io_inc/dsal/stack.inc" /* details diff --git a/share/fast_io/fast_io_inc/core.inc b/share/fast_io/fast_io_inc/core.inc index eae3ae611..45cfd64e8 100644 --- a/share/fast_io/fast_io_inc/core.inc +++ b/share/fast_io/fast_io_inc/core.inc @@ -210,8 +210,16 @@ using ::fast_io::manipulators::ip_generic; using ::fast_io::manipulators::ip_scan_generic; #endif using ::fast_io::manipulators::cur_src_loc; + +using ::fast_io::manipulators::ip_scan_generic; +using ::fast_io::manipulators::strvw; } // namespace manipulators +namespace char_category +{ + using ::fast_io::char_category::is_dos_file_invalid_character; +} + namespace mnp = manipulators; namespace operations @@ -252,6 +260,8 @@ using ::fast_io::operations::scatter_pread_some_bytes; using ::fast_io::operations::output_stream_ref; +using ::fast_io::operations::io_stream_seek_bytes; + namespace decay { using ::fast_io::operations::decay::scan_freestanding_decay; @@ -264,6 +274,11 @@ using ::fast_io::operations::decay::output_stream_unlocked_ref_decay; } // namespace decay +namespace defines +{ +using ::fast_io::operations::defines::print_freestanding_okay; +} // namespace defines + using ::fast_io::operations::print_freestanding; } // namespace operations @@ -323,6 +338,7 @@ using ::fast_io::bitops::rtz; } // namespace bitops // network +using ::fast_io::ip; using ::fast_io::posix_empty_network_service; using ::fast_io::sock_family; using ::fast_io::sock_protocol; @@ -342,12 +358,23 @@ using ::fast_io::ipv6_scan_state_t; using ::fast_io::ip_port_scan_state_t; #endif +using ::fast_io::io_scatter_t; +using ::fast_io::io_scatter_status_t; +using ::fast_io::perms; +using ::fast_io::intfpos_t; +using ::fast_io::fposoffadd_scatters; +using ::fast_io::seekdir; + using ::fast_io::basic_timestamp; using ::fast_io::unix_timestamp; using ::fast_io::win32_timestamp; using ::fast_io::csharp_timestamp; using ::fast_io::year0_timestamp; using ::fast_io::universe_timestamp; +using ::fast_io::iso8601_timestamp; + +using ::fast_io::local; +using ::fast_io::utc; using ::fast_io::operator==; using ::fast_io::operator!=; @@ -369,4 +396,14 @@ using ::fast_io::operator^=; using ::fast_io::operator++; +namespace details +{ +using ::fast_io::details::dummy_buffer_output_stream; +} // namespace details + +using ::fast_io::basic_general_concat; +using ::fast_io::io_print_forward; +using ::fast_io::io_print_alias; + +using ::fast_io::uint_least64_subseconds_per_second; } // namespace fast_io diff --git a/share/fast_io/fast_io_inc/device.inc b/share/fast_io/fast_io_inc/device.inc index aee9b2349..976d9ee56 100644 --- a/share/fast_io/fast_io_inc/device.inc +++ b/share/fast_io/fast_io_inc/device.inc @@ -2,6 +2,8 @@ export namespace fast_io { using ::fast_io::dir_file; +using ::fast_io::dir_io_observer; + using ::fast_io::basic_iobuf_pipe; using ::fast_io::basic_ibuf_file; using ::fast_io::basic_obuf_file; diff --git a/share/fast_io/fast_io_inc/dsal/list.inc b/share/fast_io/fast_io_inc/dsal/list.inc new file mode 100644 index 000000000..190e37b91 --- /dev/null +++ b/share/fast_io/fast_io_inc/dsal/list.inc @@ -0,0 +1,14 @@ +export namespace fast_io +{ +namespace containers +{ + using ::fast_io::containers::list; +} + +using ::fast_io::list; +namespace tlc +{ + using ::fast_io::tlc::list; +} + +} // namespace fast_io \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/dsal/queue.inc b/share/fast_io/fast_io_inc/dsal/queue.inc new file mode 100644 index 000000000..08bd540d2 --- /dev/null +++ b/share/fast_io/fast_io_inc/dsal/queue.inc @@ -0,0 +1,14 @@ +export namespace fast_io +{ +namespace containers +{ + using ::fast_io::containers::queue; +} + +using ::fast_io::queue; +namespace tlc +{ + using ::fast_io::tlc::queue; +} + +} // namespace fast_io \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/dsal/stack.inc b/share/fast_io/fast_io_inc/dsal/stack.inc new file mode 100644 index 000000000..a9c111afe --- /dev/null +++ b/share/fast_io/fast_io_inc/dsal/stack.inc @@ -0,0 +1,14 @@ +export namespace fast_io +{ +namespace containers +{ + using ::fast_io::containers::stack; +} + +using ::fast_io::stack; +namespace tlc +{ + using ::fast_io::tlc::stack; +} + +} // namespace fast_io \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/dsal/string_view.inc b/share/fast_io/fast_io_inc/dsal/string_view.inc index 4154cccc5..9a636a42a 100644 --- a/share/fast_io/fast_io_inc/dsal/string_view.inc +++ b/share/fast_io/fast_io_inc/dsal/string_view.inc @@ -11,6 +11,8 @@ using ::fast_io::containers::operator==; using ::fast_io::containers::operator<=>; using ::fast_io::containers::swap; using ::fast_io::containers::print_alias_define; + +using ::fast_io::containers::npos; } // namespace containers using ::fast_io::string_view; diff --git a/share/fast_io/fast_io_inc/dsal/tuple.inc b/share/fast_io/fast_io_inc/dsal/tuple.inc index 4a2c20f8a..d669e10a5 100644 --- a/share/fast_io/fast_io_inc/dsal/tuple.inc +++ b/share/fast_io/fast_io_inc/dsal/tuple.inc @@ -13,4 +13,5 @@ using ::fast_io::tuple; using ::fast_io::get; using ::fast_io::is_tuple; using ::fast_io::forward_as_tuple; +using ::fast_io::tuple_size; } // namespace fast_io diff --git a/share/fast_io/fast_io_inc/freestanding.inc b/share/fast_io/fast_io_inc/freestanding.inc index 11be871dc..6b5aeef37 100644 --- a/share/fast_io/fast_io_inc/freestanding.inc +++ b/share/fast_io/fast_io_inc/freestanding.inc @@ -46,7 +46,10 @@ using ::fast_io::freestanding::find_last_not; using ::fast_io::freestanding::find_first_not_of; using ::fast_io::freestanding::find_last_of; using ::fast_io::freestanding::find_last_not_of; +using ::fast_io::freestanding::nonoverlapped_bytes_copy_n; +using ::fast_io::freestanding::bytes_clear_n; using ::fast_io::freestanding::errc; + } // namespace freestanding } // namespace fast_io \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/host/nt.inc b/share/fast_io/fast_io_inc/host/nt.inc index 9b890699c..74c4fc829 100644 --- a/share/fast_io/fast_io_inc/host/nt.inc +++ b/share/fast_io/fast_io_inc/host/nt.inc @@ -1,6 +1,8 @@ export namespace fast_io { + using ::fast_io::nt_domain_value; + namespace win32::nt { using ::fast_io::win32::nt::nt_get_current_peb; @@ -10,5 +12,30 @@ export namespace fast_io using ::fast_io::win32::nt::nt_set_information_virtual_memory; using ::fast_io::win32::nt::memory_range_entry; using ::fast_io::win32::nt::virtual_memory_information_class; + using ::fast_io::win32::nt::nt_query_system_information; + using ::fast_io::win32::nt::system_information_class; + using ::fast_io::win32::nt::nt_allocate_virtual_memory; + using ::fast_io::win32::nt::nt_free_virtual_memory; + using ::fast_io::win32::nt::system_basic_information; + using ::fast_io::win32::nt::nt_yield_execution; + using ::fast_io::win32::nt::file_fs_device_type; + using ::fast_io::win32::nt::io_status_block; + using ::fast_io::win32::nt::fs_information_class; + using ::fast_io::win32::nt::nt_query_volume_information_file; + using ::fast_io::win32::nt::file_basic_information; + using ::fast_io::win32::nt::file_information_class; + using ::fast_io::win32::nt::nt_query_information_file; + using ::fast_io::win32::nt::nt_create_timer; + using ::fast_io::win32::nt::nt_set_information_file; + using ::fast_io::win32::nt::file_allocation_information; + using ::fast_io::win32::nt::RtlGetSystemTimePrecise; + using ::fast_io::win32::nt::file_standard_information; + using ::fast_io::win32::nt::nt_set_timer; + using ::fast_io::win32::nt::timer_type; + using ::fast_io::win32::nt::nt_close; + using ::fast_io::win32::nt::nt_wait_for_multiple_objects; + using ::fast_io::win32::nt::wait_type; + using ::fast_io::win32::nt::nt_delay_execution; + using ::fast_io::win32::nt::nt_wait_for_single_object; } // namespace win32::nt } \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/host/posix.inc b/share/fast_io/fast_io_inc/host/posix.inc index 26d066084..0ab9324ab 100644 --- a/share/fast_io/fast_io_inc/host/posix.inc +++ b/share/fast_io/fast_io_inc/host/posix.inc @@ -4,10 +4,24 @@ export namespace fast_io using ::fast_io::posix_stdin_number; using ::fast_io::posix_stdout_number; using ::fast_io::posix_stderr_number; + using ::fast_io::posix_domain_value; + #if ((!defined(_WIN32) || defined(__WINE__)) || defined(__CYGWIN__)) namespace posix { using ::fast_io::posix::libc_ioctl; } + + namespace details + { + using ::fast_io::details::sys_mmap; + using ::fast_io::details::sys_mprotect; + using ::fast_io::details::sys_munmap; + using ::fast_io::details::sys_munmap_nothrow; + + } + + using ::fast_io::posix_socklen_t; + #endif } \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/host/win32.inc b/share/fast_io/fast_io_inc/host/win32.inc index 7b1fa0962..1f08c09da 100644 --- a/share/fast_io/fast_io_inc/host/win32.inc +++ b/share/fast_io/fast_io_inc/host/win32.inc @@ -23,5 +23,42 @@ export namespace fast_io using ::fast_io::win32::SetConsoleTextAttribute; using ::fast_io::win32::console_screen_buffer_info; using ::fast_io::win32::GetConsoleScreenBufferInfo; + using ::fast_io::win32::GetSystemInfo; + using ::fast_io::win32::system_info; + using ::fast_io::win32::VirtualAlloc; + using ::fast_io::win32::VirtualFree; + using ::fast_io::win32::GetEnvironmentStringsW; + using ::fast_io::win32::GetEnvironmentStringsA; + using ::fast_io::win32::FreeEnvironmentStringsW; + using ::fast_io::win32::FreeEnvironmentStringsA; + using ::fast_io::win32::AddVectoredExceptionHandler; + using ::fast_io::win32::exception_pointers; + using ::fast_io::win32::RaiseException; + using ::fast_io::win32::getsockopt; + using ::fast_io::win32::ioctlsocket; + using ::fast_io::win32::WSAGetLastError; + using ::fast_io::win32::shutdown; + using ::fast_io::win32::ExitProcess; + using ::fast_io::win32::wsabuf; + using ::fast_io::win32::WSARecv; + using ::fast_io::win32::WSASend; + using ::fast_io::win32::GetFileType; + using ::fast_io::win32::sockaddr_in; + using ::fast_io::win32::sockaddr_storage; + using ::fast_io::win32::sockaddr_in6; + using ::fast_io::win32::WSACreateEvent; + using ::fast_io::win32::WSACloseEvent; + using ::fast_io::win32::WSAEventSelect; + using ::fast_io::win32::wsanetworkevents; + using ::fast_io::win32::WSAEnumNetworkEvents; + } // namespace win32 + + using ::fast_io::win32_socket_file; + using ::fast_io::win32_socket_io_observer; + using ::fast_io::win32_socket_event_guard_t; + + using ::fast_io::data_sync_flags; + using ::fast_io::data_sync; +u using ::fast_io::flush; } \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/hosted.inc b/share/fast_io/fast_io_inc/hosted.inc index f5d1163fb..2201e2d5d 100644 --- a/share/fast_io/fast_io_inc/hosted.inc +++ b/share/fast_io/fast_io_inc/hosted.inc @@ -124,5 +124,65 @@ using ::fast_io::system_call; using ::fast_io::posix_clock_id; using ::fast_io::posix_clock_gettime; +using ::fast_io::posix_clock_getres; +using ::fast_io::native_mutex; + +using ::fast_io::native_socklen_t; + +namespace this_thread +{ +#if ((defined(_WIN32) && !defined(__WINE__)) && !defined(__CYGWIN__)) || (defined(__MSDOS__) || defined(__DJGPP__)) || defined(__wasi__) || (!defined(__SINGLE_THREAD__) && !defined(__NEWLIB__) && !defined(__MSDOS__) && __has_include()) +using ::fast_io::this_thread::get_id; +using ::fast_io::this_thread::sleep_for; +using ::fast_io::this_thread::sleep_until; +using ::fast_io::this_thread::yield; +#endif +} // namespace this_thread + +using ::fast_io::native_readlinkat; +using ::fast_io::native_symlinkat; +using ::fast_io::native_unlinkat; +using ::fast_io::native_renameat; +using ::fast_io::native_mkdirat; +using ::fast_io::native_fstatat; +using ::fast_io::native_at_flags; +using ::fast_io::native_utimensat; +using ::fast_io::native_linkat; + +using ::fast_io::posix_accept; +using ::fast_io::posix_connect; +using ::fast_io::posix_bind; +using ::fast_io::posix_listen; + +using ::fast_io::begin; +using ::fast_io::end; +using ::fast_io::current; +using ::fast_io::u8filename; +using ::fast_io::inode_ul64; +using ::fast_io::type; +using ::fast_io::is_dot; + +using ::fast_io::status; +using ::fast_io::file_type; +using ::fast_io::posix_file_status; + +using ::fast_io::truncate; + +using ::fast_io::native_white_hole; +using ::fast_io::native_socket_file; +using ::fast_io::native_socket_io_observer; + +using ::fast_io::ipv4; +using ::fast_io::ipv6; + +using ::fast_io::native_dns_file; +using ::fast_io::to_ip; +using ::fast_io::to_ip_address; + +using ::fast_io::io_kernel; + +#if defined(__linux__) +using ::fast_io::fast_exit; +#endif } // namespace fast_io From f90356309e19ff9959f22e3f5315e93c04031a2b Mon Sep 17 00:00:00 2001 From: MacroModel Date: Tue, 23 Dec 2025 05:56:29 +0000 Subject: [PATCH 2/4] Refactor and enhance threading support across various platforms. Added yield functions for Win32, POSIX, and WASI, improving thread management. Updated socket handling definitions and fixed formatting inconsistencies in header files. --- .../platforms/win32/win32_definitions.h | 128 +++++++++++++++--- .../platforms/win32_network/socket_file.h | 2 +- include/fast_io_hosted/threads/thread/dos.h | 16 +++ include/fast_io_hosted/threads/thread/nt.h | 13 ++ .../fast_io_hosted/threads/thread/pthread.h | 55 +++++--- include/fast_io_hosted/threads/thread/wasi.h | 10 ++ include/fast_io_hosted/threads/thread/win32.h | 16 +++ third-party/googletest | 1 + 8 files changed, 196 insertions(+), 45 deletions(-) create mode 160000 third-party/googletest diff --git a/include/fast_io_hosted/platforms/win32/win32_definitions.h b/include/fast_io_hosted/platforms/win32/win32_definitions.h index 280365686..895ca2bdd 100644 --- a/include/fast_io_hosted/platforms/win32/win32_definitions.h +++ b/include/fast_io_hosted/platforms/win32/win32_definitions.h @@ -456,7 +456,7 @@ using farproc = ::std::ptrdiff_t(FAST_IO_STDCALL *)() noexcept; struct win32_memory_range_entry { - void* VirtualAddress; + void *VirtualAddress; ::std::size_t NumberOfBytes; }; @@ -464,41 +464,125 @@ inline constexpr ::std::size_t exception_maximum_parameters{15u}; struct exception_record { - ::std::uint_least32_t ExceptionCode; - ::std::uint_least32_t ExceptionFlags; - exception_record* ExceptionRecord; - void* ExceptionAddress; - ::std::uint_least32_t NumberParameters; - ::std::size_t ExceptionInformation[exception_maximum_parameters]; + ::std::uint_least32_t ExceptionCode; + ::std::uint_least32_t ExceptionFlags; + exception_record *ExceptionRecord; + void *ExceptionAddress; + ::std::uint_least32_t NumberParameters; + ::std::size_t ExceptionInformation[exception_maximum_parameters]; }; struct exception_record32 { - ::std::uint_least32_t ExceptionCode; - ::std::uint_least32_t ExceptionFlags; - ::std::uint_least32_t ExceptionRecord; - ::std::uint_least32_t ExceptionAddress; - ::std::uint_least32_t NumberParameters; - ::std::uint_least32_t ExceptionInformation[exception_maximum_parameters]; + ::std::uint_least32_t ExceptionCode; + ::std::uint_least32_t ExceptionFlags; + ::std::uint_least32_t ExceptionRecord; + ::std::uint_least32_t ExceptionAddress; + ::std::uint_least32_t NumberParameters; + ::std::uint_least32_t ExceptionInformation[exception_maximum_parameters]; }; struct exception_record64 { - ::std::uint_least32_t ExceptionCode; - ::std::uint_least32_t ExceptionFlags; - ::std::uint_least64_t ExceptionRecord; - ::std::uint_least64_t ExceptionAddress; - ::std::uint_least32_t NumberParameters; - ::std::uint_least32_t UnusedAlignment; - ::std::uint_least64_t ExceptionInformation[exception_maximum_parameters]; + ::std::uint_least32_t ExceptionCode; + ::std::uint_least32_t ExceptionFlags; + ::std::uint_least64_t ExceptionRecord; + ::std::uint_least64_t ExceptionAddress; + ::std::uint_least32_t NumberParameters; + ::std::uint_least32_t UnusedAlignment; + ::std::uint_least64_t ExceptionInformation[exception_maximum_parameters]; }; struct exception_pointers { - exception_record* ExceptionRecord; - void* ContextRecord; + exception_record *ExceptionRecord; + void *ContextRecord; }; using pvectored_exception_handler = ::std::int_least32_t(FAST_IO_WINSTDCALL *)(exception_pointers *) noexcept; +using address_family = ::std::uint_least16_t; + +inline constexpr ::std::size_t ss_maxsize{128u}; +inline constexpr ::std::size_t ss_alignsize{sizeof(::std::int_least64_t)}; +inline constexpr ::std::size_t ss_pad1size{ss_alignsize - sizeof(::std::uint_least16_t)}; +inline constexpr ::std::size_t ss_pad2size{ss_maxsize - (sizeof(::std::uint_least16_t) + ss_pad1size + ss_alignsize)}; + +// +// Definitions used for sockaddr_storage structure paddings design. +// + +struct sockaddr_storage +{ + address_family ss_family; // address family + char ss_pad1[ss_pad1size]; // 6 byte pad, this is to make + // implementation specific pad up to + // alignment field that follows explicit + // in the data structure + ::std::int_least64_t __ss_align; // Field to force desired structure + char ss_pad2[ss_pad2size]; // 112 byte pad to achieve desired size; + // _SS_MAXSIZE value minus size of + // ss_family, __ss_pad1, and + // __ss_align fields is 112 +}; + +struct in_addr +{ + union S_un_u + { + struct S_un_b_t + { + ::std::uint_least8_t s_b1, s_b2, s_b3, s_b4; + } S_un_b; + struct S_un_w_t + { + ::std::uint_least16_t s_w1, s_w2; + } S_un_w; + ::std::uint_least32_t S_addr; + } S_un; +}; + +struct sockaddr_in +{ + address_family sin_family; + ::std::uint_least16_t sin_port; + in_addr sin_addr; + char sin_zero[8]; +}; + +struct in6_addr +{ + union u_u + { + ::std::uint_least8_t Byte[16]; + ::std::uint_least16_t Word[8]; + } u; +}; + +struct scope_id +{ + union DUMMYUNIONNAME_U + { + struct DUMMYSTRUCTNAME_T + { + ::std::uint_least32_t Zone : 28; + ::std::uint_least32_t Level : 4; + } DUMMYSTRUCTNAME; + ::std::uint_least32_t Value; + } DUMMYUNIONNAME; +}; + +struct sockaddr_in6 +{ + address_family sin6_family; // AF_INET6. + ::std::uint_least16_t sin6_port; // Transport level port number. + ::std::uint_least32_t sin6_flowinfo; // IPv6 flow information. + in6_addr sin6_addr; // IPv6 address. + union sin6_scope_u + { + ::std::uint_least32_t sin6_scope_id; // Set of interfaces for a scope. + scope_id sin6_scope_struct; + } sin6_scope; +}; + } // namespace fast_io::win32 diff --git a/include/fast_io_hosted/platforms/win32_network/socket_file.h b/include/fast_io_hosted/platforms/win32_network/socket_file.h index 998c66102..2a848b327 100644 --- a/include/fast_io_hosted/platforms/win32_network/socket_file.h +++ b/include/fast_io_hosted/platforms/win32_network/socket_file.h @@ -29,7 +29,7 @@ struct win32_socket_event_guard_t return *this; } - if(curr_handle) [[likely]] + if (curr_handle) [[likely]] { ::fast_io::win32::WSACloseEvent(curr_handle); } diff --git a/include/fast_io_hosted/threads/thread/dos.h b/include/fast_io_hosted/threads/thread/dos.h index 3639b984c..f56568835 100644 --- a/include/fast_io_hosted/threads/thread/dos.h +++ b/include/fast_io_hosted/threads/thread/dos.h @@ -1,11 +1,14 @@ #pragma once +// std #include #include #include #include #include #include +// system +#include namespace fast_io { @@ -122,6 +125,18 @@ inline auto const delta{unix_expect - now}; ::fast_io::dos::this_thread::sleep_for(delta); } + +inline +#if __cpp_constexpr >= 202207L + // https://en.cppreference.com/w/cpp/compiler_support/23.html#cpp_constexpr_202207L + // for reduce some warning purpose + constexpr +#endif + void yield() noexcept +{ + ::fast_io::noexcept_call(::__dpmi_yield()); +} + } // namespace dos::this_thread #if defined(__MSDOS__) || defined(__DJGPP__) @@ -131,6 +146,7 @@ namespace this_thread using ::fast_io::dos::this_thread::get_id; using ::fast_io::dos::this_thread::sleep_for; using ::fast_io::dos::this_thread::sleep_until; +using ::fast_io::dos::this_thread::yield; } // namespace this_thread #endif diff --git a/include/fast_io_hosted/threads/thread/nt.h b/include/fast_io_hosted/threads/thread/nt.h index 0dbb77c04..155d4ff17 100644 --- a/include/fast_io_hosted/threads/thread/nt.h +++ b/include/fast_io_hosted/threads/thread/nt.h @@ -427,6 +427,18 @@ inline } } +template +inline +#if __cpp_constexpr >= 202207L + // https://en.cppreference.com/w/cpp/compiler_support/23.html#cpp_constexpr_202207L + // for reduce some warning purpose + constexpr +#endif + void yield() noexcept +{ + ::fast_io::win32::nt::nt_yield_execution(); +} + } // namespace this_thread } // namespace win32::nt @@ -442,6 +454,7 @@ namespace this_thread using ::fast_io::win32::nt::this_thread::get_id; using ::fast_io::win32::nt::this_thread::sleep_for; using ::fast_io::win32::nt::this_thread::sleep_until; +using ::fast_io::win32::nt::this_thread::yield; } // namespace this_thread #endif diff --git a/include/fast_io_hosted/threads/thread/pthread.h b/include/fast_io_hosted/threads/thread/pthread.h index 20104ce8f..6f5627081 100644 --- a/include/fast_io_hosted/threads/thread/pthread.h +++ b/include/fast_io_hosted/threads/thread/pthread.h @@ -1,12 +1,15 @@ #pragma once +// std #include #include #include #include #include #include +// system #include +#include #include #include @@ -32,8 +35,8 @@ class pthread_thread_start_routine_tuple_allocate_guard inline constexpr pthread_thread_start_routine_tuple_allocate_guard(pthread_thread_start_routine_tuple_allocate_guard const &) noexcept = delete; inline constexpr pthread_thread_start_routine_tuple_allocate_guard(pthread_thread_start_routine_tuple_allocate_guard &&other) noexcept = delete; - inline constexpr pthread_thread_start_routine_tuple_allocate_guard& operator=(pthread_thread_start_routine_tuple_allocate_guard const &) noexcept = delete; - inline constexpr pthread_thread_start_routine_tuple_allocate_guard& operator=(pthread_thread_start_routine_tuple_allocate_guard &&other) noexcept = delete; + inline constexpr pthread_thread_start_routine_tuple_allocate_guard &operator=(pthread_thread_start_routine_tuple_allocate_guard const &) noexcept = delete; + inline constexpr pthread_thread_start_routine_tuple_allocate_guard &operator=(pthread_thread_start_routine_tuple_allocate_guard &&other) noexcept = delete; inline constexpr ~pthread_thread_start_routine_tuple_allocate_guard() { @@ -91,8 +94,6 @@ class pthread_thread bool joinable_{false}; private: - - public: inline constexpr pthread_thread() noexcept = default; @@ -101,7 +102,7 @@ class pthread_thread inline constexpr pthread_thread(Func &&func, Args &&...args) { using start_routine_tuple_type = ::fast_io::containers::tuple<::std::decay_t, ::std::decay_t...>; - using alloc = ::fast_io::native_typed_global_allocator; + using alloc = ::fast_io::native_typed_global_allocator; auto start_routine_tuple{alloc::allocate(1u)}; #if defined(__clang__) @@ -225,25 +226,25 @@ namespace this_thread { [[nodiscard]] -inline +inline #if __cpp_constexpr >= 202207L // https://en.cppreference.com/w/cpp/compiler_support/23.html#cpp_constexpr_202207L // for reduce some warning purpose constexpr #endif -::fast_io::posix::pthread_thread::id get_id() noexcept + ::fast_io::posix::pthread_thread::id get_id() noexcept { return ::fast_io::noexcept_call(::pthread_self); } template -inline +inline #if __cpp_constexpr >= 202207L // https://en.cppreference.com/w/cpp/compiler_support/23.html#cpp_constexpr_202207L // for reduce some warning purpose constexpr #endif -void sleep_for(::std::chrono::duration const &sleep_duration) noexcept + void sleep_for(::std::chrono::duration const &sleep_duration) noexcept { auto const ns64{::std::chrono::duration_cast<::std::chrono::nanoseconds>(sleep_duration).count()}; if (ns64 <= 0) @@ -257,13 +258,13 @@ void sleep_for(::std::chrono::duration const &sleep_duration) noexc } template -inline +inline #if __cpp_constexpr >= 202207L // https://en.cppreference.com/w/cpp/compiler_support/23.html#cpp_constexpr_202207L // for reduce some warning purpose constexpr #endif -void sleep_until(::std::chrono::time_point const &expect_time) noexcept + void sleep_until(::std::chrono::time_point const &expect_time) noexcept { auto const now{Clock::now()}; if (now < expect_time) @@ -294,13 +295,13 @@ void sleep_until(::std::chrono::time_point const &expect_time) } template <::std::int_least64_t off_to_epoch> -inline +inline #if __cpp_constexpr >= 202207L // https://en.cppreference.com/w/cpp/compiler_support/23.html#cpp_constexpr_202207L // for reduce some warning purpose constexpr #endif -void sleep_for(::fast_io::basic_timestamp const &sleep_duration) noexcept + void sleep_for(::fast_io::basic_timestamp const &sleep_duration) noexcept { if (sleep_duration.seconds < 0) { @@ -316,18 +317,18 @@ void sleep_for(::fast_io::basic_timestamp const &sleep_duration) n { return; } - - ::fast_io::noexcept_call(::nanosleep, __builtin_addressof(req), nullptr); + + ::fast_io::noexcept_call(::nanosleep, __builtin_addressof(req), nullptr); } template <::std::int_least64_t off_to_epoch> -inline +inline #if __cpp_constexpr >= 202207L // https://en.cppreference.com/w/cpp/compiler_support/23.html#cpp_constexpr_202207L // for reduce some warning purpose constexpr #endif -void sleep_until(::fast_io::basic_timestamp const &expect_time) noexcept + void sleep_until(::fast_io::basic_timestamp const &expect_time) noexcept { if (expect_time.seconds < 0) { @@ -336,7 +337,7 @@ void sleep_until(::fast_io::basic_timestamp const &expect_time) no ::timespec ts{}; - auto const unix_ts{static_cast<::fast_io::unix_timestamp>(expect_time)}; + auto const unix_ts{static_cast<::fast_io::unix_timestamp>(expect_time)}; ts.tv_sec = static_cast<::time_t>(unix_ts.seconds); constexpr ::std::uint_least64_t mul_factor{::fast_io::uint_least64_subseconds_per_second / 1000000000u}; ts.tv_nsec = static_cast(unix_ts.subseconds / mul_factor); @@ -346,8 +347,8 @@ void sleep_until(::fast_io::basic_timestamp const &expect_time) no #else ::timespec now{}; ::fast_io::noexcept_call(::clock_gettime, CLOCK_REALTIME, __builtin_addressof(now)); - - if ((ts.tv_sec < now.tv_sec) || (ts.tv_sec == now.tv_sec && ts.tv_nsec <= now.tv_nsec)) + + if ((ts.tv_sec < now.tv_sec) || (ts.tv_sec == now.tv_sec && ts.tv_nsec <= now.tv_nsec)) { return; } @@ -359,11 +360,20 @@ void sleep_until(::fast_io::basic_timestamp const &expect_time) no delta.tv_nsec += 1'000'000'000L; delta.tv_sec -= 1; } - - ::fast_io::noexcept_call(::nanosleep, __builtin_addressof(delta), nullptr); + + ::fast_io::noexcept_call(::nanosleep, __builtin_addressof(delta), nullptr); #endif } +inline +#if __cpp_constexpr >= 202207L + constexpr +#endif + void yield() noexcept +{ + ::fast_io::noexcept_call(::sched_yield); +} + } // namespace this_thread } // namespace posix @@ -378,6 +388,7 @@ namespace this_thread using ::fast_io::posix::this_thread::get_id; using ::fast_io::posix::this_thread::sleep_for; using ::fast_io::posix::this_thread::sleep_until; +using ::fast_io::posix::this_thread::yield; } // namespace this_thread #endif diff --git a/include/fast_io_hosted/threads/thread/wasi.h b/include/fast_io_hosted/threads/thread/wasi.h index 29ec2ea26..8f5558533 100644 --- a/include/fast_io_hosted/threads/thread/wasi.h +++ b/include/fast_io_hosted/threads/thread/wasi.h @@ -264,6 +264,15 @@ void sleep_until(::fast_io::basic_timestamp const &expect_time) no ::fast_io::wasi::this_thread::sleep_for(delta); } +inline +#if __cpp_constexpr >= 202207L + constexpr +#endif +void yield() noexcept +{ + __wasi_sched_yield(); +} + } // namespace this_thread #if defined(__wasi_thread__) @@ -404,6 +413,7 @@ namespace this_thread using ::fast_io::wasi::this_thread::get_id; using ::fast_io::wasi::this_thread::sleep_for; using ::fast_io::wasi::this_thread::sleep_until; +using ::fast_io::wasi::this_thread::yield; } // namespace this_thread } // namespace fast_io diff --git a/include/fast_io_hosted/threads/thread/win32.h b/include/fast_io_hosted/threads/thread/win32.h index add5e8606..613a9147b 100644 --- a/include/fast_io_hosted/threads/thread/win32.h +++ b/include/fast_io_hosted/threads/thread/win32.h @@ -385,6 +385,21 @@ inline ::fast_io::win32::Sleep(ms); } +inline +#if __cpp_constexpr >= 202207L + // https://en.cppreference.com/w/cpp/compiler_support/23.html#cpp_constexpr_202207L + // for reduce some warning purpose + constexpr +#endif + void yield() noexcept +{ +#if (!defined(_WIN32_WINNT) || (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500)) && !defined(_WIN32_WINDOWS) + ::fast_io::win32::SwitchToThread(); +#else + ::fast_io::win32::Sleep(0); +#endif +} + } // namespace this_thread } // namespace win32 @@ -399,6 +414,7 @@ namespace this_thread using ::fast_io::win32::this_thread::get_id; using ::fast_io::win32::this_thread::sleep_for; using ::fast_io::win32::this_thread::sleep_until; +using ::fast_io::win32::this_thread::yield; } // namespace this_thread #endif } // namespace fast_io diff --git a/third-party/googletest b/third-party/googletest new file mode 160000 index 000000000..fa8438ae6 --- /dev/null +++ b/third-party/googletest @@ -0,0 +1 @@ +Subproject commit fa8438ae6b70c57010177de47a9f13d7041a6328 From 7bc9121574caf613258df93267cb667b206ea79b Mon Sep 17 00:00:00 2001 From: MacroModel Date: Tue, 23 Dec 2025 06:04:03 +0000 Subject: [PATCH 3/4] Fix yield function in dos.h to remove unnecessary parentheses for improved clarity and consistency. --- include/fast_io_hosted/threads/thread/dos.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fast_io_hosted/threads/thread/dos.h b/include/fast_io_hosted/threads/thread/dos.h index f56568835..d136510dd 100644 --- a/include/fast_io_hosted/threads/thread/dos.h +++ b/include/fast_io_hosted/threads/thread/dos.h @@ -134,7 +134,7 @@ inline #endif void yield() noexcept { - ::fast_io::noexcept_call(::__dpmi_yield()); + ::fast_io::noexcept_call(::__dpmi_yield); } } // namespace dos::this_thread From ed3b971adfb5bc2e0bb92555baa7d297eea1efdd Mon Sep 17 00:00:00 2001 From: MacroModel Date: Tue, 23 Dec 2025 06:12:20 +0000 Subject: [PATCH 4/4] Remove googletest submodule from third-party directory. --- third-party/googletest | 1 - 1 file changed, 1 deletion(-) delete mode 160000 third-party/googletest diff --git a/third-party/googletest b/third-party/googletest deleted file mode 160000 index fa8438ae6..000000000 --- a/third-party/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fa8438ae6b70c57010177de47a9f13d7041a6328