1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 #include "system.h" 29 30 #include <osl/interlck.h> 31 #include <osl/diagnose.h> 32 33 extern int osl_isSingleCPU; 34 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. 42 */ 43 44 /*****************************************************************************/ 45 /* osl_incrementInterlockedCount */ 46 /*****************************************************************************/ 47 oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInterlockedCount* pCount) 48 #ifdef _M_IX86 49 #ifdef __MINGW32__ 50 { 51 asm 52 ( 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) 65 ); 66 } 67 #else 68 #pragma warning(disable: 4035) 69 { 70 __asm 71 { 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 83 } 84 } 85 #pragma warning(default: 4035) 86 #endif 87 #else 88 #pragma message("WARNING: Using system InterlockedIncrement") 89 { 90 return (InterlockedIncrement(pCount)); 91 } 92 #endif 93 94 /*****************************************************************************/ 95 /* osl_decrementInterlockedCount */ 96 /*****************************************************************************/ 97 oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* pCount) 98 #ifdef _M_IX86 99 #ifdef __MINGW32__ 100 { 101 asm 102 ( 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) 115 ); 116 } 117 #else 118 #pragma warning(disable: 4035) 119 { 120 __asm 121 { 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 133 } 134 } 135 #pragma warning(default: 4035) 136 #endif 137 #else 138 #pragma message("WARNING: Using system InterlockedDecrement") 139 { 140 return (InterlockedDecrement(pCount)); 141 } 142 #endif 143