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>
26 #include <osl/diagnose.h>
31 oslSignalHandlerImpl
* SignalList
;
32 bool bInitSignal
= false;
34 std::mutex
& getSignalMutex()
36 static std::mutex aMutex
;
41 oslSignalAction
callSignalHandler(oslSignalInfo
* pInfo
)
43 oslSignalHandlerImpl
* pHandler
= SignalList
;
44 oslSignalAction Action
= osl_Signal_ActCallNextHdl
;
48 if ((Action
= pHandler
->Handler(pHandler
->pData
, pInfo
)) != osl_Signal_ActCallNextHdl
)
51 pHandler
= pHandler
->pNext
;
57 oslSignalHandler SAL_CALL
osl_addSignalHandler(oslSignalHandlerFunction handler
, void* pData
)
62 oslSignalHandlerImpl
* pHandler
63 = static_cast<oslSignalHandlerImpl
*>(calloc(1, sizeof(oslSignalHandlerImpl
)));
65 std::scoped_lock
aGuard(getSignalMutex());
68 bInitSignal
= onInitSignal();
72 pHandler
->Handler
= handler
;
73 pHandler
->pData
= pData
;
75 pHandler
->pNext
= SignalList
;
76 SignalList
= pHandler
;
84 sal_Bool SAL_CALL
osl_removeSignalHandler(oslSignalHandler handler
)
86 std::scoped_lock
aGuard(getSignalMutex());
89 bInitSignal
= onInitSignal();
91 oslSignalHandlerImpl
* pHandler
= SignalList
;
92 oslSignalHandlerImpl
* pPrevious
= nullptr;
96 if (pHandler
== handler
)
99 pPrevious
->pNext
= pHandler
->pNext
;
101 SignalList
= pHandler
->pNext
;
103 if (SignalList
== nullptr)
104 bInitSignal
= onDeInitSignal();
111 pPrevious
= pHandler
;
112 pHandler
= pHandler
->pNext
;
118 oslSignalAction SAL_CALL
osl_raiseSignal(sal_Int32 userSignal
, void* userData
)
120 std::scoped_lock
aGuard(getSignalMutex());
123 bInitSignal
= onInitSignal();
126 info
.Signal
= osl_Signal_User
;
127 info
.UserSignal
= userSignal
;
128 info
.UserData
= userData
;
130 oslSignalAction action
= callSignalHandler(&info
);
135 sal_Bool SAL_CALL
osl_setErrorReporting(sal_Bool
/*bEnable*/)
137 // this is part of the stable API
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */