| 1013 | } |
| 1014 | |
| 1015 | bool BfCodeGen::Finish() |
| 1016 | { |
| 1017 | BP_ZONE("BfCodeGen::Finish"); |
| 1018 | |
| 1019 | while (mRequests.size() != 0) |
| 1020 | { |
| 1021 | auto request = mRequests[0]; |
| 1022 | if (request->mResult.mType == BfCodeGenResult_NotDone) |
| 1023 | { |
| 1024 | bool hasRunningThreads = false; |
| 1025 | for (auto thread : mThreads) |
| 1026 | { |
| 1027 | if (thread->mRunning) |
| 1028 | hasRunningThreads = true; |
| 1029 | } |
| 1030 | if (!hasRunningThreads) |
| 1031 | { |
| 1032 | mPendingRequests.Clear(); |
| 1033 | request->mResult.mType = BfCodeGenResult_Aborted; |
| 1034 | continue; |
| 1035 | } |
| 1036 | |
| 1037 | mDoneEvent.WaitFor(20); |
| 1038 | continue; |
| 1039 | } |
| 1040 | |
| 1041 | RequestComplete(request); |
| 1042 | delete request; |
| 1043 | mRequests.RemoveAt(0); |
| 1044 | return false; |
| 1045 | } |
| 1046 | |
| 1047 | if (mIsUsingReleaseThunk) |
| 1048 | { |
| 1049 | // Make the thunk release its threads (and more important, its LLVM contexts) |
| 1050 | mFinishFunc(); |
| 1051 | } |
| 1052 | |
| 1053 | // We need to shut down these threads to remove their memory |
| 1054 | for (auto thread : mThreads) |
| 1055 | { |
| 1056 | thread->mShuttingDown = true; |
| 1057 | mOldThreads.push_back(thread); |
| 1058 | } |
| 1059 | mThreads.Clear(); |
| 1060 | mRequestEvent.Set(true); |
| 1061 | |
| 1062 | ClearOldThreads(false); |
| 1063 | |
| 1064 | // for (auto request : mPendingRequests) |
| 1065 | // { |
| 1066 | // if (request->mExternResultPtr != NULL) |
| 1067 | // { |
| 1068 | // request->mExternResultPtr->mType = BfCodeGenResult_Aborted; |
| 1069 | // //delete request; |
| 1070 | // } |
| 1071 | // //request->mResult.mType = BfCodeGenResult_Aborted; |
| 1072 | // //delete request; |