Locking fix. Also change the locking behaviour of DMS_SetMode, to avoid repeated locks/unlocks and make the code invoking this function a bit cleaner.
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3740 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
+15
-11
@@ -606,6 +606,7 @@ DMS_FlashEscortShipCrewCount (BYTE slotNr)
|
|||||||
|
|
||||||
// Helper function for DoModifyShips(). Called to change the flash
|
// Helper function for DoModifyShips(). Called to change the flash
|
||||||
// rectangle to the currently selected ship (flagship or escort ship).
|
// rectangle to the currently selected ship (flagship or escort ship).
|
||||||
|
// The caller must hold the graphicsLock.
|
||||||
static void
|
static void
|
||||||
DMS_FlashActiveShip (MENU_STATE *pMS)
|
DMS_FlashActiveShip (MENU_STATE *pMS)
|
||||||
{
|
{
|
||||||
@@ -626,10 +627,10 @@ DMS_FlashActiveShip (MENU_STATE *pMS)
|
|||||||
// XXX: right now, this only switches the sound and flash rectangle.
|
// XXX: right now, this only switches the sound and flash rectangle.
|
||||||
// Perhaps we should move more of the code to modify other aspects
|
// Perhaps we should move more of the code to modify other aspects
|
||||||
// here too.
|
// here too.
|
||||||
|
// The caller must hold the graphicsLock.
|
||||||
static void
|
static void
|
||||||
DMS_SetMode (MENU_STATE *pMS, DMS_Mode mode)
|
DMS_SetMode (MENU_STATE *pMS, DMS_Mode mode)
|
||||||
{
|
{
|
||||||
LockMutex (GraphicsLock);
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case DMS_Mode_navigate:
|
case DMS_Mode_navigate:
|
||||||
SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT);
|
SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT);
|
||||||
@@ -658,7 +659,6 @@ DMS_SetMode (MENU_STATE *pMS, DMS_Mode mode)
|
|||||||
SetFlashRect (SFR_MENU_3DO);
|
SetFlashRect (SFR_MENU_3DO);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
UnlockMutex (GraphicsLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MODIFY_CREW_FLAG (1 << 8)
|
#define MODIFY_CREW_FLAG (1 << 8)
|
||||||
@@ -960,8 +960,8 @@ DMS_TryAddEscortShip (MENU_STATE *pMS)
|
|||||||
LockMutex (GraphicsLock);
|
LockMutex (GraphicsLock);
|
||||||
DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA,
|
DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA,
|
||||||
-((int)ShipCost[Index]));
|
-((int)ShipCost[Index]));
|
||||||
UnlockMutex (GraphicsLock);
|
|
||||||
DMS_SetMode (pMS, DMS_Mode_editCrew);
|
DMS_SetMode (pMS, DMS_Mode_editCrew);
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -986,7 +986,9 @@ DMS_AddEscortShip (MENU_STATE *pMS, BOOLEAN special, BOOLEAN select,
|
|||||||
{
|
{
|
||||||
HSHIPFRAG hStarShip = GetEscortByStarShipIndex (pMS->delta_item);
|
HSHIPFRAG hStarShip = GetEscortByStarShipIndex (pMS->delta_item);
|
||||||
DMS_SpinShip (pMS, hStarShip);
|
DMS_SpinShip (pMS, hStarShip);
|
||||||
|
LockMutex (GraphicsLock);
|
||||||
DMS_SetMode (pMS, DMS_Mode_addEscort);
|
DMS_SetMode (pMS, DMS_Mode_addEscort);
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -1002,7 +1004,9 @@ DMS_AddEscortShip (MENU_STATE *pMS, BOOLEAN special, BOOLEAN select,
|
|||||||
SetFlashRect (SFR_MENU_3DO);
|
SetFlashRect (SFR_MENU_3DO);
|
||||||
UnlockMutex (GraphicsLock);
|
UnlockMutex (GraphicsLock);
|
||||||
DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);
|
DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);
|
||||||
|
LockMutex (GraphicsLock);
|
||||||
DMS_SetMode (pMS, DMS_Mode_navigate);
|
DMS_SetMode (pMS, DMS_Mode_navigate);
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
}
|
}
|
||||||
else if (select)
|
else if (select)
|
||||||
{
|
{
|
||||||
@@ -1059,9 +1063,7 @@ DMS_ScrapEscortShip (MENU_STATE *pMS, HSHIPFRAG hStarShip)
|
|||||||
DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA);
|
DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA);
|
||||||
|
|
||||||
SetContext (SpaceContext);
|
SetContext (SpaceContext);
|
||||||
UnlockMutex (GraphicsLock);
|
|
||||||
DMS_SetMode (pMS, DMS_Mode_navigate);
|
DMS_SetMode (pMS, DMS_Mode_navigate);
|
||||||
LockMutex (GraphicsLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function for DoModifyShips(), called when the player presses
|
// Helper function for DoModifyShips(), called when the player presses
|
||||||
@@ -1131,7 +1133,9 @@ DMS_EditCrewMode (MENU_STATE *pMS, HSHIPFRAG hStarShip,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pMS->delta_item &= ~MODIFY_CREW_FLAG;
|
pMS->delta_item &= ~MODIFY_CREW_FLAG;
|
||||||
|
LockMutex (GraphicsLock);
|
||||||
DMS_SetMode (pMS, DMS_Mode_navigate);
|
DMS_SetMode (pMS, DMS_Mode_navigate);
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
}
|
}
|
||||||
else if (dy)
|
else if (dy)
|
||||||
{
|
{
|
||||||
@@ -1176,11 +1180,11 @@ DMS_NavigateShipSlots (MENU_STATE *pMS, BOOLEAN special, BOOLEAN select,
|
|||||||
{
|
{
|
||||||
// Select button was pressed over an empty escort
|
// Select button was pressed over an empty escort
|
||||||
// ship slot. Switch to 'add escort ship' mode.
|
// ship slot. Switch to 'add escort ship' mode.
|
||||||
UnlockMutex (GraphicsLock);
|
|
||||||
pMS->delta_item = MODIFY_CREW_FLAG;
|
pMS->delta_item = MODIFY_CREW_FLAG;
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
DrawRaceStrings (pMS, 0);
|
DrawRaceStrings (pMS, 0);
|
||||||
DMS_SetMode (pMS, DMS_Mode_addEscort);
|
|
||||||
LockMutex (GraphicsLock);
|
LockMutex (GraphicsLock);
|
||||||
|
DMS_SetMode (pMS, DMS_Mode_addEscort);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1193,12 +1197,12 @@ DMS_NavigateShipSlots (MENU_STATE *pMS, BOOLEAN special, BOOLEAN select,
|
|||||||
else if (cancel)
|
else if (cancel)
|
||||||
{
|
{
|
||||||
// Leave escort ship editor.
|
// Leave escort ship editor.
|
||||||
UnlockMutex (GraphicsLock);
|
|
||||||
pMS->InputFunc = DoShipyard;
|
pMS->InputFunc = DoShipyard;
|
||||||
pMS->CurState = SHIPYARD_CREW;
|
pMS->CurState = SHIPYARD_CREW;
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
DrawMenuStateStrings (PM_CREW, pMS->CurState);
|
DrawMenuStateStrings (PM_CREW, pMS->CurState);
|
||||||
DMS_SetMode (pMS, DMS_Mode_exit);
|
|
||||||
LockMutex (GraphicsLock);
|
LockMutex (GraphicsLock);
|
||||||
|
DMS_SetMode (pMS, DMS_Mode_exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1225,10 +1229,10 @@ DoModifyShips (MENU_STATE *pMS)
|
|||||||
pMS->CurState = MAKE_BYTE (0, 0xF);
|
pMS->CurState = MAKE_BYTE (0, 0xF);
|
||||||
pMS->delta_item = 0;
|
pMS->delta_item = 0;
|
||||||
|
|
||||||
DMS_SetMode (pMS, DMS_Mode_navigate);
|
|
||||||
LockMutex (GraphicsLock);
|
LockMutex (GraphicsLock);
|
||||||
SetContext (SpaceContext);
|
SetContext (SpaceContext);
|
||||||
DMS_SetMode (pMS, DMS_Mode_navigate);
|
DMS_SetMode (pMS, DMS_Mode_navigate);
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1271,9 +1275,9 @@ DoModifyShips (MENU_STATE *pMS)
|
|||||||
DMS_EditCrewMode (pMS, hStarShip, select, cancel, dy);
|
DMS_EditCrewMode (pMS, hStarShip, select, cancel, dy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
UnlockMutex (GraphicsLock);
|
UnlockMutex (GraphicsLock);
|
||||||
|
}
|
||||||
|
|
||||||
SleepThread (ONE_SECOND / 30);
|
SleepThread (ONE_SECOND / 30);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user