root/OpenSceneGraph/trunk/src/OpenThreads/qt/QtThreadPrivateData.h @ 13482

Revision 13482, 3.0 kB (checked in by robert, 6 hours ago)

Added write support

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007  The Open Thread Group
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14
15//
16// QtThreadPrivateData.h - Private data structure for Thread
17// ~~~~~~~~~~~~~~~~~~~~~
18
19#ifndef _QTTHREADPRIVATEDATA_H_
20#define _QTTHREADPRIVATEDATA_H_
21
22#include <OpenThreads/Thread>
23#include <OpenThreads/Block>
24#include <QThread>
25
26struct QtThreadCanceled {};
27
28class QtThreadPrivateData : public QThread
29{
30public:
31    static int createUniqueID()
32    {
33        static int nextID = 0;
34        return nextID++;
35    }
36   
37    static void microSleep(unsigned int microsec)
38    {
39        usleep(microsec);
40    }
41   
42    QtThreadPrivateData(OpenThreads::Thread* master)
43    : QThread(0), _master(master) {}
44   
45    virtual ~QtThreadPrivateData() {}
46   
47    OpenThreads::Thread* getMasterThread() { return _master; }
48   
49    void setAsynchronousTermination( bool enabled )
50    { setTerminationEnabled(enabled); }
51   
52    void applyPriority()
53    {
54        Priority prio = NormalPriority;
55        switch (threadPriority)
56        {
57        case OpenThreads::Thread::THREAD_PRIORITY_MAX:
58            prio = HighestPriority;
59            break;
60        case OpenThreads::Thread::THREAD_PRIORITY_HIGH:
61            prio = HighPriority;
62            break;
63        case OpenThreads::Thread::THREAD_PRIORITY_NOMINAL:
64            prio = NormalPriority;
65            break;
66        case OpenThreads::Thread::THREAD_PRIORITY_LOW:
67            prio = LowPriority;
68            break;
69        case OpenThreads::Thread::THREAD_PRIORITY_MIN:
70            prio = IdlePriority;
71            break;
72        default:
73            break;
74        }
75        setPriority( prio );
76    }
77   
78    virtual void run()
79    {
80        applyPriority();
81        isRunning = true;
82        threadStartedBlock.release();
83       
84        if (_master)
85        {
86            try
87            {
88                _master->run();
89            }
90            catch (QtThreadCanceled&)
91            {
92                try { _master->cancelCleanup(); }
93                catch (...) {}
94            }
95            catch (...)
96            {}
97        }
98        isRunning = false;
99    }
100   
101    OpenThreads::Thread::ThreadPolicy threadPolicy;
102    OpenThreads::Thread::ThreadPriority threadPriority;
103    unsigned int stackSize;
104    int cpunum;
105    int uniqueId;
106    int cancelMode;  // 0 - deffered; 1 - asynchronous; 2 - disabled
107    bool cancelled;
108    bool detached;
109    bool isRunning;
110   
111    OpenThreads::Block threadStartedBlock;
112   
113private:
114    OpenThreads::Thread* _master;
115};
116
117#endif
Note: See TracBrowser for help on using the browser.