Hi,
I apologize, but I don’t have one. However, I don’t believe it would be a significant issue to port the C++ code to C#. I’m not an expert in C# but it can be something like this:
foreach (PFAST_IO_SECTION i in fast_io_section)
{
if (Interlocked.CompareExchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0, 0) != 0)
{
Interlocked.Exchange(ref i.fast_io_header.read_in_progress_flag, 1);
var write_union = Interlocked.CompareExchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0, 0);
uint current_packets_success = (uint)write_union.union_.split.number_of_packets;
//
// Copy packets and reset section
//
Buffer.BlockCopy(i.fast_io_packets, 0, packet_buffer_, (int)(fast_io_packets_success * Marshal.SizeOf<INTERMEDIATE_BUFFER>()), (int)(current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>());
// For the last packet(s) wait the write completion if in progress
write_union = Interlocked.CompareExchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0, 0);
while (write_union.union_.split.write_in_progress_flag != 0)
{
write_union = Interlocked.CompareExchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0, 0);
}
// Copy the last packet(s)
Buffer.BlockCopy(i.fast_io_packets, (int)(current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>(), packet_buffer_, (int)(fast_io_packets_success + current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>(), Marshal.SizeOf<INTERMEDIATE_BUFFER>());
if (current_packets_success < write_union.union_.split.number_of_packets)
{
current_packets_success = write_union.union_.split.number_of_packets;
Buffer.BlockCopy(i.fast_io_packets, (int)(current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>(), packet_buffer_, (int)(fast_io_packets_success + current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>(), Marshal.SizeOf<INTERMEDIATE_BUFFER>());
}
Interlocked.Exchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0);
Interlocked.Exchange(ref i.fast_io_header.read_in_progress_flag, 0);
fast_io_packets_success += current_packets_success;
}
}