Browse Source

Reorder dthread.cpp

pull/910/head
Anders Jenbo 5 years ago
parent
commit
a0476b45a0
  1. 76
      Source/dthread.cpp
  2. 4
      Source/dthread.h

76
Source/dthread.cpp

@ -15,6 +15,44 @@ HANDLE sghWorkToDoEvent;
/* rdata */
static HANDLE sghThread = INVALID_HANDLE_VALUE;
static unsigned int __stdcall dthread_handler(void *data)
{
const char *error_buf;
TMegaPkt *pkt;
DWORD dwMilliseconds;
while (dthread_running) {
if (!sgpInfoHead && WaitForSingleObject(sghWorkToDoEvent, INFINITE) == WAIT_FAILED) {
error_buf = TraceLastError();
app_fatal("dthread4:\n%s", error_buf);
}
sgMemCrit.Enter();
pkt = sgpInfoHead;
if (sgpInfoHead)
sgpInfoHead = sgpInfoHead->pNext;
else
ResetEvent(sghWorkToDoEvent);
sgMemCrit.Leave();
if (pkt) {
if (pkt->dwSpaceLeft != MAX_PLRS)
multi_send_zero_packet(pkt->dwSpaceLeft, pkt->data[0], &pkt->data[8], *(DWORD *)&pkt->data[4]);
dwMilliseconds = 1000 * *(DWORD *)&pkt->data[4] / gdwDeltaBytesSec;
if (dwMilliseconds >= 1)
dwMilliseconds = 1;
mem_free_dbg(pkt);
if (dwMilliseconds)
Sleep(dwMilliseconds);
}
}
return 0;
}
void dthread_remove_player(int pnum)
{
TMegaPkt *pkt;
@ -76,44 +114,6 @@ void dthread_start()
}
}
unsigned int __stdcall dthread_handler(void *data)
{
const char *error_buf;
TMegaPkt *pkt;
DWORD dwMilliseconds;
while (dthread_running) {
if (!sgpInfoHead && WaitForSingleObject(sghWorkToDoEvent, INFINITE) == WAIT_FAILED) {
error_buf = TraceLastError();
app_fatal("dthread4:\n%s", error_buf);
}
sgMemCrit.Enter();
pkt = sgpInfoHead;
if (sgpInfoHead)
sgpInfoHead = sgpInfoHead->pNext;
else
ResetEvent(sghWorkToDoEvent);
sgMemCrit.Leave();
if (pkt) {
if (pkt->dwSpaceLeft != MAX_PLRS)
multi_send_zero_packet(pkt->dwSpaceLeft, pkt->data[0], &pkt->data[8], *(DWORD *)&pkt->data[4]);
dwMilliseconds = 1000 * *(DWORD *)&pkt->data[4] / gdwDeltaBytesSec;
if (dwMilliseconds >= 1)
dwMilliseconds = 1;
mem_free_dbg(pkt);
if (dwMilliseconds)
Sleep(dwMilliseconds);
}
}
return 0;
}
void dthread_cleanup()
{
const char *error_buf;

4
Source/dthread.h

@ -6,13 +6,9 @@
#ifndef __DTHREAD_H__
#define __DTHREAD_H__
extern unsigned int glpDThreadId;
extern BOOLEAN dthread_running;
void dthread_remove_player(int pnum);
void dthread_send_delta(int pnum, char cmd, void *pbSrc, int dwLen);
void dthread_start();
unsigned int __stdcall dthread_handler(void *data);
void dthread_cleanup();
/* data */

Loading…
Cancel
Save