tdf#154546 skip dispatch when presenter controller is not set
[LibreOffice.git] / sal / osl / unx / interlck.cxx
blob81404cb57a7a8333741029bb30ec92a272818bc7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "system.hxx"
22 #include <config_global.h>
23 #include <osl/interlck.h>
25 #if ( defined (__sun) || defined ( NETBSD ) ) && defined ( SPARC )
26 #error please use asm/interlck_sparc.s
27 #elif defined (__sun) && defined ( X86 )
28 #error please use asm/interlck_x86.s
29 #elif HAVE_GCC_BUILTIN_ATOMIC
30 oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInterlockedCount* pCount)
32 return __sync_add_and_fetch(pCount, 1);
34 oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* pCount)
36 return __sync_sub_and_fetch(pCount, 1);
38 #elif defined ( __GNUC__ ) && ( defined ( X86 ) || defined ( X86_64 ) )
39 /* That's possible on x86-64 too since oslInterlockedCount is a sal_Int32 */
41 oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInterlockedCount* pCount)
43 register oslInterlockedCount nCount asm("%eax");
44 nCount = 1;
45 __asm__ __volatile__ (
46 "lock\n\t"
47 "xaddl %0, %1\n\t"
48 : "+r" (nCount), "+m" (*pCount)
49 : /* nothing */
50 : "memory");
51 return ++nCount;
54 oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* pCount)
56 register oslInterlockedCount nCount asm("%eax");
57 nCount = -1;
58 __asm__ __volatile__ (
59 "lock\n\t"
60 "xaddl %0, %1\n\t"
61 : "+r" (nCount), "+m" (*pCount)
62 : /* nothing */
63 : "memory");
64 return --nCount;
66 #else
67 /* use only if nothing else works, expensive due to single mutex for all reference counts */
69 static pthread_mutex_t InterLock = PTHREAD_MUTEX_INITIALIZER;
71 oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInterlockedCount* pCount)
73 oslInterlockedCount Count;
75 pthread_mutex_lock(&InterLock);
76 Count = ++(*pCount);
77 pthread_mutex_unlock(&InterLock);
79 return Count;
82 oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* pCount)
84 oslInterlockedCount Count;
86 pthread_mutex_lock(&InterLock);
87 Count = --(*pCount);
88 pthread_mutex_unlock(&InterLock);
90 return Count;
93 #endif /* default */
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */