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:
@@ -1,4 +1,5 @@
|
|||||||
0.2:
|
0.2:
|
||||||
|
- Some race conditions eliminated, from PhracturedBlue
|
||||||
- Earth / other slave shielded planet color issue fixed, from PhracturedBlue
|
- Earth / other slave shielded planet color issue fixed, from PhracturedBlue
|
||||||
- Orbit/starmap related lockup fixed, from PhracturedBlue
|
- Orbit/starmap related lockup fixed, from PhracturedBlue
|
||||||
- 3D planet showing on starmap when in orbit fixed, from PhracturedBlue
|
- 3D planet showing on starmap when in orbit fixed, from PhracturedBlue
|
||||||
|
|||||||
@@ -27,11 +27,22 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#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
|
#ifdef THREAD_QUEUE
|
||||||
static volatile Thread threadQueue = NULL;
|
static volatile Thread threadQueue = NULL;
|
||||||
static Semaphore threadQueueSemaphore;
|
static Semaphore threadQueueSemaphore;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct ThreadStartInfo
|
struct ThreadStartInfo
|
||||||
{
|
{
|
||||||
ThreadFunction func;
|
ThreadFunction func;
|
||||||
@@ -307,25 +318,79 @@ DestroySemaphore (Semaphore sem)
|
|||||||
int
|
int
|
||||||
SetSemaphore (Semaphore sem)
|
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
|
int
|
||||||
TrySetSemaphore (Semaphore sem)
|
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
|
int
|
||||||
TimeoutSetSemaphore (Semaphore sem, TimePeriod timeout)
|
TimeoutSetSemaphore (Semaphore sem, TimePeriod timeout)
|
||||||
{
|
{
|
||||||
return NativeTimeoutSetSemaphore ((NativeSemaphore) sem,
|
int i;
|
||||||
timeout);
|
|
||||||
|
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
|
void
|
||||||
ClearSemaphore (Semaphore sem)
|
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);
|
NativeClearSemaphore ((NativeSemaphore) sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -539,6 +539,7 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS)
|
|||||||
|
|
||||||
BatchGraphics ();
|
BatchGraphics ();
|
||||||
DrawSISFrame ();
|
DrawSISFrame ();
|
||||||
|
SetSemaphore(GraphicsSem);
|
||||||
DrawSISMessage (GAME_STRING (STARBASE_STRING_BASE + 2));
|
DrawSISMessage (GAME_STRING (STARBASE_STRING_BASE + 2));
|
||||||
DrawSISTitle (GAME_STRING (STARBASE_STRING_BASE));
|
DrawSISTitle (GAME_STRING (STARBASE_STRING_BASE));
|
||||||
|
|
||||||
@@ -572,7 +573,6 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS)
|
|||||||
GLOBAL_SIS (ModuleSlots[num_frames])) < EMPTY_SLOT)
|
GLOBAL_SIS (ModuleSlots[num_frames])) < EMPTY_SLOT)
|
||||||
DrawShipPiece (pMS, which_piece, num_frames, FALSE);
|
DrawShipPiece (pMS, which_piece, num_frames, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
RedistributeFuel ();
|
RedistributeFuel ();
|
||||||
DisplayLanders (pMS);
|
DisplayLanders (pMS);
|
||||||
if (GET_GAME_STATE (CHMMR_BOMB_STATE) < 3)
|
if (GET_GAME_STATE (CHMMR_BOMB_STATE) < 3)
|
||||||
@@ -596,8 +596,11 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS)
|
|||||||
DrawStamp ((PSTAMP)&s);
|
DrawStamp ((PSTAMP)&s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClearSemaphore(GraphicsSem);
|
||||||
DrawMenuStateStrings (PM_FUEL, pMS->CurState);
|
DrawMenuStateStrings (PM_FUEL, pMS->CurState);
|
||||||
|
SetSemaphore(GraphicsSem);
|
||||||
DrawFlagshipName (FALSE);
|
DrawFlagshipName (FALSE);
|
||||||
|
ClearSemaphore(GraphicsSem);
|
||||||
|
|
||||||
{
|
{
|
||||||
RECT r;
|
RECT r;
|
||||||
|
|||||||
@@ -220,7 +220,9 @@ LastActivity = WON_LAST_BATTLE;
|
|||||||
BatchGraphics ();
|
BatchGraphics ();
|
||||||
ClearDrawable ();
|
ClearDrawable ();
|
||||||
FlushColorXForms ();
|
FlushColorXForms ();
|
||||||
|
SetSemaphore (GraphicsSem);
|
||||||
DrawStamp (&s);
|
DrawStamp (&s);
|
||||||
|
ClearSemaphore (GraphicsSem);
|
||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
|
|
||||||
FlushInput ();
|
FlushInput ();
|
||||||
|
|||||||
@@ -1070,9 +1070,10 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS)
|
|||||||
BatchGraphics ();
|
BatchGraphics ();
|
||||||
|
|
||||||
DrawSISFrame ();
|
DrawSISFrame ();
|
||||||
|
SetSemaphore(GraphicsSem);
|
||||||
DrawSISMessage (GAME_STRING (STARBASE_STRING_BASE + 3));
|
DrawSISMessage (GAME_STRING (STARBASE_STRING_BASE + 3));
|
||||||
DrawSISTitle (GAME_STRING (STARBASE_STRING_BASE));
|
DrawSISTitle (GAME_STRING (STARBASE_STRING_BASE));
|
||||||
|
ClearSemaphore(GraphicsSem);
|
||||||
DrawBluePrint (pMS);
|
DrawBluePrint (pMS);
|
||||||
pMS->ModuleFrame = s.frame;
|
pMS->ModuleFrame = s.frame;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user