diff --git a/Frameworks/File_Extractor/File_Extractor/7z_C/posix/Threads.c b/Frameworks/File_Extractor/File_Extractor/7z_C/posix/Threads.c index 0a785c318..9b0c68984 100644 --- a/Frameworks/File_Extractor/File_Extractor/7z_C/posix/Threads.c +++ b/Frameworks/File_Extractor/File_Extractor/7z_C/posix/Threads.c @@ -61,7 +61,29 @@ WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled) { return Event_Crea WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) { return ManualResetEvent_Create(p, 0); } WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) { return AutoResetEvent_Create(p, 0); } +#ifdef __APPLE__ +WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount) +{ + p->sem = dispatch_semaphore_create( initCount ); + p->count = initCount; + p->maxCount = maxCount; + return 0; +} +static WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) +{ + if (previousCount) + { + *previousCount = p->count; + } + while (releaseCount--) + { + dispatch_semaphore_signal(p->sem); + IncrementAtomic(&p->count); + } + return 0; +} +#else WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount) { sem_init( &p->sem, 0, initCount ); @@ -81,6 +103,8 @@ static WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCo sem_post( &p->sem ); return 0; } +#endif + WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num) { return Semaphore_Release(p, (LONG)num, NULL); } WRes Semaphore_Release1(CSemaphore *p) { return Semaphore_ReleaseN(p, 1); } diff --git a/Frameworks/File_Extractor/File_Extractor/7z_C/posix/Threads.h b/Frameworks/File_Extractor/File_Extractor/7z_C/posix/Threads.h index fba44ca27..addf9fe12 100644 --- a/Frameworks/File_Extractor/File_Extractor/7z_C/posix/Threads.h +++ b/Frameworks/File_Extractor/File_Extractor/7z_C/posix/Threads.h @@ -7,7 +7,13 @@ #include "../Types.h" #include + +#ifdef __APPLE__ +#include +#include +#else #include +#endif #ifdef __cplusplus extern "C" { @@ -55,14 +61,23 @@ WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); typedef struct { +#ifdef __APPLE__ + dispatch_semaphore_t sem; + SInt32 count; +#else sem_t sem; +#endif UInt32 maxCount; } CSemaphore; #define Semaphore_Construct(p) #define Semaphore_Close(p) +#ifdef __APPLE__ +#define Semaphore_Wait(p) { DecrementAtomic(&((p)->count)); dispatch_semaphore_wait((p)->sem, DISPATCH_TIME_FOREVER); } +#else #define Semaphore_Wait(p) { sem_wait(&((p)->sem)); } +#endif WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount); WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); WRes Semaphore_Release1(CSemaphore *p); diff --git a/Frameworks/File_Extractor/File_Extractor/unrar/unrar.cpp b/Frameworks/File_Extractor/File_Extractor/unrar/unrar.cpp index 26eb56eae..410d2c97c 100644 --- a/Frameworks/File_Extractor/File_Extractor/unrar/unrar.cpp +++ b/Frameworks/File_Extractor/File_Extractor/unrar/unrar.cpp @@ -147,8 +147,10 @@ static unrar_err_t next_( unrar_t* p, bool skipping_solid ) if ( type != HEAD_FILE ) { // Skip non-files +#if 0 if ( type != HEAD_SERVICE && type != HEAD_CRYPT && type != HEAD_MARK ) debug_printf( "unrar: Skipping unknown block type: %X\n", (unsigned) type ); +#endif update_solid_pos( p ); }