1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
24 #include <osl/mutex.h>
25 #include <osl/diagnose.h>
29 The void* hidden by oslMutex points to a WIN32
30 CRITICAL_SECTION structure.
33 oslMutex SAL_CALL
osl_createMutex(void)
35 CRITICAL_SECTION
* pMutexImpl
;
37 pMutexImpl
= static_cast<CRITICAL_SECTION
*>(calloc(sizeof(CRITICAL_SECTION
), 1));
39 OSL_ASSERT(pMutexImpl
); /* alloc successful? */
41 InitializeCriticalSection(pMutexImpl
);
43 return reinterpret_cast<oslMutex
>(pMutexImpl
);
46 void SAL_CALL
osl_destroyMutex(oslMutex Mutex
)
48 CRITICAL_SECTION
* pMutexImpl
= reinterpret_cast<CRITICAL_SECTION
*>(Mutex
);
52 DeleteCriticalSection(pMutexImpl
);
57 sal_Bool SAL_CALL
osl_acquireMutex(oslMutex Mutex
)
59 CRITICAL_SECTION
* pMutexImpl
= reinterpret_cast<CRITICAL_SECTION
*>(Mutex
);
63 EnterCriticalSection(pMutexImpl
);
68 sal_Bool SAL_CALL
osl_tryToAcquireMutex(oslMutex Mutex
)
70 CRITICAL_SECTION
* pMutexImpl
= reinterpret_cast<CRITICAL_SECTION
*>(Mutex
);
74 return TryEnterCriticalSection(pMutexImpl
) != FALSE
;
77 sal_Bool SAL_CALL
osl_releaseMutex(oslMutex Mutex
)
79 CRITICAL_SECTION
* pMutexImpl
= reinterpret_cast<CRITICAL_SECTION
*>(Mutex
);
83 LeaveCriticalSection(pMutexImpl
);
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */