tdf#161411 - UI: Add Better wording for ASCII-only characters
[LibreOffice.git] / sal / osl / all / signalshared.cxx
blob9ed08626f74f9fb8a25b16ac2388ec4258e71eb5
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 <sal/config.h>
22 #include <stdlib.h>
24 #include <signalshared.hxx>
26 #include <mutex>
28 namespace
30 oslSignalHandlerImpl* SignalList;
31 bool bInitSignal = false;
33 std::mutex& getSignalMutex()
35 static std::mutex aMutex;
36 return aMutex;
40 oslSignalAction callSignalHandler(oslSignalInfo* pInfo)
42 oslSignalHandlerImpl* pHandler = SignalList;
43 oslSignalAction Action = osl_Signal_ActCallNextHdl;
45 while (pHandler)
47 if ((Action = pHandler->Handler(pHandler->pData, pInfo)) != osl_Signal_ActCallNextHdl)
48 break;
50 pHandler = pHandler->pNext;
53 return Action;
56 oslSignalHandler SAL_CALL osl_addSignalHandler(oslSignalHandlerFunction handler, void* pData)
58 if (!handler)
59 return nullptr;
61 oslSignalHandlerImpl* pHandler
62 = static_cast<oslSignalHandlerImpl*>(calloc(1, sizeof(oslSignalHandlerImpl)));
64 std::scoped_lock aGuard(getSignalMutex());
66 if (!bInitSignal)
67 bInitSignal = onInitSignal();
69 if (pHandler)
71 pHandler->Handler = handler;
72 pHandler->pData = pData;
74 pHandler->pNext = SignalList;
75 SignalList = pHandler;
77 return pHandler;
80 return nullptr;
83 sal_Bool SAL_CALL osl_removeSignalHandler(oslSignalHandler handler)
85 std::scoped_lock aGuard(getSignalMutex());
87 if (!bInitSignal)
88 bInitSignal = onInitSignal();
90 oslSignalHandlerImpl* pHandler = SignalList;
91 oslSignalHandlerImpl* pPrevious = nullptr;
93 while (pHandler)
95 if (pHandler == handler)
97 if (pPrevious)
98 pPrevious->pNext = pHandler->pNext;
99 else
100 SignalList = pHandler->pNext;
102 if (SignalList == nullptr)
103 bInitSignal = onDeInitSignal();
105 free(pHandler);
107 return true;
110 pPrevious = pHandler;
111 pHandler = pHandler->pNext;
114 return false;
117 oslSignalAction SAL_CALL osl_raiseSignal(sal_Int32 userSignal, void* userData)
119 std::scoped_lock aGuard(getSignalMutex());
121 if (!bInitSignal)
122 bInitSignal = onInitSignal();
124 oslSignalInfo info;
125 info.Signal = osl_Signal_User;
126 info.UserSignal = userSignal;
127 info.UserData = userData;
129 oslSignalAction action = callSignalHandler(&info);
131 return action;
134 sal_Bool SAL_CALL osl_setErrorReporting(sal_Bool /*bEnable*/)
136 // this is part of the stable API
137 return false;
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */