update dev300-m58
[ooovba.git] / sal / osl / w32 / interlck.c
blob02ec29dca58178442c194c379d98aa0b7b4a0550
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: interlck.c,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 #include "system.h"
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)
51 #ifdef _M_IX86
52 #ifdef __MINGW32__
54 asm
56 " movl %0, %%ecx\n"
57 " movl $1, %%eax\n"
58 " movl %1, %%edx\n"
59 " cmpl $0, %%edx\n"
60 " je 1f\n"
61 " xadd %%eax, (%%ecx)\n"
62 " jmp 2f\n"
63 "1:\n"
64 " lock xadd %%eax, (%%ecx)\n"
65 "2:\n"
66 " incl %%eax\n"
67 ::"m"(pCount),"m"(osl_isSingleCPU)
70 #else
71 #pragma warning(disable: 4035)
73 __asm
75 mov ecx, pCount
76 mov eax, 1
77 mov edx, osl_isSingleCPU
78 cmp edx, 0
79 je is_not_single
80 xadd dword ptr [ecx],eax
81 jmp cont
82 is_not_single:
83 lock xadd dword ptr [ecx],eax
84 cont:
85 inc eax
88 #pragma warning(default: 4035)
89 #endif
90 #else
91 #pragma message("WARNING: Using system InterlockedIncrement")
93 return (InterlockedIncrement(pCount));
95 #endif
97 /*****************************************************************************/
98 /* osl_decrementInterlockedCount */
99 /*****************************************************************************/
100 oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* pCount)
101 #ifdef _M_IX86
102 #ifdef __MINGW32__
106 " movl %0, %%ecx\n"
107 " orl $-1, %%eax\n"
108 " movl %1, %%edx\n"
109 " cmpl $0, %%edx\n"
110 " je 1f\n"
111 " xadd %%eax, (%%ecx)\n"
112 " jmp 2f\n"
113 "1:\n"
114 " lock xadd %%eax, (%%ecx)\n"
115 "2:\n"
116 " decl %%eax\n"
117 ::"m"(pCount),"m"(osl_isSingleCPU)
120 #else
121 #pragma warning(disable: 4035)
123 __asm
125 mov ecx, pCount
126 or eax, -1
127 mov edx, osl_isSingleCPU
128 cmp edx, 0
129 je is_not_single
130 xadd dword ptr [ecx],eax
131 jmp cont
132 is_not_single:
133 lock xadd dword ptr [ecx],eax
134 cont:
135 dec eax
138 #pragma warning(default: 4035)
139 #endif
140 #else
141 #pragma message("WARNING: Using system InterlockedDecrement")
143 return (InterlockedDecrement(pCount));
145 #endif