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()39Thread::Thread() {} 40 launch()41void 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)53void * Thread::operator new(std::size_t size) 54 throw (std::bad_alloc) 55 { 56 return SimpleReferenceObject::operator new(size); 57 } 58 operator delete(void * p)59void Thread::operator delete(void * p) throw () { 60 SimpleReferenceObject::operator delete(p); 61 } 62 ~Thread()63Thread::~Thread() {} 64 run()65void Thread::run() { 66 try { 67 execute(); 68 } catch (...) { 69 // Work around the problem that onTerminated is not called if run throws 70 // an exception: 71 onTerminated(); 72 throw; 73 } 74 } 75 onTerminated()76void Thread::onTerminated() { 77 release(); 78 } 79