EAMainSubmitDone.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) Electronic Arts Inc. All rights reserved.
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #include <kernel.h>
  5. #include <sceerror.h>
  6. #include <gnm.h>
  7. #include "EAAssert/eaassert.h"
  8. #define SUBMIT_DEBUG_PRINT(arg)
  9. namespace EA
  10. {
  11. namespace EAMain
  12. {
  13. namespace Internal
  14. {
  15. static ScePthread gSubmitDoneThread;
  16. static SceKernelSema gSubmitDoneSema;
  17. volatile static bool gShutdownSubmitDoneThread = false;
  18. void* SubmitDoneThreadFunction(void *)
  19. {
  20. int result;
  21. EA_UNUSED(result);
  22. SUBMIT_DEBUG_PRINT("Started submit done thread\n");
  23. for(;;)
  24. {
  25. const int microsecondsPerSecond = 1000000;
  26. SceKernelUseconds timeout = 2 * microsecondsPerSecond;
  27. result = sceKernelWaitSema(gSubmitDoneSema, 1, &timeout);
  28. EA_ASSERT(result == SCE_OK || result == SCE_KERNEL_ERROR_ETIMEDOUT);
  29. if(gShutdownSubmitDoneThread)
  30. {
  31. // Break out to avoid calling submitDone
  32. break;
  33. }
  34. else
  35. {
  36. SUBMIT_DEBUG_PRINT("submitDone\n");
  37. #if SCE_ORBIS_SDK_VERSION >= 0x01000051u && SCE_ORBIS_SDK_VERSION != 0x01000071u
  38. // Only perform the submitDone call if we are above SDK version 1.00.051
  39. // but not 1.00.071 since the requirement was temporarily removed in that release.
  40. // This is not required in previous or later SDK versions.
  41. sce::Gnm::submitDone();
  42. #endif
  43. }
  44. }
  45. SUBMIT_DEBUG_PRINT("Ending submit done thread\n");
  46. return nullptr;
  47. }
  48. void StartSubmitDoneThread()
  49. {
  50. int result;
  51. EA_UNUSED(result);
  52. SUBMIT_DEBUG_PRINT("Starting submit done thread\n");
  53. result = sceKernelCreateSema(&gSubmitDoneSema, "submit done semaphore", 0, 0, 1, nullptr);
  54. EA_ASSERT(result == SCE_OK);
  55. result = scePthreadCreate(&gSubmitDoneThread, NULL, SubmitDoneThreadFunction, NULL, "submit done thread");
  56. EA_ASSERT(result == SCE_OK);
  57. }
  58. void ShutdownSubmitDoneThread()
  59. {
  60. if(!gShutdownSubmitDoneThread)
  61. {
  62. SUBMIT_DEBUG_PRINT("Disabling submit done thread\n");
  63. int result;
  64. EA_UNUSED(result);
  65. // Indicate that the submit done thread should exit
  66. gShutdownSubmitDoneThread = true;
  67. // Signal semaphore to unblock the submit done thread
  68. result = sceKernelSignalSema(gSubmitDoneSema, 1);
  69. EA_ASSERT(result == SCE_OK);
  70. // Wait for the thread to exit
  71. result = scePthreadJoin(gSubmitDoneThread, nullptr);
  72. EA_ASSERT(result == SCE_OK);
  73. // Free up kernel resources
  74. result = sceKernelDeleteSema(gSubmitDoneSema);
  75. EA_ASSERT(result == SCE_OK);
  76. }
  77. }
  78. }
  79. void DisableSubmitDoneThread()
  80. {
  81. using namespace EA::EAMain::Internal;
  82. ShutdownSubmitDoneThread();
  83. }
  84. }
  85. }
  86. #undef SUBMIT_DEBUG_PRINT