1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: interlck.c,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <osl/interlck.h>
34 #include <osl/diagnose.h>
36 extern int osl_isSingleCPU
;
38 /* For all Intel x86 above x486 we use a spezial inline assembler implementation.
39 The main reason is that WIN9? does not return the result of the operation.
40 Instead there is only returned a value greater than zero is the increment
41 result is greater than zero, but not the the result of the addition.
42 For Windows NT the native function could be used, because the correct result
43 is returned. Beacuse of simpler code maintance and performace reasons we use
44 on every x86-Windows-Platform the inline assembler implementation.
47 /*****************************************************************************/
48 /* osl_incrementInterlockedCount */
49 /*****************************************************************************/
50 oslInterlockedCount SAL_CALL
osl_incrementInterlockedCount(oslInterlockedCount
* pCount
)
61 " xadd %%eax, (%%ecx)\n"
64 " lock xadd %%eax, (%%ecx)\n"
67 ::"m"(pCount
),"m"(osl_isSingleCPU
)
71 #pragma warning(disable: 4035)
77 mov edx
, osl_isSingleCPU
80 xadd dword ptr
[ecx
],eax
83 lock xadd dword ptr
[ecx
],eax
88 #pragma warning(default: 4035)
91 #pragma message("WARNING: Using system InterlockedIncrement")
93 return (InterlockedIncrement(pCount
));
97 /*****************************************************************************/
98 /* osl_decrementInterlockedCount */
99 /*****************************************************************************/
100 oslInterlockedCount SAL_CALL
osl_decrementInterlockedCount(oslInterlockedCount
* pCount
)
111 " xadd %%eax, (%%ecx)\n"
114 " lock xadd %%eax, (%%ecx)\n"
117 ::"m"(pCount
),"m"(osl_isSingleCPU
)
121 #pragma warning(disable: 4035)
127 mov edx
, osl_isSingleCPU
130 xadd dword ptr
[ecx
],eax
133 lock xadd dword ptr
[ecx
],eax
138 #pragma warning(default: 4035)
141 #pragma message("WARNING: Using system InterlockedDecrement")
143 return (InterlockedDecrement(pCount
));