Some race conditions eliminated, from PhracturedBlue

Also added debug information.


git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@417 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2002-12-12 23:00:33 +00:00
parent 10d3e7f43a
commit dda669080c
5 changed files with 78 additions and 6 deletions
+69 -4
View File
@@ -27,11 +27,22 @@
#include <unistd.h>
#endif
#define DEBUG_TRACK_SEM
#ifdef DEBUG_TRACK_SEM
// Define all semaphores to be tracked in SemList. Make sure it is NULL terminated
// Make that semthread is the same length as SemList, and is initialized as all 0's
extern Semaphore GraphicsSem;
static Semaphore *SemList[] = {&GraphicsSem, NULL};
Uint32 semthread[] = {0, 0};
#endif
#ifdef THREAD_QUEUE
static volatile Thread threadQueue = NULL;
static Semaphore threadQueueSemaphore;
#endif
struct ThreadStartInfo
{
ThreadFunction func;
@@ -307,25 +318,79 @@ DestroySemaphore (Semaphore sem)
int
SetSemaphore (Semaphore sem)
{
return NativeSetSemaphore ((NativeSemaphore) sem);
int i;
i = NativeSetSemaphore ((NativeSemaphore) sem);
#ifdef DEBUG_TRACK_SEM
if (i != 0)
fprintf(stderr, "WARNING: SetSemaphore did not return 0, this could be bad!\n");
for (i = 0; SemList[i] != NULL; i++)
if (*SemList[i] == sem)
{
semthread[i] = SDL_ThreadID ();
break;
}
#endif
return i;
}
int
TrySetSemaphore (Semaphore sem)
{
return NativeTrySetSemaphore ((NativeSemaphore) sem);
int i;
i = NativeTrySetSemaphore ((NativeSemaphore) sem);
#ifdef DEBUG_TRACK_SEM
if (i == 0)
for (i = 0; SemList[i] != NULL; i++)
if (*SemList[i] == sem)
{
semthread[i] = SDL_ThreadID ();
break;
}
#endif
return (i);
}
int
TimeoutSetSemaphore (Semaphore sem, TimePeriod timeout)
{
return NativeTimeoutSetSemaphore ((NativeSemaphore) sem,
timeout);
int i;
i = NativeTimeoutSetSemaphore ((NativeSemaphore) sem, timeout);
#ifdef DEBUG_TRACK_SEM
if (i == 0)
for (i = 0; SemList[i] != NULL; i++)
if (*SemList[i] == sem)
{
semthread[i] = SDL_ThreadID ();
break;
}
#endif
return (i);
}
void
ClearSemaphore (Semaphore sem)
{
int i;
#ifdef DEBUG_TRACK_SEM
Uint32 semval = SDL_SemValue (sem);
if (semval != 0)
{
fprintf (stderr, "WARNING: trying to clear a free semaphore (value=%d)\n", semval);
// Should we unset the Semaphore twice? Perhaps not.
return;
}
for (i = 0;SemList[i] != NULL; i++)
if (*SemList[i] == sem)
{
if (! semthread[i] && semthread[i] != SDL_ThreadID ())
fprintf( stderr, "WARNING: tried to free a Semaphore held by another thread!\n");
semthread[i] = 0;
break;
}
#endif
NativeClearSemaphore ((NativeSemaphore) sem);
}
+4 -1
View File
@@ -539,6 +539,7 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS)
BatchGraphics ();
DrawSISFrame ();
SetSemaphore(GraphicsSem);
DrawSISMessage (GAME_STRING (STARBASE_STRING_BASE + 2));
DrawSISTitle (GAME_STRING (STARBASE_STRING_BASE));
@@ -572,7 +573,6 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS)
GLOBAL_SIS (ModuleSlots[num_frames])) < EMPTY_SLOT)
DrawShipPiece (pMS, which_piece, num_frames, FALSE);
}
RedistributeFuel ();
DisplayLanders (pMS);
if (GET_GAME_STATE (CHMMR_BOMB_STATE) < 3)
@@ -596,8 +596,11 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS)
DrawStamp ((PSTAMP)&s);
}
ClearSemaphore(GraphicsSem);
DrawMenuStateStrings (PM_FUEL, pMS->CurState);
SetSemaphore(GraphicsSem);
DrawFlagshipName (FALSE);
ClearSemaphore(GraphicsSem);
{
RECT r;
+2
View File
@@ -220,7 +220,9 @@ LastActivity = WON_LAST_BATTLE;
BatchGraphics ();
ClearDrawable ();
FlushColorXForms ();
SetSemaphore (GraphicsSem);
DrawStamp (&s);
ClearSemaphore (GraphicsSem);
UnbatchGraphics ();
FlushInput ();
+2 -1
View File
@@ -1070,9 +1070,10 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS)
BatchGraphics ();
DrawSISFrame ();
SetSemaphore(GraphicsSem);
DrawSISMessage (GAME_STRING (STARBASE_STRING_BASE + 3));
DrawSISTitle (GAME_STRING (STARBASE_STRING_BASE));
ClearSemaphore(GraphicsSem);
DrawBluePrint (pMS);
pMS->ModuleFrame = s.frame;