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_TESTING_TEST_THREAD_H
16 #define EMUGL_COMMON_TESTING_TEST_THREAD_H
19 # define WIN32_LEAN_AND_MEAN 1
27 // Very basic platform thread wrapper that only uses a tiny stack.
28 // This shall only be used during unit testing, and allows test code
29 // to not depend on the implementation of emugl::Thread.
32 // Main thread function type.
33 typedef void* (ThreadFunction)(void* param);
35 // Constructor actually launches a new platform thread.
36 TestThread(ThreadFunction* func, void* funcParam) {
38 mThread = CreateThread(NULL,
40 (DWORD WINAPI (*)(void*))func,
46 pthread_attr_init(&attr);
47 pthread_attr_setstacksize(&attr, 16384);
48 pthread_create(&mThread, &attr, func, funcParam);
49 pthread_attr_destroy(&attr);
61 WaitForSingleObject(mThread, INFINITE);
64 pthread_join(mThread, &ret);
78 #endif // EMUGL_COMMON_TESTING_TEST_THREAD_H