1 //===--- A platform independent indirection for a thread class --*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_SRC_SUPPORT_THREADS_THREAD_H 10 #define LLVM_LIBC_SRC_SUPPORT_THREADS_THREAD_H 11 12 #include <stddef.h> 13 14 using ThreadRunnerPosix = void *(void *); 15 using ThreadRunnerStdc = int(void *); 16 17 union ThreadRunner { 18 ThreadRunnerPosix *posix_runner; 19 ThreadRunnerStdc *stdc_runner; 20 }; 21 22 union ThreadReturnValue { 23 void *posix_retval; 24 int stdc_retval; 25 }; 26 27 // The platform specific implemnetations are pulled via the following include. 28 // The idea is for the platform implementation to implement a class named Thread 29 // in the namespace __llvm_libc with the following properties: 30 // 31 // 1. Has a defaulted default constructor (not a default constructor). 32 // 33 // 2. Has a "run" method with the following signature: 34 // 35 // int run(ThreadRunner runner, void *arg, void *stack, size_t size, 36 // bool detached); 37 // 38 // Returns: 39 // 0 on success and an error value on failure. 40 // Args: 41 // runner - The function to execute in the new thread. 42 // arg - The argument to be passed to the thread runner after the thread 43 // is created. 44 // stack - The stack to use for the thread. 45 // size - The stack size. 46 // detached - The detached state of the thread at startup. 47 // 48 // If callers pass a non-null |stack| value, then it will be assumed that 49 // 1. The clean up the stack memory is their responsibility 50 // 2. The guard area is setup appropriately by the caller. 51 // 52 // 3. Has a "join" method with the following signature: 53 // int join(ThreadReturnValue &retval); 54 // The "join" method should return 0 on success and set retcode to the 55 // threads return value. On failure, an appropriate errno value should be 56 // returned. 57 // 58 // 4. Has an operator== for comparison between two threads. 59 #ifdef __unix__ 60 #include "linux/thread.h" 61 #endif // __unix__ 62 63 #endif // LLVM_LIBC_SRC_SUPPORT_THREADS_THREAD_H 64