merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / osl / w32 / interlck.c
blob14589e56184ac06676a9ab0dda3e7dbfbcf63513
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include "system.h"
30 #include <osl/interlck.h>
31 #include <osl/diagnose.h>
33 extern int osl_isSingleCPU;
35 /* For all Intel x86 above x486 we use a spezial inline assembler implementation.
36 The main reason is that WIN9? does not return the result of the operation.
37 Instead there is only returned a value greater than zero is the increment
38 result is greater than zero, but not the the result of the addition.
39 For Windows NT the native function could be used, because the correct result
40 is returned. Beacuse of simpler code maintance and performace reasons we use
41 on every x86-Windows-Platform the inline assembler implementation.
44 /*****************************************************************************/
45 /* osl_incrementInterlockedCount */
46 /*****************************************************************************/
47 oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInterlockedCount* pCount)
48 #ifdef _M_IX86
49 #ifdef __MINGW32__
51 asm
53 " movl %0, %%ecx\n"
54 " movl $1, %%eax\n"
55 " movl %1, %%edx\n"
56 " cmpl $0, %%edx\n"
57 " je 1f\n"
58 " xadd %%eax, (%%ecx)\n"
59 " jmp 2f\n"
60 "1:\n"
61 " lock xadd %%eax, (%%ecx)\n"
62 "2:\n"
63 " incl %%eax\n"
64 ::"m"(pCount),"m"(osl_isSingleCPU)
67 #else
68 #pragma warning(disable: 4035)
70 __asm
72 mov ecx, pCount
73 mov eax, 1
74 mov edx, osl_isSingleCPU
75 cmp edx, 0
76 je is_not_single
77 xadd dword ptr [ecx],eax
78 jmp cont
79 is_not_single:
80 lock xadd dword ptr [ecx],eax
81 cont:
82 inc eax
85 #pragma warning(default: 4035)
86 #endif
87 #else
88 #pragma message("WARNING: Using system InterlockedIncrement")
90 return (InterlockedIncrement(pCount));
92 #endif
94 /*****************************************************************************/
95 /* osl_decrementInterlockedCount */
96 /*****************************************************************************/
97 oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* pCount)
98 #ifdef _M_IX86
99 #ifdef __MINGW32__
103 " movl %0, %%ecx\n"
104 " orl $-1, %%eax\n"
105 " movl %1, %%edx\n"
106 " cmpl $0, %%edx\n"
107 " je 1f\n"
108 " xadd %%eax, (%%ecx)\n"
109 " jmp 2f\n"
110 "1:\n"
111 " lock xadd %%eax, (%%ecx)\n"
112 "2:\n"
113 " decl %%eax\n"
114 ::"m"(pCount),"m"(osl_isSingleCPU)
117 #else
118 #pragma warning(disable: 4035)
120 __asm
122 mov ecx, pCount
123 or eax, -1
124 mov edx, osl_isSingleCPU
125 cmp edx, 0
126 je is_not_single
127 xadd dword ptr [ecx],eax
128 jmp cont
129 is_not_single:
130 lock xadd dword ptr [ecx],eax
131 cont:
132 dec eax
135 #pragma warning(default: 4035)
136 #endif
137 #else
138 #pragma message("WARNING: Using system InterlockedDecrement")
140 return (InterlockedDecrement(pCount));
142 #endif