Skip to content

Commit

Permalink
Renamed mutex routines to Sys_Lock and Sys_Unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 9, 2003
1 parent 3b62241 commit 0e173d8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions doomsday/Include/sys_system.h
Expand Up @@ -45,7 +45,7 @@ void Sys_SuspendThread(int handle, boolean dopause);
boolean Sys_GetThreadExitCode(int handle, uint *exitCode);
int Sys_CreateMutex(const char *name);
void Sys_DestroyMutex(int handle);
void Sys_AcquireMutex(int handle);
void Sys_ReleaseMutex(int handle);
void Sys_Lock(int handle);
void Sys_Unlock(int handle);

#endif
22 changes: 11 additions & 11 deletions doomsday/Src/dd_input.c
Expand Up @@ -169,7 +169,7 @@ static char defaultShiftTable[96] = // Contains characters 32 to 127.

static boolean stopInputThread = false;
static int inputThreadHandle;
static int eventQueueMutex;
static int eventQueueLock;

static repeater_t keyReps[MAX_DOWNKEYS];
static int oldMouseX, oldMouseY;
Expand Down Expand Up @@ -364,7 +364,7 @@ void DD_ProcessEvents(void)

// No new events will be posted until the currently queued ones
// have been processed.
Sys_AcquireMutex(eventQueueMutex);
Sys_Lock(eventQueueLock);

for(; eventTail != eventHead; eventTail = (++eventTail)&(MAXEVENTS-1))
{
Expand Down Expand Up @@ -406,21 +406,21 @@ void DD_ProcessEvents(void)
}

// New events can be posted again.
Sys_ReleaseMutex(eventQueueMutex);
Sys_Unlock(eventQueueLock);
}

/*
* Clear the input event queue.
*/
void DD_ClearEvents(void)
{
Sys_AcquireMutex(eventQueueMutex);
Sys_Lock(eventQueueLock);

eventHead = eventTail;
eventCount = 0;

// New events can be posted again.
Sys_ReleaseMutex(eventQueueMutex);
Sys_Unlock(eventQueueLock);
}

/*
Expand All @@ -432,13 +432,13 @@ void DD_PostEvent(event_t *ev)
if(eventCount == MAXEVENTS - 1) return;

// Only one thread can access the queue at a time.
Sys_AcquireMutex(eventQueueMutex);
Sys_Lock(eventQueueLock);

events[eventHead] = *ev;
eventHead = (++eventHead) & (MAXEVENTS - 1);
eventCount++;

Sys_ReleaseMutex(eventQueueMutex);
Sys_Unlock(eventQueueLock);
}

//===========================================================================
Expand Down Expand Up @@ -777,7 +777,7 @@ int DD_InputThread(void *parm)

// Generate ticcmds for local players.
for(i = 0; i < DDMAXPLAYERS; i++)
if(players[i].ingame && players[i].flags && DDPF_LOCAL)
if(Net_IsLocalPlayer(i))
{
// Build a command for this player.
P_BuildCommand(i);
Expand Down Expand Up @@ -827,7 +827,7 @@ void DD_InitInput(void)
// A mutex is used to control access to the event queue. The input
// threads writes to the queue and the refresh queue reads events
// from it.
eventQueueMutex = Sys_CreateMutex("EventQueueMutex");
eventQueueLock = Sys_CreateMutex("EventQueueMutex");

DD_DefaultKeyMapping();
}
Expand All @@ -839,6 +839,6 @@ void DD_ShutdownInput(void)
{
DD_StopInput();

Sys_DestroyMutex(eventQueueMutex);
eventQueueMutex = 0;
Sys_DestroyMutex(eventQueueLock);
eventQueueLock = 0;
}
10 changes: 5 additions & 5 deletions doomsday/Src/net_main.c
Expand Up @@ -381,23 +381,23 @@ void Net_NewLocalCmd(ticcmd_t *cmd, int pNum)
client_t *cl = clients + pNum;

// Acquire exclusive usage on the local buffer.
Sys_AcquireMutex(cl->localCmdLock);
Sys_Lock(cl->localCmdLock);

if(cl->numLocal != LOCALTICS)
{
// Copy the new command into the buffer.
memcpy(&cl->localCmds[TICCMD_IDX(cl->numLocal++)], cmd, TICCMD_SIZE);
}

Sys_ReleaseMutex(cl->localCmdLock);
Sys_Unlock(cl->localCmdLock);
}

/*
* Returns true if the specified player is a real local player.
*/
boolean Net_IsLocalPlayer(int pNum)
{
return players[pNum].ingame && (players[pNum].flags & DDPF_LOCAL);
return players[pNum].ingame && players[pNum].flags & DDPF_LOCAL;
}

