2
0

BsCoreObjectCore.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "BsCoreObjectCore.h"
  2. #include "BsCoreThread.h"
  3. namespace BansheeEngine
  4. {
  5. BS_STATIC_THREAD_SYNCHRONISER_CLASS_INSTANCE(mCoreGpuObjectLoadedCondition, CoreObjectCore)
  6. BS_STATIC_MUTEX_CLASS_INSTANCE(mCoreGpuObjectLoadedMutex, CoreObjectCore)
  7. CoreObjectCore::CoreObjectCore()
  8. :mCoreDirtyFlags(0xFFFFFFFF), mFlags(0)
  9. { }
  10. CoreObjectCore::~CoreObjectCore()
  11. {
  12. THROW_IF_NOT_CORE_THREAD;
  13. }
  14. void CoreObjectCore::initialize()
  15. {
  16. {
  17. BS_LOCK_MUTEX(mCoreGpuObjectLoadedMutex);
  18. setIsInitialized(true);
  19. }
  20. setScheduledToBeInitialized(false);
  21. BS_THREAD_NOTIFY_ALL(mCoreGpuObjectLoadedCondition);
  22. }
  23. void CoreObjectCore::synchronize()
  24. {
  25. if (!isInitialized())
  26. {
  27. #if BS_DEBUG_MODE
  28. if (BS_THREAD_CURRENT_ID == CoreThread::instance().getCoreThreadId())
  29. BS_EXCEPT(InternalErrorException, "You cannot call this method on the core thread. It will cause a deadlock!");
  30. #endif
  31. BS_LOCK_MUTEX_NAMED(mCoreGpuObjectLoadedMutex, lock);
  32. while (!isInitialized())
  33. {
  34. if (!isScheduledToBeInitialized())
  35. BS_EXCEPT(InternalErrorException, "Attempting to wait until initialization finishes but object is not scheduled to be initialized.");
  36. BS_THREAD_WAIT(mCoreGpuObjectLoadedCondition, mCoreGpuObjectLoadedMutex, lock);
  37. }
  38. }
  39. }
  40. void CoreObjectCore::_setThisPtr(std::shared_ptr<CoreObjectCore> ptrThis)
  41. {
  42. mThis = ptrThis;
  43. }
  44. }