From f12dd7dc94fd1467a3ef702773504d5a5fad62b1 Mon Sep 17 00:00:00 2001 From: janwas Date: Thu, 13 Nov 2003 20:10:15 +0000 Subject: [PATCH] no message This was SVN commit r64. --- source/lib/misc.h | 2 +- source/lib/posix/aio.cpp | 11 ++++++++--- source/ps/CStr.cpp | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source/lib/misc.h b/source/lib/misc.h index 0140e9455a..a40c181f96 100755 --- a/source/lib/misc.h +++ b/source/lib/misc.h @@ -38,7 +38,7 @@ #define UNUSED(param) (void)param; -#define ONCE(code) { pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER; if(pthread_mutex_trylock(&(mutex))==0) { code; } } +#define ONCE(code) { static pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER; if(pthread_mutex_trylock(&(mutex))==0) { code; } } template diff --git a/source/lib/posix/aio.cpp b/source/lib/posix/aio.cpp index d963cf5178..c60f0fb14e 100755 --- a/source/lib/posix/aio.cpp +++ b/source/lib/posix/aio.cpp @@ -53,10 +53,12 @@ struct Req static const int MAX_REQS = 4; static Req reqs[MAX_REQS]; -static HANDLE open_mutex, reqs_mutex; +// TODO: use pthread mutex +static HANDLE open_mutex = INVALID_HANDLE_VALUE; +static HANDLE reqs_mutex = INVALID_HANDLE_VALUE; #define LOCK(what)\ {\ -if(!what##_mutex)\ +if(what##_mutex == INVALID_HANDLE_VALUE)\ what##_mutex = CreateMutex(0,0,"aio_"#what);\ WaitForSingleObject(what##_mutex, INFINITE);\ } @@ -117,7 +119,10 @@ static void cleanup(void) } CloseHandle(open_mutex); - CloseHandle(reqs_mutex); + open_mutex = INVALID_HANDLE_VALUE; + if(reqs_mutex != INVALID_HANDLE_VALUE) // happens if not initialized, i.e. aio_rw wasn't called + CloseHandle(reqs_mutex); + reqs_mutex = INVALID_HANDLE_VALUE; } // called by aio_open and aio_open_winhandle diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index 9e11dabbc1..ebd2833fc1 100755 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -219,7 +219,7 @@ void CStr::Replace(const CStr &ToReplace, const CStr &ReplaceWith) // returns a trimed string, removes whitespace from the left/right/both CStr CStr::Trim(PS_TRIM_MODE Mode) { - size_t Left, Right; + int Left, Right; switch (Mode)