xref: /trunk/main/desktop/source/deployment/gui/dp_gui_thread.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 
27 #include "sal/config.h"
28 
29 #include <cstddef>
30 #include <new>
31 
32 #include "osl/thread.hxx"
33 #include "salhelper/simplereferenceobject.hxx"
34 
35 #include "dp_gui_thread.hxx"
36 
37 using dp_gui::Thread;
38 
Thread()39 Thread::Thread() {}
40 
launch()41 void Thread::launch() {
42     // Assumption is that osl::Thread::create returns normally iff it causes
43     // osl::Thread::run to start executing:
44     acquire();
45     try {
46         create();
47     } catch (...) {
48         release();
49         throw;
50     }
51 }
52 
operator new(std::size_t size)53 void * Thread::operator new(std::size_t size)
54 {
55     return SimpleReferenceObject::operator new(size);
56 }
57 
operator delete(void * p)58 void Thread::operator delete(void * p) throw () {
59     SimpleReferenceObject::operator delete(p);
60 }
61 
~Thread()62 Thread::~Thread() {}
63 
run()64 void Thread::run() {
65     try {
66         execute();
67     } catch (...) {
68         // Work around the problem that onTerminated is not called if run throws
69         // an exception:
70         onTerminated();
71         throw;
72     }
73 }
74 
onTerminated()75 void Thread::onTerminated() {
76     release();
77 }
78