1 // Copyright (C) 2014 The Android Open Source Project
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef EMUGL_COMMON_THREAD_H
16 #define EMUGL_COMMON_THREAD_H
28 // Wrapper class for platform-specific threads.
29 // To create your own thread, define a sub-class of emugl::Thread
30 // and override its main() method.
34 // class MyThread : public emugl::Thread {
36 // MyThread() : Thread() {}
38 // virtual intptr_t main() {
39 // ... main thread loop implementation
46 // // Create new instance, but does not start it.
47 // MyThread* thread = new MyThread();
49 // // Start the thread.
52 // // Wait for thread completion, and gets result into |exitStatus|.
54 // thread->wait(&exitStatus);
58 // Public constructor.
61 // Virtual destructor.
64 // Override this method in your own thread sub-classes. This will
65 // be called when start() is invoked on the Thread instance.
66 virtual intptr_t main() = 0;
68 // Start a thread instance. Return true on success, false otherwise
69 // (e.g. if the thread was already started or terminated).
72 // Wait for thread termination and retrieve exist status into
73 // |*exitStatus|. Return true on success, false otherwise.
74 // NOTE: |exitStatus| can be NULL.
75 bool wait(intptr_t *exitStatus);
77 // Check whether a thread has terminated. On success, return true
78 // and sets |*exitStatus|. On failure, return false.
79 // NOTE: |exitStatus| can be NULL.
80 bool tryWait(intptr_t *exitStatus);
84 static DWORD WINAPI thread_main(void* arg);
88 CRITICAL_SECTION mLock;
90 static void* thread_main(void* arg);
93 pthread_mutex_t mLock;
102 #endif // EMUGL_COMMON_THREAD_H