[distcc] cygwin port (distcc V1.1) using native win32 mutexes
Heiko Elger
heiko.elger at gmx.de
Mon Feb 10 05:06:36 GMT 2003
Hello,
cause cygwin doesn't support advisory file locking
http://cygwin.com/ml/cygwin/2003-01/msg00674.html I do a port
in using native mutexes for syncronisation.
I use native win32 mutexes cause I don't no much about in using posix
syncronisation objects.
Perhaps this code cae be includes in the distribution.
--------------------------- snip - snip ------------------------------
63a64,69
> #if defined(__CYGWIN__)
> /* if not defined there were errors while including sub headerfiles */
> # define WIN32_LEAN_AND_MEAN
> # include <w32api/windows.h>
> #endif
>
66a73
>
87a95,117
>
> #if defined(__CYGWIN__)
> /* Convert error number to string */
> /* not reentrant ! */
> static const char* strLastError(DWORD err)
> {
> static TCHAR msgBuf[100];
> if (!FormatMessage(
> FORMAT_MESSAGE_FROM_SYSTEM |
> FORMAT_MESSAGE_IGNORE_INSERTS,
> NULL,
> err,
> MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
> (LPTSTR) &msgBuf[0],
> sizeof(msgBuf)/sizeof(msgBuf[0]),
> NULL ))
> {
> msgBuf[0]='\0';
> }
> return (char*)&msgBuf[0];
> }
> #endif
>
113a144,155
> #if defined(__CYGWIN__)
> /****
> * we have not to Release() the mutex, cause the system release it,
when the
> * process terminates or is killed
> *
> * the same behavior as using file handles (original code)
> *****/
> HANDLE h=(HANDLE)fd;
> DWORD rc;
> rc = WaitForSingleObject(h, block ? INFINITE : 0);
> return rc;
> #else
129a172
> #endif
142c185,214
<
---
> #if defined(__CYGWIN__)
> {
> HANDLE h;
> DWORD lastError;
> h = CreateMutex(NULL, FALSE, fname);
> if (NULL==h)
> {
> rs_log_error("failed to creat %s: %s", fname,
strLastError(GetLastError()));
> goto bomb;
> }
> ret = sys_lock((int)h, block);
> lastError = GetLastError();
> switch (ret)
> {
> case WAIT_OBJECT_0: /* Locked OK */
> /* fall through */
> case WAIT_ABANDONED: /* other process ends, killed or
terminated -> I got lock */
> rs_trace("locked %s", fname);
> free(fname);
> return 0;
> break;
> case WAIT_TIMEOUT: /* Timeout */
> rs_trace("%s already locked", fname);
> break;
> case WAIT_FAILED: /* unknown error */
> default:
> rs_log_error("lock(%lu) %s failed: %s", lastError, fname,
strLastError(lastError));
> }
> }
> #else
168c240
< rs_log_error("lock %s failed: %s", fname, strerror(errno));
---
> rs_log_error("lock(%d) %s failed: %s", errno, fname,
strerror(errno));
171c243
<
---
> #endif
176a249
>
--------------------------- snip - snip ------------------------------
Let me know if you like it or if you have any other comments,
suggestions, or fixes.
best regards .....
Heiko Elger
More information about the distcc
mailing list