Skip to content
Merged

Next #1247

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 106 additions & 22 deletions include/fast_io_hosted/platforms/win32/win32_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,49 +456,133 @@ using farproc = ::std::ptrdiff_t(FAST_IO_STDCALL *)() noexcept;

struct win32_memory_range_entry
{
void* VirtualAddress;
void *VirtualAddress;
::std::size_t NumberOfBytes;
};

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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 16 additions & 0 deletions include/fast_io_hosted/threads/thread/dos.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma once

// std
#include <chrono>
#include <ranges>
#include <cstdint>
#include <utility>
#include <functional>
#include <type_traits>
// system
#include <dpmi.h>

namespace fast_io
{
Expand Down Expand Up @@ -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__)
Expand All @@ -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

Expand Down
13 changes: 13 additions & 0 deletions include/fast_io_hosted/threads/thread/nt.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,18 @@ inline
}
}

template <bool zw = false>
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<zw>();
}

} // namespace this_thread

} // namespace win32::nt
Expand All @@ -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

Expand Down
Loading