1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_desktop.hxx"
30 
31 #include "sal/config.h"
32 
33 #include <cstddef>
34 #include <new>
35 
36 #include "osl/thread.hxx"
37 #include "salhelper/simplereferenceobject.hxx"
38 
39 #include "dp_gui_thread.hxx"
40 
41 using dp_gui::Thread;
42 
43 Thread::Thread() {}
44 
45 void Thread::launch() {
46     // Assumption is that osl::Thread::create returns normally iff it causes
47     // osl::Thread::run to start executing:
48     acquire();
49     try {
50         create();
51     } catch (...) {
52         release();
53         throw;
54     }
55 }
56 
57 void * Thread::operator new(std::size_t size)
58     throw (std::bad_alloc)
59 {
60     return SimpleReferenceObject::operator new(size);
61 }
62 
63 void Thread::operator delete(void * p) throw () {
64     SimpleReferenceObject::operator delete(p);
65 }
66 
67 Thread::~Thread() {}
68 
69 void Thread::run() {
70     try {
71         execute();
72     } catch (...) {
73         // Work around the problem that onTerminated is not called if run throws
74         // an exception:
75         onTerminated();
76         throw;
77     }
78 }
79 
80 void Thread::onTerminated() {
81     release();
82 }
83