1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <signalshared.hxx>
30 oslSignalHandlerImpl
* SignalList
;
31 bool bInitSignal
= false;
33 std::mutex
& getSignalMutex()
35 static std::mutex aMutex
;
40 oslSignalAction
callSignalHandler(oslSignalInfo
* pInfo
)
42 oslSignalHandlerImpl
* pHandler
= SignalList
;
43 oslSignalAction Action
= osl_Signal_ActCallNextHdl
;
47 if ((Action
= pHandler
->Handler(pHandler
->pData
, pInfo
)) != osl_Signal_ActCallNextHdl
)
50 pHandler
= pHandler
->pNext
;
56 oslSignalHandler SAL_CALL
osl_addSignalHandler(oslSignalHandlerFunction handler
, void* pData
)
61 oslSignalHandlerImpl
* pHandler
62 = static_cast<oslSignalHandlerImpl
*>(calloc(1, sizeof(oslSignalHandlerImpl
)));
64 std::scoped_lock
aGuard(getSignalMutex());
67 bInitSignal
= onInitSignal();
71 pHandler
->Handler
= handler
;
72 pHandler
->pData
= pData
;
74 pHandler
->pNext
= SignalList
;
75 SignalList
= pHandler
;
83 sal_Bool SAL_CALL
osl_removeSignalHandler(oslSignalHandler handler
)
85 std::scoped_lock
aGuard(getSignalMutex());
88 bInitSignal
= onInitSignal();
90 oslSignalHandlerImpl
* pHandler
= SignalList
;
91 oslSignalHandlerImpl
* pPrevious
= nullptr;
95 if (pHandler
== handler
)
98 pPrevious
->pNext
= pHandler
->pNext
;
100 SignalList
= pHandler
->pNext
;
102 if (SignalList
== nullptr)
103 bInitSignal
= onDeInitSignal();
110 pPrevious
= pHandler
;
111 pHandler
= pHandler
->pNext
;
117 oslSignalAction SAL_CALL
osl_raiseSignal(sal_Int32 userSignal
, void* userData
)
119 std::scoped_lock
aGuard(getSignalMutex());
122 bInitSignal
= onInitSignal();
125 info
.Signal
= osl_Signal_User
;
126 info
.UserSignal
= userSignal
;
127 info
.UserData
= userData
;
129 oslSignalAction action
= callSignalHandler(&info
);
134 sal_Bool SAL_CALL
osl_setErrorReporting(sal_Bool
/*bEnable*/)
136 // this is part of the stable API
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */