BsCoreObjectCore.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "CoreThread/BsCoreObjectCore.h"
  4. #include "CoreThread/BsCoreThread.h"
  5. namespace bs
  6. {
  7. namespace ct
  8. {
  9. Signal CoreObject::mCoreGpuObjectLoadedCondition;
  10. Mutex CoreObject::mCoreGpuObjectLoadedMutex;
  11. CoreObject::CoreObject()
  12. :mFlags(0)
  13. { }
  14. CoreObject::~CoreObject()
  15. {
  16. THROW_IF_NOT_CORE_THREAD;
  17. }
  18. void CoreObject::initialize()
  19. {
  20. {
  21. Lock lock(mCoreGpuObjectLoadedMutex);
  22. setIsInitialized(true);
  23. }
  24. setScheduledToBeInitialized(false);
  25. mCoreGpuObjectLoadedCondition.notify_all();
  26. }
  27. void CoreObject::synchronize()
  28. {
  29. if (!isInitialized())
  30. {
  31. #if BS_DEBUG_MODE
  32. if (BS_THREAD_CURRENT_ID == CoreThread::instance().getCoreThreadId())
  33. BS_EXCEPT(InternalErrorException, "You cannot call this method on the core thread. It will cause a deadlock!");
  34. #endif
  35. Lock lock(mCoreGpuObjectLoadedMutex);
  36. while (!isInitialized())
  37. {
  38. if (!isScheduledToBeInitialized())
  39. BS_EXCEPT(InternalErrorException, "Attempting to wait until initialization finishes but object is not scheduled to be initialized.");
  40. mCoreGpuObjectLoadedCondition.wait(lock);
  41. }
  42. }
  43. }
  44. void CoreObject::_setThisPtr(SPtr<CoreObject> ptrThis)
  45. {
  46. mThis = ptrThis;
  47. }
  48. }
  49. }