1 | /** @file
|
---|
2 | * VirtualBox ThreadTask class definition
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2015-2016 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ____H_THREADTASK
|
---|
18 | #define ____H_THREADTASK
|
---|
19 |
|
---|
20 | #include "VBox/com/string.h"
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * The class ThreadVoidData is used as a base class for any data which we want to pass into a thread
|
---|
24 | */
|
---|
25 | struct ThreadVoidData
|
---|
26 | {
|
---|
27 | public:
|
---|
28 | ThreadVoidData() { }
|
---|
29 | virtual ~ThreadVoidData() { }
|
---|
30 | };
|
---|
31 |
|
---|
32 |
|
---|
33 | class ThreadTask
|
---|
34 | {
|
---|
35 | public:
|
---|
36 | ThreadTask(const Utf8Str &t) : m_hThread(NIL_RTTHREAD), m_strTaskName(t)
|
---|
37 | { }
|
---|
38 |
|
---|
39 | virtual ~ThreadTask()
|
---|
40 | { }
|
---|
41 |
|
---|
42 | HRESULT createThread(void);
|
---|
43 | HRESULT createThreadWithType(RTTHREADTYPE enmType);
|
---|
44 | HRESULT createThreadWithRaceCondition(PRTTHREAD pThread);
|
---|
45 |
|
---|
46 |
|
---|
47 | inline Utf8Str getTaskName() const { return m_strTaskName; }
|
---|
48 |
|
---|
49 | protected:
|
---|
50 | HRESULT createThreadInternal(RTTHREADTYPE enmType, PRTTHREAD pThread);
|
---|
51 | static DECLCALLBACK(int) taskHandlerThreadProc(RTTHREAD thread, void *pvUser);
|
---|
52 |
|
---|
53 | ThreadTask() : m_hThread(NIL_RTTHREAD), m_strTaskName("GenericTask")
|
---|
54 | { }
|
---|
55 |
|
---|
56 | /** The worker thread handle (may be invalid if the thread has shut down). */
|
---|
57 | RTTHREAD m_hThread;
|
---|
58 | Utf8Str m_strTaskName;
|
---|
59 |
|
---|
60 | private:
|
---|
61 | virtual void handler() = 0;
|
---|
62 | };
|
---|
63 |
|
---|
64 | #endif
|
---|
65 |
|
---|