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>
28 bool bInitSignal
= false;
32 oslSignalHandlerImpl
* SignalList
;
33 oslMutex SignalListMutex
;
37 SignalListMutex
= osl_createMutex();
39 return onInitSignal();
44 bool bRet
= onDeInitSignal();
46 osl_destroyMutex(SignalListMutex
);
53 oslSignalAction
callSignalHandler(oslSignalInfo
* pInfo
)
55 oslSignalHandlerImpl
* pHandler
= SignalList
;
56 oslSignalAction Action
= osl_Signal_ActCallNextHdl
;
60 if ((Action
= pHandler
->Handler(pHandler
->pData
, pInfo
))
61 != osl_Signal_ActCallNextHdl
)
64 pHandler
= pHandler
->pNext
;
70 oslSignalHandler SAL_CALL
osl_addSignalHandler(oslSignalHandlerFunction handler
, void* pData
)
76 bInitSignal
= initSignal();
78 oslSignalHandlerImpl
* pHandler
= static_cast<oslSignalHandlerImpl
*>(calloc(1, sizeof(oslSignalHandlerImpl
)));
82 pHandler
->Handler
= handler
;
83 pHandler
->pData
= pData
;
85 osl_acquireMutex(SignalListMutex
);
87 pHandler
->pNext
= SignalList
;
88 SignalList
= pHandler
;
90 osl_releaseMutex(SignalListMutex
);
98 sal_Bool SAL_CALL
osl_removeSignalHandler(oslSignalHandler handler
)
101 bInitSignal
= initSignal();
103 osl_acquireMutex(SignalListMutex
);
105 oslSignalHandlerImpl
* pHandler
= SignalList
;
106 oslSignalHandlerImpl
* pPrevious
= nullptr;
110 if (pHandler
== handler
)
113 pPrevious
->pNext
= pHandler
->pNext
;
115 SignalList
= pHandler
->pNext
;
117 osl_releaseMutex(SignalListMutex
);
120 bInitSignal
= deInitSignal();
127 pPrevious
= pHandler
;
128 pHandler
= pHandler
->pNext
;
131 osl_releaseMutex(SignalListMutex
);
136 oslSignalAction SAL_CALL
osl_raiseSignal(sal_Int32 userSignal
, void* userData
)
139 bInitSignal
= initSignal();
141 osl_acquireMutex(SignalListMutex
);
144 info
.Signal
= osl_Signal_User
;
145 info
.UserSignal
= userSignal
;
146 info
.UserData
= userData
;
148 oslSignalAction action
= callSignalHandler(&info
);
150 osl_releaseMutex(SignalListMutex
);
155 sal_Bool SAL_CALL
osl_setErrorReporting( sal_Bool
/*bEnable*/ )
157 // this is part of the stable API
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */