diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/CdStream.cpp | 41 | ||||
-rw-r--r-- | src/core/CdStreamPosix.cpp | 82 | ||||
-rw-r--r-- | src/extras/shaders/colourfilterIII.frag | 2 | ||||
-rw-r--r-- | src/extras/shaders/colourfilterIII_PS.hlsl | 2 | ||||
-rw-r--r-- | src/extras/shaders/contrast.frag | 2 | ||||
-rw-r--r-- | src/extras/shaders/neoVehicle.vert | 2 | ||||
-rw-r--r-- | src/extras/shaders/neoVehicle_VS.hlsl | 2 | ||||
-rw-r--r-- | src/extras/shaders/obj/colourfilterIII_frag.inc | 2 | ||||
-rw-r--r-- | src/extras/shaders/obj/contrast_frag.inc | 2 | ||||
-rw-r--r-- | src/extras/shaders/obj/neoVehicle_vert.inc | 2 | ||||
-rw-r--r-- | src/skel/crossplatform.h | 7 |
11 files changed, 105 insertions, 41 deletions
diff --git a/src/core/CdStream.cpp b/src/core/CdStream.cpp index da85a238..977f16c2 100644 --- a/src/core/CdStream.cpp +++ b/src/core/CdStream.cpp @@ -14,9 +14,9 @@ struct CdReadInfo void *pBuffer; char field_C; bool bLocked; - bool bInUse; + bool bReading; int32 nStatus; - HANDLE hSemaphore; // used for CdStreamSync + HANDLE pDoneSemaphore; // used for CdStreamSync HANDLE hFile; OVERLAPPED Overlapped; }; @@ -53,9 +53,9 @@ CdStreamInitThread(void) { for ( int32 i = 0; i < gNumChannels; i++ ) { - gpReadInfo[i].hSemaphore = CreateSemaphore(nil, 0, 2, nil); + gpReadInfo[i].pDoneSemaphore = CreateSemaphore(nil, 0, 2, nil); - if ( gpReadInfo[i].hSemaphore == nil ) + if ( gpReadInfo[i].pDoneSemaphore == nil ) { printf("%s: failed to create sync semaphore\n", "cdvd_stream"); ASSERT(0); @@ -183,7 +183,7 @@ CdStreamShutdown(void) CloseHandle(_gCdStreamThread); for ( int32 i = 0; i < gNumChannels; i++ ) - CloseHandle(gpReadInfo[i].hSemaphore); + CloseHandle(gpReadInfo[i].pDoneSemaphore); } LocalFree(gpReadInfo); @@ -213,7 +213,7 @@ CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size) if ( _gbCdStreamAsync ) { - if ( pChannel->nSectorsToRead != 0 || pChannel->bInUse ) + if ( pChannel->nSectorsToRead != 0 || pChannel->bReading ) return STREAM_NONE; pChannel->nStatus = STREAM_NONE; @@ -271,7 +271,7 @@ CdStreamGetStatus(int32 channel) if ( _gbCdStreamAsync ) { - if ( pChannel->bInUse ) + if ( pChannel->bReading ) return STREAM_READING; if ( pChannel->nSectorsToRead != 0 ) @@ -321,12 +321,21 @@ CdStreamSync(int32 channel) { pChannel->bLocked = true; - ASSERT( pChannel->hSemaphore != nil ); + ASSERT( pChannel->pDoneSemaphore != nil ); - WaitForSingleObject(pChannel->hSemaphore, INFINITE); + // Deadlock fix 1 +#ifdef FIX_BUGS + // This is while loop on Posix streamer, for spurious wakeups + if (pChannel->bLocked && pChannel->nSectorsToRead != 0){ + WaitForSingleObject(pChannel->pDoneSemaphore, INFINITE); + } + pChannel->bLocked = false; +#else + WaitForSingleObject(pChannel->pDoneSemaphore, INFINITE); +#endif } - pChannel->bInUse = false; + pChannel->bReading = false; return pChannel->nStatus; } @@ -398,7 +407,7 @@ WINAPI CdStreamThread(LPVOID lpThreadParameter) CdReadInfo *pChannel = &gpReadInfo[channel]; ASSERT( pChannel != nil ); - pChannel->bInUse = true; + pChannel->bReading = true; if ( pChannel->nStatus == STREAM_NONE ) { @@ -455,11 +464,15 @@ WINAPI CdStreamThread(LPVOID lpThreadParameter) if ( pChannel->bLocked ) { - ASSERT( pChannel->hSemaphore != nil ); - ReleaseSemaphore(pChannel->hSemaphore, 1, NULL); + ASSERT( pChannel->pDoneSemaphore != nil ); + // Deadlock fix 2 +#ifdef FIX_BUGS + pChannel->bLocked = 0; +#endif + ReleaseSemaphore(pChannel->pDoneSemaphore, 1, NULL); } - pChannel->bInUse = false; + pChannel->bReading = false; } } diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index e18280e5..30fe06a0 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -1,8 +1,8 @@ #ifndef _WIN32 #include "common.h" #include "crossplatform.h" -#include <pthread.h> #include <signal.h> +#include <pthread.h> #include <semaphore.h> #include <sys/types.h> #include <unistd.h> @@ -12,7 +12,11 @@ #include <sys/stat.h> #include <fcntl.h> #include <sys/resource.h> +#include <stdarg.h> + +#ifdef __linux__ #include <sys/syscall.h> +#endif #include "CdStream.h" #include "rwcore.h" @@ -25,6 +29,58 @@ bool flushStream[MAX_CDCHANNELS]; #endif +#ifdef USE_UNNAMED_SEM + +#define RE3_SEM_OPEN(name, ...) re3_sem_open() +sem_t* +re3_sem_open(void) +{ + sem_t* sem = (sem_t*)malloc(sizeof(sem_t)); + if (sem_init(sem, 0, 1) == -1) { + sem = SEM_FAILED; + } + + return sem; +} + +#define RE3_SEM_CLOSE(sem, format, ...) re3_sem_close(sem) +void +re3_sem_close(sem_t* sem) +{ + sem_destroy(sem); + free(sem); +} + +#else + +#define RE3_SEM_OPEN re3_sem_open +sem_t* +re3_sem_open(const char* format, ...) +{ + char semName[21]; + va_list va; + va_start(va, format); + vsprintf(semName, format, va); + + return sem_open(semName, O_CREAT, 0644, 1); +} + +#define RE3_SEM_CLOSE re3_sem_close +void +re3_sem_close(sem_t* sem, const char* format, ...) +{ + sem_close(sem); + + char semName[21]; + va_list va; + va_start(va, format); + vsprintf(semName, format, va); + + sem_unlink(semName); +} + +#endif + struct CdReadInfo { uint32 nSectorOffset; @@ -69,14 +125,13 @@ void CdStreamInitThread(void) { int status; - char semName[20]; #ifndef ONE_THREAD_PER_CHANNEL gChannelRequestQ.items = (int32 *)calloc(gNumChannels + 1, sizeof(int32)); gChannelRequestQ.head = 0; gChannelRequestQ.tail = 0; gChannelRequestQ.size = gNumChannels + 1; ASSERT(gChannelRequestQ.items != nil ); - gCdStreamSema = sem_open("/semaphore_cd_stream", O_CREAT, 0644, 0); + gCdStreamSema = RE3_SEM_OPEN("/semaphore_cd_stream"); if (gCdStreamSema == SEM_FAILED) { @@ -90,8 +145,7 @@ CdStreamInitThread(void) { for ( int32 i = 0; i < gNumChannels; i++ ) { - sprintf(semName,"/semaphore_done%d",i); - gpReadInfo[i].pDoneSemaphore = sem_open(semName, O_CREAT, 0644, 0); + gpReadInfo[i].pDoneSemaphore = RE3_SEM_OPEN("/semaphore_done%d", i); if (gpReadInfo[i].pDoneSemaphore == SEM_FAILED) { @@ -101,8 +155,7 @@ CdStreamInitThread(void) } #ifdef ONE_THREAD_PER_CHANNEL - sprintf(semName,"/semaphore_start%d",i); - gpReadInfo[i].pStartSemaphore = sem_open(semName, O_CREAT, 0644, 0); + gpReadInfo[i].pStartSemaphore = RE3_SEM_OPEN("/semaphore_start%d", i); if (gpReadInfo[i].pStartSemaphore == SEM_FAILED) { @@ -464,21 +517,14 @@ void *CdStreamThread(void *param) #ifndef ONE_THREAD_PER_CHANNEL for ( int32 i = 0; i < gNumChannels; i++ ) { - sem_close(gpReadInfo[i].pDoneSemaphore); - sprintf(semName,"/semaphore_done%d",i); - sem_unlink(semName); + RE3_SEM_CLOSE(gpReadInfo[i].pDoneSemaphore, "/semaphore_done%d", i); } - sem_close(gCdStreamSema); - sem_unlink("/semaphore_cd_stream"); + RE3_SEM_CLOSE(gCdStreamSema, "/semaphore_cd_stream"); free(gChannelRequestQ.items); #else - sem_close(gpReadInfo[channel].pStartSemaphore); - sprintf(semName,"/semaphore_start%d",channel); - sem_unlink(semName); + RE3_SEM_CLOSE(gpReadInfo[channel].pStartSemaphore, "/semaphore_start%d", channel); - sem_close(gpReadInfo[channel].pDoneSemaphore); - sprintf(semName,"/semaphore_done%d",channel); - sem_unlink(semName); + RE3_SEM_CLOSE(gpReadInfo[channel].pDoneSemaphore, "/semaphore_done%d", channel); #endif if (gpReadInfo) free(gpReadInfo); diff --git a/src/extras/shaders/colourfilterIII.frag b/src/extras/shaders/colourfilterIII.frag index b41cb94a..95e5d052 100644 --- a/src/extras/shaders/colourfilterIII.frag +++ b/src/extras/shaders/colourfilterIII.frag @@ -17,7 +17,7 @@ main(void) } vec4 color; color.rgb = prev.rgb; - color.a = 1.0f; + color.a = 1.0; FRAGCOLOR(color); } diff --git a/src/extras/shaders/colourfilterIII_PS.hlsl b/src/extras/shaders/colourfilterIII_PS.hlsl index 27f099ef..3d893c3c 100644 --- a/src/extras/shaders/colourfilterIII_PS.hlsl +++ b/src/extras/shaders/colourfilterIII_PS.hlsl @@ -10,6 +10,6 @@ float4 main(in float2 texcoord : TEXCOORD0) : COLOR0 float4 tmp = dst*(1-a) + prev*blurcol*a; prev = saturate(tmp); } - prev.a = 1.0f; + prev.a = 1.0; return prev; } diff --git a/src/extras/shaders/contrast.frag b/src/extras/shaders/contrast.frag index 1b93f6fe..2d394f66 100644 --- a/src/extras/shaders/contrast.frag +++ b/src/extras/shaders/contrast.frag @@ -12,7 +12,7 @@ main(void) vec4 dst = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); vec4 color; color.rgb = dst.rgb*u_contrastMult + u_contrastAdd; - color.a = 1.0f; + color.a = 1.0; FRAGCOLOR(color); } diff --git a/src/extras/shaders/neoVehicle.vert b/src/extras/shaders/neoVehicle.vert index f0224ddb..6985a689 100644 --- a/src/extras/shaders/neoVehicle.vert +++ b/src/extras/shaders/neoVehicle.vert @@ -42,7 +42,7 @@ main(void) v_tex1 = uv2.xy*0.5 + 0.5; float b = 1.0 - clamp(dot(viewVec, Normal), 0.0, 1.0); v_reflcolor = vec4(0.0, 0.0, 0.0, 1.0); - v_reflcolor.a = mix(b*b*b*b*b, 1.0f, fresnel)*shininess; + v_reflcolor.a = mix(b*b*b*b*b, 1.0, fresnel)*shininess; for(int i = 0; i < 5; i++) v_reflcolor.rgb += DoDirLightSpec(u_specDir[i].xyz, u_specColor[i].rgb, Normal, viewVec, u_specDir[i].w)*specularity*lightStrength; diff --git a/src/extras/shaders/neoVehicle_VS.hlsl b/src/extras/shaders/neoVehicle_VS.hlsl index de75e745..fb730092 100644 --- a/src/extras/shaders/neoVehicle_VS.hlsl +++ b/src/extras/shaders/neoVehicle_VS.hlsl @@ -52,7 +52,7 @@ VS_out main(in VS_in input) output.TexCoord1 = uv2.xy*0.5 + 0.5; float b = 1.0 - saturate(dot(viewVec, Normal)); output.ReflColor = float4(0.0, 0.0, 0.0, 1.0); - output.ReflColor.a = lerp(b*b*b*b*b, 1.0f, fresnel)*shininess; + output.ReflColor.a = lerp(b*b*b*b*b, 1.0, fresnel)*shininess; //Light mainLight = lights[0]; for(i = 0; i < 5; i++) diff --git a/src/extras/shaders/obj/colourfilterIII_frag.inc b/src/extras/shaders/obj/colourfilterIII_frag.inc index 6fd1935b..05f92785 100644 --- a/src/extras/shaders/obj/colourfilterIII_frag.inc +++ b/src/extras/shaders/obj/colourfilterIII_frag.inc @@ -18,7 +18,7 @@ const char *colourfilterIII_frag_src = " }\n" " vec4 color;\n" " color.rgb = prev.rgb;\n" -" color.a = 1.0f;\n" +" color.a = 1.0;\n" " FRAGCOLOR(color);\n" "}\n" diff --git a/src/extras/shaders/obj/contrast_frag.inc b/src/extras/shaders/obj/contrast_frag.inc index 97f78194..a1ad479f 100644 --- a/src/extras/shaders/obj/contrast_frag.inc +++ b/src/extras/shaders/obj/contrast_frag.inc @@ -13,7 +13,7 @@ const char *contrast_frag_src = " vec4 dst = texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" " vec4 color;\n" " color.rgb = dst.rgb*u_contrastMult + u_contrastAdd;\n" -" color.a = 1.0f;\n" +" color.a = 1.0;\n" " FRAGCOLOR(color);\n" "}\n" diff --git a/src/extras/shaders/obj/neoVehicle_vert.inc b/src/extras/shaders/obj/neoVehicle_vert.inc index b7b42622..ebd0ea12 100644 --- a/src/extras/shaders/obj/neoVehicle_vert.inc +++ b/src/extras/shaders/obj/neoVehicle_vert.inc @@ -43,7 +43,7 @@ const char *neoVehicle_vert_src = " v_tex1 = uv2.xy*0.5 + 0.5;\n" " float b = 1.0 - clamp(dot(viewVec, Normal), 0.0, 1.0);\n" " v_reflcolor = vec4(0.0, 0.0, 0.0, 1.0);\n" -" v_reflcolor.a = mix(b*b*b*b*b, 1.0f, fresnel)*shininess;\n" +" v_reflcolor.a = mix(b*b*b*b*b, 1.0, fresnel)*shininess;\n" " for(int i = 0; i < 5; i++)\n" " v_reflcolor.rgb += DoDirLightSpec(u_specDir[i].xyz, u_specColor[i].rgb, Normal, viewVec, u_specDir[i].w)*specularity*lightStrength;\n" diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h index e5f4c7ba..710a7702 100644 --- a/src/skel/crossplatform.h +++ b/src/skel/crossplatform.h @@ -132,7 +132,12 @@ void GetLocalTime_CP(SYSTEMTIME* out); typedef void* HANDLE; #define INVALID_HANDLE_VALUE NULL -#define FindClose(h) closedir((DIR*)h) +#define FindClose(h) \ + do { \ + if (h != nil) \ + closedir((DIR*)h); \ + } while(0) + #define LOCALE_USER_DEFAULT 0 #define DATE_SHORTDATE 0 |