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 .
22 #include <osl/mutex.h>
23 #include <osl/diagnose.h>
27 The void* hidden by oslMutex points to a WIN32
28 CRITICAL_SECTION structure.
31 /*****************************************************************************/
33 /*****************************************************************************/
34 oslMutex SAL_CALL
osl_createMutex(void)
36 CRITICAL_SECTION
*pMutexImpl
;
38 pMutexImpl
= calloc(sizeof(CRITICAL_SECTION
), 1);
40 OSL_ASSERT(pMutexImpl
); /* alloc successful? */
42 InitializeCriticalSection(pMutexImpl
);
44 return (oslMutex
)pMutexImpl
;
47 /*****************************************************************************/
48 /* osl_destroyMutex */
49 /*****************************************************************************/
50 void SAL_CALL
osl_destroyMutex(oslMutex Mutex
)
52 CRITICAL_SECTION
*pMutexImpl
= (CRITICAL_SECTION
*)Mutex
;
56 DeleteCriticalSection(pMutexImpl
);
61 /*****************************************************************************/
62 /* osl_acquireMutex */
63 /*****************************************************************************/
64 sal_Bool SAL_CALL
osl_acquireMutex(oslMutex Mutex
)
66 CRITICAL_SECTION
*pMutexImpl
= (CRITICAL_SECTION
*)Mutex
;
70 EnterCriticalSection(pMutexImpl
);
75 /*****************************************************************************/
76 /* osl_tryToAcquireMutex */
77 /*****************************************************************************/
78 sal_Bool SAL_CALL
osl_tryToAcquireMutex(oslMutex Mutex
)
80 CRITICAL_SECTION
*pMutexImpl
= (CRITICAL_SECTION
*)Mutex
;
84 return (sal_Bool
)(TryEnterCriticalSection(pMutexImpl
) != FALSE
);
87 /*****************************************************************************/
88 /* osl_releaseMutex */
89 /*****************************************************************************/
90 sal_Bool SAL_CALL
osl_releaseMutex(oslMutex Mutex
)
92 CRITICAL_SECTION
*pMutexImpl
= (CRITICAL_SECTION
*)Mutex
;
96 LeaveCriticalSection(pMutexImpl
);
101 /*****************************************************************************/
102 /* osl_getGlobalMutex */
103 /*****************************************************************************/
105 /* initialized in dllentry.c */
108 oslMutex
* SAL_CALL
osl_getGlobalMutex(void)
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */