Index: loader/win32.c =================================================================== --- loader/win32.c.orig 2007-02-15 09:53:20.000000000 -0800 +++ loader/win32.c 2007-02-15 09:54:06.000000000 -0800 @@ -807,8 +807,22 @@ while (pp && (pp->pm != ml->pm)) pp = pp->prev; if (!pp) { - dbgprintf("WaitForSingleObject: NotFound\n"); - return (void*)ret; + pthread_t *thread = (pthread_t *)object; + th_list *th = list; + int rc; + while(th && (th->thread != (void *)thread)) + th = th->prev; + if (!th) { + dbgprintf("WaitForSingleObject: NotFound\n"); + return (void*)ret; + } + rc = pthread_join(*thread, NULL); + if (! rc) { + dbgprintf("WaitForSingleObject: Thread exited\n"); + return (void *)WAIT_OBJECT_0; + } + dbgprintf("WaitForSingleObject: Thread failed to exit: %d\n", rc); + return (void *)ret; } pthread_mutex_lock(ml->pm); @@ -841,18 +855,49 @@ } break; case 1: /* Semaphore */ + if(ml->semaphore != 0) { + ret = WAIT_OBJECT_0; + ml->semaphore--; + break; + } if (duration == 0) { - if(ml->semaphore==0) ret = WAIT_FAILED; - else { - ml->semaphore++; - ret = WAIT_OBJECT_0; - } + ret = WAIT_FAILED; + break; } if (duration == -1) { - if (ml->semaphore==0) + while(ml->semaphore==0) { pthread_cond_wait(ml->pc,ml->pm); - ml->semaphore--; - } + } + ml->semaphore--; + ret = WAIT_OBJECT_0; + } else { + int rc = 0; + struct timespec tm; + struct timeb tp; + long sec, millisec; + + sec = duration / 1000; + millisec = duration % 1000; + ftime( &tp ); + tp.time += sec; + tp.millitm += millisec; + if( tp.millitm > 999 ) { + tp.millitm -= 1000; + tp.time++; + } + tm.tv_sec = tp.time; + tm.tv_nsec = tp.millitm * 1000000 ; + while(ml->semaphore==0 && !rc) { + if(rc = pthread_cond_timedwait(ml->pc,ml->pm, &tm) == ETIMEDOUT) + break; + } + if(rc == ETIMEDOUT) { + ret = WAIT_TIMEOUT; + } else if (rc == 0) { + ml->semaphore--; + ret = WAIT_OBJECT_0; + } + } break; } pthread_mutex_unlock(ml->pm); @@ -889,31 +934,6 @@ dbgprintf("ExitThread(%d)\n", retcode); pthread_exit(&retcode); } - -static HANDLE WINAPI expCreateMutexA(void *pSecAttr, - char bInitialOwner, const char *name) -{ - HANDLE mlist = (HANDLE)expCreateEventA(pSecAttr, 0, 0, name); - - if (name) - dbgprintf("CreateMutexA(0x%x, %d, '%s') => 0x%x\n", - pSecAttr, bInitialOwner, name, mlist); - else - dbgprintf("CreateMutexA(0x%x, %d, NULL) => 0x%x\n", - pSecAttr, bInitialOwner, mlist); -#ifndef QTX - /* 10l to QTX, if CreateMutex returns a real mutex, WaitForSingleObject - waits for ever, else it works ;) */ - return mlist; -#endif -} - -static int WINAPI expReleaseMutex(HANDLE hMutex) -{ - dbgprintf("ReleaseMutex(%x) => 1\n", hMutex); - /* FIXME:XXX !! not yet implemented */ - return 1; -} #endif static int pf_set = 0; @@ -1167,7 +1187,7 @@ * CreateThread ...etc.. * */ - cachedsi.dwNumberOfProcessors=1; + //cachedsi.dwNumberOfProcessors=1; } #endif /* __linux__ */ cache = 1; @@ -1865,7 +1885,7 @@ pthread_mutex_lock(ml->pm); if (prev_count != 0) *prev_count = ml->semaphore; - if (ml->semaphore == 0) pthread_cond_signal(ml->pc); + if (ml->semaphore == 0) pthread_cond_broadcast(ml->pc); ml->semaphore += increment; pthread_mutex_unlock(ml->pm); dbgprintf("ReleaseSemaphore(semaphore 0x%x, increment %d, prev_count 0x%x) => 1\n", @@ -1873,6 +1893,28 @@ return 1; } +#ifdef QTX +static HANDLE WINAPI expCreateMutexA(void *pSecAttr, + char bInitialOwner, const char *name) +{ + HANDLE mlist = expCreateSemaphoreA(pSecAttr, bInitialOwner ? 0 : 1, 1, name); + + if (name) + dbgprintf("CreateMutexA(0x%x, %d, '%s') => 0x%x\n", + pSecAttr, bInitialOwner, name, mlist); + else + dbgprintf("CreateMutexA(0x%x, %d, NULL) => 0x%x\n", + pSecAttr, bInitialOwner, mlist); + return mlist; +} + +static int WINAPI expReleaseMutex(HANDLE hMutex) +{ + int ret = expReleaseSemaphore(hMutex, 1 , 0); + dbgprintf("ReleaseMutex(%x) => %d\n", hMutex, ret); + return ret; +} +#endif static long WINAPI expRegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey) { @@ -3748,10 +3790,15 @@ LPDWORD lpProcessAffinityMask, LPDWORD lpSystemAffinityMask) { + SYSTEM_INFO si; + DWORD mask; dbgprintf("GetProcessAffinityMask(0x%x, 0x%x, 0x%x) => 1\n", hProcess, lpProcessAffinityMask, lpSystemAffinityMask); - if(lpProcessAffinityMask)*lpProcessAffinityMask=1; - if(lpSystemAffinityMask)*lpSystemAffinityMask=1; + expGetSystemInfo(&si); + mask = ((DWORD)1 << si.dwNumberOfProcessors) - 1; + if(lpProcessAffinityMask)*lpProcessAffinityMask=mask; + if(lpSystemAffinityMask)*lpSystemAffinityMask=mask; + dbgprintf("GetProcessAffinityMask =>0x%08x\n", mask); return 1; }