BsCoreObjectCore.cpp 1.4 KB

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