| 1 | /**************************************************************************************** |
| 2 | |
| 3 | Copyright (C) 2015 Autodesk, Inc. |
| 4 | All rights reserved. |
| 5 | |
| 6 | Use of this software is subject to the terms of the Autodesk license agreement |
| 7 | provided at the time of installation or download, or which otherwise accompanies |
| 8 | this software in either electronic or hard copy form. |
| 9 | |
| 10 | ****************************************************************************************/ |
| 11 | |
| 12 | //! \file fbxthread.h |
| 13 | #ifndef _FBXSDK_CORE_SYNC_THREAD_H_ |
| 14 | #define _FBXSDK_CORE_SYNC_THREAD_H_ |
| 15 | |
| 16 | #include <fbxsdk/fbxsdk_def.h> |
| 17 | |
| 18 | #if !defined(FBXSDK_ENV_WINSTORE) && !defined(FBXSDK_ENV_EMSCRIPTEN) |
| 19 | |
| 20 | #include <fbxsdk/fbxsdk_nsbegin.h> |
| 21 | |
| 22 | class FbxThreadImpl; |
| 23 | |
| 24 | //! Definition of a thread procedure function signature. |
| 25 | typedef void (*FbxThreadProc)(void*); |
| 26 | |
| 27 | /** This class implement a standard way to use threads across platforms. |
| 28 | */ |
| 29 | class FBXSDK_DLL FbxThread |
| 30 | { |
| 31 | public: |
| 32 | enum EState {eUnknown, eRunning, eDead}; |
| 33 | enum EPriority {eNone, eIdle, eLowest, eLow, eNormal, eHigh, eHighest, eRealTime}; |
| 34 | |
| 35 | /** Constructor |
| 36 | * \param pProc The procedure called upon thread startup. |
| 37 | * \param pArg The arguments passed to the procedure. |
| 38 | * \param pSuspend Start the thread suspended. |
| 39 | */ |
| 40 | FbxThread(FbxThreadProc pProc, void* pArg, bool pSuspend=false); |
| 41 | |
| 42 | /** Constructor |
| 43 | * \param pProc The procedure called upon thread startup. |
| 44 | * \param pArg The arguments passed to the procedure. |
| 45 | * \param pPriority The thread priority to set upon creation. |
| 46 | * \param pSuspend Start the thread suspended. |
| 47 | */ |
| 48 | FbxThread(FbxThreadProc pProc, void* pArg, EPriority pPriority, bool pSuspend=false); |
| 49 | |
| 50 | //! Destructor |
| 51 | virtual ~FbxThread(); |
| 52 | |
| 53 | /** Suspend the execution of the thread. |
| 54 | * \return Return true if the thread was successfully suspended, otherwise false. |
| 55 | * \remarks It should be used only if you can control where the thread will be suspended in its procedure, |
| 56 | * otherwise the state of the thread and its memory is unknown, since the code will stop anywhere. |
| 57 | */ |
| 58 | bool Suspend(); |
| 59 | |
| 60 | /** Resume the execution of the thread. |
| 61 | * \return Return true if the thread was successfully resumed, otherwise false. |
| 62 | */ |
| 63 | bool Resume(); |
| 64 | |
| 65 | /** Wait for the thread completion. |
| 66 | * \return True if the thread successfully returned from its procedure. |
| 67 | */ |
| 68 | bool Join(); |
| 69 | |
| 70 | /** Do not wait for the thread completion and terminate it. |
| 71 | * \return True if the thread successfully died. |
| 72 | */ |
| 73 | bool Kill(); |
| 74 | |
| 75 | /** Retrieve the priority of the thread. |
| 76 | * \return The thread's priority. |
| 77 | */ |
| 78 | EPriority GetPriority(); |
| 79 | |
| 80 | /** Set the thread priority. |
| 81 | * \param pPriority The priority to set to this thread. |
| 82 | * \return True if the thread priority was successfully changed. |
| 83 | */ |
| 84 | bool SetPriority(EPriority pPriority); |
| 85 | |
| 86 | /** Retrieve the thread current state. |
| 87 | * \return The state of the thread. |
| 88 | */ |
| 89 | EState GetState(); |
| 90 | |
| 91 | private: |
| 92 | FbxThreadImpl* mImpl; |
| 93 | }; |
| 94 | |
| 95 | #include <fbxsdk/fbxsdk_nsend.h> |
| 96 | |
| 97 | #endif /* !FBXSDK_ENV_WINSTORE && !FBXSDK_ENV_EMSCRIPTEN */ |
| 98 | |
| 99 | #endif /* _FBXSDK_CORE_SYNC_THREAD_H_ */ |
| 100 | |