/*
Expand All @@ -417,7 +417,7 @@ void Net_SendCommandsToServer(timespan_t time)
{
if(!Net_IsLocalPlayer(i)) continue;

Sys_AcquireMutex(clients[i].localCmdLock);
Sys_Lock(clients[i].localCmdLock);

// The game will pack the commands into a buffer. The returned
// pointer points to a buffer that contains its size and the
Expand All @@ -433,7 +433,7 @@ void Net_SendCommandsToServer(timespan_t time)

// The buffer is cleared.
clients[i].numLocal = 0;
Sys_ReleaseMutex(clients[i].localCmdLock);
Sys_Unlock(clients[i].localCmdLock);
}
}

Expand Down
11 changes: 7 additions & 4 deletions doomsday/Src/sys_network.cpp
Expand Up @@ -38,6 +38,9 @@

/*
* $Log$
* Revision 1.8 2003/09/09 21:38:24 skyjake
* Renamed mutex routines to Sys_Lock and Sys_Unlock
*
* Revision 1.7 2003/09/08 22:19:40 skyjake
* Float timing loop, use timespan_t in tickers, style cleanup
*
Expand Down Expand Up @@ -690,7 +693,7 @@ void N_SMSReset(store_t *store)
void N_PostMessage(netmessage_t *msg)
{
// Lock the message queue.
Sys_AcquireMutex(gMsgMutex);
Sys_Lock(gMsgMutex);

// This will be the latest message.
msg->next = NULL;
Expand All @@ -707,7 +710,7 @@ void N_PostMessage(netmessage_t *msg)
// If there is no head, this'll be the first message.
if(gMsgHead == NULL) gMsgHead = msg;

Sys_ReleaseMutex(gMsgMutex);
Sys_Unlock(gMsgMutex);
}

/*
Expand All @@ -721,7 +724,7 @@ netmessage_t* N_GetMessage(void)
{
if(gMsgHead == NULL) return NULL;

Sys_AcquireMutex(gMsgMutex);
Sys_Lock(gMsgMutex);

// This is the message we'll return.
netmessage_t *msg = gMsgHead;
Expand All @@ -732,7 +735,7 @@ netmessage_t* N_GetMessage(void)
// Advance the head pointer.
gMsgHead = gMsgHead->next;

Sys_ReleaseMutex(gMsgMutex);
Sys_Unlock(gMsgMutex);

// Identify the sender.
msg->player = N_IdentifyPlayer(msg->sender);
Expand Down
8 changes: 4 additions & 4 deletions doomsday/Src/sys_system.c
Expand Up @@ -336,10 +336,10 @@ void Sys_DestroyMutex(int handle)
/*
* Acquire a mutex. Blocks until ownership has been acquired.
*/
void Sys_AcquireMutex(int handle)
void Sys_Lock(int mutexHandle)
{
// Five seconds is plenty.
if(WaitForSingleObject((HANDLE)handle, 5000) == WAIT_TIMEOUT)
if(WaitForSingleObject((HANDLE)mutexHandle, 5000) == WAIT_TIMEOUT)
{
// Couldn't lock it.
#ifdef _DEBUG
Expand All @@ -351,7 +351,7 @@ void Sys_AcquireMutex(int handle)
/*
* Release a mutex.
*/
void Sys_ReleaseMutex(int handle)
void Sys_Unlock(int mutexHandle)
{
ReleaseMutex((HANDLE)handle);
ReleaseMutex((HANDLE)mutexHandle);
}

0 comments on commit 0e173d8

Please sign in to comment.