Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / osl / w32 / mutex.c
blobf9ce1c0e3a8a7179cfba80a467ad9ef85fc67814
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "system.h"
22 #include <osl/mutex.h>
23 #include <osl/diagnose.h>
26 Implementation notes:
27 The void* hidden by oslMutex points to a WIN32
28 CRITICAL_SECTION structure.
31 /*****************************************************************************/
32 /* osl_createMutex */
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;
54 if (pMutexImpl)
56 DeleteCriticalSection(pMutexImpl);
57 free(pMutexImpl);
61 /*****************************************************************************/
62 /* osl_acquireMutex */
63 /*****************************************************************************/
64 sal_Bool SAL_CALL osl_acquireMutex(oslMutex Mutex)
66 CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex;
68 OSL_ASSERT(Mutex);
70 EnterCriticalSection(pMutexImpl);
72 return sal_True;
75 /*****************************************************************************/
76 /* osl_tryToAcquireMutex */
77 /*****************************************************************************/
78 sal_Bool SAL_CALL osl_tryToAcquireMutex(oslMutex Mutex)
80 CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex;
82 OSL_ASSERT(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;
94 OSL_ASSERT(Mutex);
96 LeaveCriticalSection(pMutexImpl);
98 return sal_True;
101 /*****************************************************************************/
102 /* osl_getGlobalMutex */
103 /*****************************************************************************/
105 /* initialized in dllentry.c */
106 oslMutex g_Mutex;
108 oslMutex * SAL_CALL osl_getGlobalMutex(void)
110 return &g_Mutex;
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */