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 ************************************************************************/
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
)
58 " xadd %%eax, (%%ecx)\n"
61 " lock xadd %%eax, (%%ecx)\n"
64 ::"m"(pCount
),"m"(osl_isSingleCPU
)
68 #pragma warning(disable: 4035)
74 mov edx
, osl_isSingleCPU
77 xadd dword ptr
[ecx
],eax
80 lock xadd dword ptr
[ecx
],eax
85 #pragma warning(default: 4035)
88 #pragma message("WARNING: Using system InterlockedIncrement")
90 return (InterlockedIncrement(pCount
));
94 /*****************************************************************************/
95 /* osl_decrementInterlockedCount */
96 /*****************************************************************************/
97 oslInterlockedCount SAL_CALL
osl_decrementInterlockedCount(oslInterlockedCount
* pCount
)
108 " xadd %%eax, (%%ecx)\n"
111 " lock xadd %%eax, (%%ecx)\n"
114 ::"m"(pCount
),"m"(osl_isSingleCPU
)
118 #pragma warning(disable: 4035)
124 mov edx
, osl_isSingleCPU
127 xadd dword ptr
[ecx
],eax
130 lock xadd dword ptr
[ecx
],eax
135 #pragma warning(default: 4035)
138 #pragma message("WARNING: Using system InterlockedDecrement")
140 return (InterlockedDecrement(pCount
));