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