2 Copyright (C) 2004-2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "JackWinMutex.h"
21 #include "JackError.h"
26 bool JackBaseWinMutex::Lock()
28 if (fOwner
!= GetCurrentThreadId()) {
29 DWORD res
= WaitForSingleObject(fMutex
, INFINITE
);
30 if (res
== WAIT_OBJECT_0
) {
31 fOwner
= GetCurrentThreadId();
34 jack_log("JackBaseWinMutex::Lock res = %d", res
);
38 jack_error("JackBaseWinMutex::Lock mutex already locked by thread = %d", GetCurrentThreadId());
43 bool JackBaseWinMutex::Trylock()
45 if (fOwner
!= GetCurrentThreadId()) {
46 DWORD res
= WaitForSingleObject(fMutex
, 0);
47 if (res
== WAIT_OBJECT_0
) {
48 fOwner
= GetCurrentThreadId();
51 jack_log("JackBaseWinMutex::Trylock res = %d", res
);
55 jack_error("JackBaseWinMutex::Trylock mutex already locked by thread = %d", GetCurrentThreadId());
60 bool JackBaseWinMutex::Unlock()
62 if (fOwner
== GetCurrentThreadId()) {
64 int res
= ReleaseMutex(fMutex
);
68 jack_log("JackBaseWinMutex::Unlock res = %d", res
);
72 jack_error("JackBaseWinMutex::Unlock mutex not locked by thread = %d", GetCurrentThreadId());
77 bool JackWinMutex::Lock()
79 if (WAIT_OBJECT_0
== WaitForSingleObject(fMutex
, INFINITE
)) {
82 jack_log("JackWinProcessSync::Lock WaitForSingleObject err = %d", GetLastError());
87 bool JackWinMutex::Trylock()
89 if (WAIT_OBJECT_0
== WaitForSingleObject(fMutex
, 0)) {
92 jack_log("JackWinProcessSync::Trylock WaitForSingleObject err = %d", GetLastError());
97 bool JackWinMutex::Unlock()
99 if (!ReleaseMutex(fMutex
)) {
100 jack_log("JackWinProcessSync::Unlock ReleaseMutex err = %d", GetLastError());
107 bool JackWinCriticalSection::Lock()
109 EnterCriticalSection(&fSection
);
113 bool JackWinCriticalSection::Trylock()
115 return (TryEnterCriticalSection(&fSection
));
118 bool JackWinCriticalSection::Unlock()
120 LeaveCriticalSection(&fSection
);