Commit 42f1b866 authored by Jack Andersen's avatar Jack Andersen

Use blocking I/O for transfer thread

parent e161ef15
......@@ -132,13 +132,6 @@ class Endpoint
CMD_WRITE = 0x15
};
enum class EWaitResp
{
NoWait = 0,
WaitCmd,
WaitIdle
};
static const u64 BITS_PER_SECOND = 115200;
static const u64 BYTES_PER_SECOND = BITS_PER_SECOND / 8;
......@@ -147,16 +140,13 @@ class Endpoint
std::thread m_transferThread;
std::mutex m_syncLock;
std::condition_variable m_syncCv;
std::condition_variable m_issueCv;
std::experimental::optional<KawasedoChallenge> m_joyBoot;
FGBACallback m_callback;
EWaitResp m_waitingResp = EWaitResp::NoWait;
size_t m_dataReceivedBytes = 0;
u8 m_buffer[5];
u64 m_timeSent = 0;
u8* m_readDstPtr = nullptr;
u8* m_statusPtr = nullptr;
u64 m_lastGCTick = 0;
u64 m_timeCmdSent = 0;
u8 m_lastCmd = 0;
u8 m_chan;
bool m_booted = false;
......@@ -167,8 +157,8 @@ class Endpoint
void clockSync();
void send(const u8* buffer);
size_t receive(u8* buffer);
size_t runBuffer(u8* buffer, u64& remTicks, EWaitResp resp);
bool idleGetStatus(u64& remTicks);
size_t runBuffer(u8* buffer, std::unique_lock<std::mutex>& lk);
bool idleGetStatus(std::unique_lock<std::mutex>& lk);
void transferProc();
void transferWakeup(ThreadLocalEndpoint& endpoint, u8 status);
......
......@@ -367,7 +367,7 @@ public:
operator bool() const { return isOpen(); }
int GetInternalSocket() const { return m_socket; }
SocketTp GetInternalSocket() const { return m_socket; }
};
}
......
......@@ -51,8 +51,18 @@ void WaitGCTicks(u64 ticks)
tv.tv_usec = (ticks % GetGCTicksPerSec()) * 1000000 / GetGCTicksPerSec();
select(0, NULL, NULL, NULL, &tv);
#else
Sleep(ticks * 1000 / GetGCTicksPerSec() +
(ticks % GetGCTicksPerSec()) * 1000 / GetGCTicksPerSec());
if (ticks < GetGCTicksPerSec() / 60)
{
/* NT is useless for scheduling sub-millisecond intervals */
u64 start = GetGCTicks();
do { Sleep(0); } while (GetGCTicks() - start < ticks);
}
else
{
/* Use normal Sleep() for durations longer than ~16ms */
Sleep(ticks * 1000 / GetGCTicksPerSec() +
(ticks % GetGCTicksPerSec()) * 1000 / GetGCTicksPerSec());
}
#endif
}
......
This diff is collapsed.
......@@ -53,8 +53,9 @@ void Listener::listenerProc()
}
}
net::Socket acceptData = {false};
net::Socket acceptClock = {false};
/* We use blocking I/O since we have a dedicated transfer thread */
net::Socket acceptData = {true};
net::Socket acceptClock = {true};
std::string hostname;
u8 chan = 1;
while (m_running && chan < 4)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment