فهرست منبع

WorkQueue: use signed type

Related: https://github.com/urho3d/Urho3D/issues/2940
1vanK 3 سال پیش
والد
کامیت
385b2628ea

+ 3 - 0
Source/Urho3D/AngelScript/Generated_GlobalVariables.cpp

@@ -628,6 +628,9 @@ void ASRegisterGeneratedGlobalVariables(asIScriptEngine* engine)
     // const StringHash VSP_ZONE | File: ../GraphicsAPI/GraphicsDefs.h
     // const StringHash VSP_ZONE | File: ../GraphicsAPI/GraphicsDefs.h
     engine->RegisterGlobalProperty("const StringHash VSP_ZONE", (void*)&VSP_ZONE);
     engine->RegisterGlobalProperty("const StringHash VSP_ZONE", (void*)&VSP_ZONE);
 
 
+    // constexpr i32 WI_MAX_PRIORITY | File: ../Core/WorkQueue.h
+    engine->RegisterGlobalProperty("const int WI_MAX_PRIORITY", (void*)&WI_MAX_PRIORITY);
+
 #ifdef URHO3D_NETWORK
 #ifdef URHO3D_NETWORK
     // static const unsigned CONTROLS_CONTENT_ID | File: ../Network/Protocol.h
     // static const unsigned CONTROLS_CONTENT_ID | File: ../Network/Protocol.h
     engine->RegisterGlobalProperty("const uint CONTROLS_CONTENT_ID", (void*)&CONTROLS_CONTENT_ID);
     engine->RegisterGlobalProperty("const uint CONTROLS_CONTENT_ID", (void*)&CONTROLS_CONTENT_ID);

+ 12 - 12
Source/Urho3D/AngelScript/Generated_Members.h

@@ -8763,7 +8763,7 @@ template <class T> void RegisterMembers_WorkItem(asIScriptEngine* engine, const
 {
 {
     RegisterMembers_RefCounted<T>(engine, className);
     RegisterMembers_RefCounted<T>(engine, className);
 
 
-    // void(* WorkItem::workFunction_) (const WorkItem* , unsigned)
+    // void(* WorkItem::workFunction_) (const WorkItem* , i32)
     // Not registered because pointer
     // Not registered because pointer
     // void* WorkItem::start_
     // void* WorkItem::start_
     // Not registered because pointer
     // Not registered because pointer
@@ -8774,8 +8774,8 @@ template <class T> void RegisterMembers_WorkItem(asIScriptEngine* engine, const
     // std::atomic<bool> WorkItem::completed_
     // std::atomic<bool> WorkItem::completed_
     // Error: type "std::atomic<bool>" can not automatically bind
     // Error: type "std::atomic<bool>" can not automatically bind
 
 
-    // unsigned WorkItem::priority_
-    engine->RegisterObjectProperty(className, "uint priority", offsetof(T, priority_));
+    // i32 WorkItem::priority_
+    engine->RegisterObjectProperty(className, "int priority", offsetof(T, priority_));
 
 
     // bool WorkItem::sendEvent_
     // bool WorkItem::sendEvent_
     engine->RegisterObjectProperty(className, "bool sendEvent", offsetof(T, sendEvent_));
     engine->RegisterObjectProperty(className, "bool sendEvent", offsetof(T, sendEvent_));
@@ -12739,26 +12739,26 @@ template <class T> void RegisterMembers_WorkQueue(asIScriptEngine* engine, const
     // Error: type "SharedPtr<WorkItem>" can not automatically bind
     // Error: type "SharedPtr<WorkItem>" can not automatically bind
     // bool WorkQueue::RemoveWorkItem(SharedPtr<WorkItem> item)
     // bool WorkQueue::RemoveWorkItem(SharedPtr<WorkItem> item)
     // Error: type "SharedPtr<WorkItem>" can not automatically bind
     // Error: type "SharedPtr<WorkItem>" can not automatically bind
-    // unsigned WorkQueue::RemoveWorkItems(const Vector<SharedPtr<WorkItem>>& items)
+    // i32 WorkQueue::RemoveWorkItems(const Vector<SharedPtr<WorkItem>>& items)
     // Error: type "const Vector<SharedPtr<WorkItem>>&" can not automatically bind
     // Error: type "const Vector<SharedPtr<WorkItem>>&" can not automatically bind
 
 
-    // void WorkQueue::Complete(unsigned priority)
-    engine->RegisterObjectMethod(className, "void Complete(uint)", AS_METHODPR(T, Complete, (unsigned), void), AS_CALL_THISCALL);
+    // void WorkQueue::Complete(i32 priority)
+    engine->RegisterObjectMethod(className, "void Complete(int)", AS_METHODPR(T, Complete, (i32), void), AS_CALL_THISCALL);
 
 
-    // void WorkQueue::CreateThreads(unsigned numThreads)
-    engine->RegisterObjectMethod(className, "void CreateThreads(uint)", AS_METHODPR(T, CreateThreads, (unsigned), void), AS_CALL_THISCALL);
+    // void WorkQueue::CreateThreads(i32 numThreads)
+    engine->RegisterObjectMethod(className, "void CreateThreads(int)", AS_METHODPR(T, CreateThreads, (i32), void), AS_CALL_THISCALL);
 
 
     // int WorkQueue::GetNonThreadedWorkMs() const
     // int WorkQueue::GetNonThreadedWorkMs() const
     engine->RegisterObjectMethod(className, "int GetNonThreadedWorkMs() const", AS_METHODPR(T, GetNonThreadedWorkMs, () const, int), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "int GetNonThreadedWorkMs() const", AS_METHODPR(T, GetNonThreadedWorkMs, () const, int), AS_CALL_THISCALL);
 
 
-    // unsigned WorkQueue::GetNumThreads() const
-    engine->RegisterObjectMethod(className, "uint GetNumThreads() const", AS_METHODPR(T, GetNumThreads, () const, unsigned), AS_CALL_THISCALL);
+    // i32 WorkQueue::GetNumThreads() const
+    engine->RegisterObjectMethod(className, "int GetNumThreads() const", AS_METHODPR(T, GetNumThreads, () const, i32), AS_CALL_THISCALL);
 
 
     // int WorkQueue::GetTolerance() const
     // int WorkQueue::GetTolerance() const
     engine->RegisterObjectMethod(className, "int GetTolerance() const", AS_METHODPR(T, GetTolerance, () const, int), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "int GetTolerance() const", AS_METHODPR(T, GetTolerance, () const, int), AS_CALL_THISCALL);
 
 
-    // bool WorkQueue::IsCompleted(unsigned priority) const
-    engine->RegisterObjectMethod(className, "bool IsCompleted(uint) const", AS_METHODPR(T, IsCompleted, (unsigned) const, bool), AS_CALL_THISCALL);
+    // bool WorkQueue::IsCompleted(i32 priority) const
+    engine->RegisterObjectMethod(className, "bool IsCompleted(int) const", AS_METHODPR(T, IsCompleted, (i32) const, bool), AS_CALL_THISCALL);
 
 
     // bool WorkQueue::IsCompleting() const
     // bool WorkQueue::IsCompleting() const
     engine->RegisterObjectMethod(className, "bool IsCompleting() const", AS_METHODPR(T, IsCompleting, () const, bool), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool IsCompleting() const", AS_METHODPR(T, IsCompleting, () const, bool), AS_CALL_THISCALL);

+ 24 - 15
Source/Urho3D/Core/WorkQueue.cpp

@@ -17,10 +17,11 @@ class WorkerThread : public Thread, public RefCounted
 {
 {
 public:
 public:
     /// Construct.
     /// Construct.
-    WorkerThread(WorkQueue* owner, unsigned index) :
+    WorkerThread(WorkQueue* owner, i32 index) :
         owner_(owner),
         owner_(owner),
         index_(index)
         index_(index)
     {
     {
+        assert(index >= 0);
     }
     }
 
 
     /// Process work items until stopped.
     /// Process work items until stopped.
@@ -37,13 +38,13 @@ public:
     }
     }
 
 
     /// Return thread index.
     /// Return thread index.
-    unsigned GetIndex() const { return index_; }
+    i32 GetIndex() const { return index_; }
 
 
 private:
 private:
     /// Work queue.
     /// Work queue.
     WorkQueue* owner_;
     WorkQueue* owner_;
     /// Thread index.
     /// Thread index.
-    unsigned index_;
+    i32 index_;
 };
 };
 
 
 WorkQueue::WorkQueue(Context* context) :
 WorkQueue::WorkQueue(Context* context) :
@@ -69,9 +70,11 @@ WorkQueue::~WorkQueue()
         thread->Stop();
         thread->Stop();
 }
 }
 
 
-void WorkQueue::CreateThreads(unsigned numThreads)
+void WorkQueue::CreateThreads(i32 numThreads)
 {
 {
 #ifdef URHO3D_THREADING
 #ifdef URHO3D_THREADING
+    assert(numThreads >= 0);
+
     // Other subsystems may initialize themselves according to the number of threads.
     // Other subsystems may initialize themselves according to the number of threads.
     // Therefore allow creating the threads only once, after which the amount is fixed
     // Therefore allow creating the threads only once, after which the amount is fixed
     if (!threads_.Empty())
     if (!threads_.Empty())
@@ -80,7 +83,7 @@ void WorkQueue::CreateThreads(unsigned numThreads)
     // Start threads in paused mode
     // Start threads in paused mode
     Pause();
     Pause();
 
 
-    for (unsigned i = 0; i < numThreads; ++i)
+    for (i32 i = 0; i < numThreads; ++i)
     {
     {
         SharedPtr<WorkerThread> thread(new WorkerThread(this, i + 1));
         SharedPtr<WorkerThread> thread(new WorkerThread(this, i + 1));
         thread->Run();
         thread->Run();
@@ -180,10 +183,10 @@ bool WorkQueue::RemoveWorkItem(SharedPtr<WorkItem> item)
     return false;
     return false;
 }
 }
 
 
-unsigned WorkQueue::RemoveWorkItems(const Vector<SharedPtr<WorkItem>>& items)
+i32 WorkQueue::RemoveWorkItems(const Vector<SharedPtr<WorkItem>>& items)
 {
 {
     MutexLock lock(queueMutex_);
     MutexLock lock(queueMutex_);
-    unsigned removed = 0;
+    i32 removed = 0;
 
 
     for (Vector<SharedPtr<WorkItem>>::ConstIterator i = items.Begin(); i != items.End(); ++i)
     for (Vector<SharedPtr<WorkItem>>::ConstIterator i = items.Begin(); i != items.End(); ++i)
     {
     {
@@ -227,8 +230,9 @@ void WorkQueue::Resume()
 }
 }
 
 
 
 
-void WorkQueue::Complete(unsigned priority)
+void WorkQueue::Complete(i32 priority)
 {
 {
+    assert(priority >= 0);
     completing_ = true;
     completing_ = true;
 
 
     if (threads_.Size())
     if (threads_.Size())
@@ -279,8 +283,9 @@ void WorkQueue::Complete(unsigned priority)
     completing_ = false;
     completing_ = false;
 }
 }
 
 
-bool WorkQueue::IsCompleted(unsigned priority) const
+bool WorkQueue::IsCompleted(i32 priority) const
 {
 {
+    assert(priority >= 0);
     for (List<SharedPtr<WorkItem>>::ConstIterator i = workItems_.Begin(); i != workItems_.End(); ++i)
     for (List<SharedPtr<WorkItem>>::ConstIterator i = workItems_.Begin(); i != workItems_.End(); ++i)
     {
     {
         if ((*i)->priority_ >= priority && !(*i)->completed_)
         if ((*i)->priority_ >= priority && !(*i)->completed_)
@@ -290,8 +295,10 @@ bool WorkQueue::IsCompleted(unsigned priority) const
     return true;
     return true;
 }
 }
 
 
-void WorkQueue::ProcessItems(unsigned threadIndex)
+void WorkQueue::ProcessItems(i32 threadIndex)
 {
 {
+    assert(threadIndex >= 0);
+
     bool wasActive = false;
     bool wasActive = false;
 
 
     for (;;)
     for (;;)
@@ -325,8 +332,10 @@ void WorkQueue::ProcessItems(unsigned threadIndex)
     }
     }
 }
 }
 
 
-void WorkQueue::PurgeCompleted(unsigned priority)
+void WorkQueue::PurgeCompleted(i32 priority)
 {
 {
+    assert(priority >= 0);
+
     // Purge completed work items and send completion events. Do not signal items lower than priority threshold,
     // Purge completed work items and send completion events. Do not signal items lower than priority threshold,
     // as those may be user submitted and lead to eg. scene manipulation that could happen in the middle of the
     // as those may be user submitted and lead to eg. scene manipulation that could happen in the middle of the
     // render update, which is not allowed
     // render update, which is not allowed
@@ -353,11 +362,11 @@ void WorkQueue::PurgeCompleted(unsigned priority)
 
 
 void WorkQueue::PurgePool()
 void WorkQueue::PurgePool()
 {
 {
-    unsigned currentSize = poolItems_.Size();
-    int difference = lastSize_ - currentSize;
+    i32 currentSize = poolItems_.Size();
+    i32 difference = lastSize_ - currentSize;
 
 
     // Difference tolerance, should be fairly significant to reduce the pool size.
     // Difference tolerance, should be fairly significant to reduce the pool size.
-    for (unsigned i = 0; poolItems_.Size() > 0 && difference > tolerance_ && i < (unsigned)difference; i++)
+    for (i32 i = 0; poolItems_.Size() > 0 && difference > tolerance_ && i < difference; i++)
         poolItems_.PopFront();
         poolItems_.PopFront();
 
 
     lastSize_ = currentSize;
     lastSize_ = currentSize;
@@ -376,7 +385,7 @@ void WorkQueue::ReturnToPool(SharedPtr<WorkItem>& item)
         item->end_ = nullptr;
         item->end_ = nullptr;
         item->aux_ = nullptr;
         item->aux_ = nullptr;
         item->workFunction_ = nullptr;
         item->workFunction_ = nullptr;
-        item->priority_ = M_MAX_UNSIGNED;
+        item->priority_ = WI_MAX_PRIORITY;
         item->sendEvent_ = false;
         item->sendEvent_ = false;
         item->completed_ = false;
         item->completed_ = false;
 
 

+ 12 - 10
Source/Urho3D/Core/WorkQueue.h

@@ -18,6 +18,8 @@ URHO3D_EVENT(E_WORKITEMCOMPLETED, WorkItemCompleted)
     URHO3D_PARAM(P_ITEM, Item);                        // WorkItem ptr
     URHO3D_PARAM(P_ITEM, Item);                        // WorkItem ptr
 }
 }
 
 
+inline constexpr i32 WI_MAX_PRIORITY = M_MAX_INT;
+
 class WorkerThread;
 class WorkerThread;
 
 
 /// Work queue item.
 /// Work queue item.
@@ -28,7 +30,7 @@ struct WorkItem : public RefCounted
 
 
 public:
 public:
     /// Work function. Called with the work item and thread index (0 = main thread) as parameters.
     /// Work function. Called with the work item and thread index (0 = main thread) as parameters.
-    void (* workFunction_)(const WorkItem*, unsigned){};
+    void (* workFunction_)(const WorkItem*, i32){};
     /// Data start pointer.
     /// Data start pointer.
     void* start_{};
     void* start_{};
     /// Data end pointer.
     /// Data end pointer.
@@ -36,7 +38,7 @@ public:
     /// Auxiliary data pointer.
     /// Auxiliary data pointer.
     void* aux_{};
     void* aux_{};
     /// Priority. Higher value = will be completed first.
     /// Priority. Higher value = will be completed first.
-    unsigned priority_{};
+    i32 priority_{};
     /// Whether to send event on completion.
     /// Whether to send event on completion.
     bool sendEvent_{};
     bool sendEvent_{};
     /// Completed flag.
     /// Completed flag.
@@ -60,7 +62,7 @@ public:
     ~WorkQueue() override;
     ~WorkQueue() override;
 
 
     /// Create worker threads. Can only be called once.
     /// Create worker threads. Can only be called once.
-    void CreateThreads(unsigned numThreads);
+    void CreateThreads(i32 numThreads);
     /// Get pointer to an usable WorkItem from the item pool. Allocate one if no more free items.
     /// Get pointer to an usable WorkItem from the item pool. Allocate one if no more free items.
     SharedPtr<WorkItem> GetFreeItem();
     SharedPtr<WorkItem> GetFreeItem();
     /// Add a work item and resume worker threads.
     /// Add a work item and resume worker threads.
@@ -68,13 +70,13 @@ public:
     /// Remove a work item before it has started executing. Return true if successfully removed.
     /// Remove a work item before it has started executing. Return true if successfully removed.
     bool RemoveWorkItem(SharedPtr<WorkItem> item);
     bool RemoveWorkItem(SharedPtr<WorkItem> item);
     /// Remove a number of work items before they have started executing. Return the number of items successfully removed.
     /// Remove a number of work items before they have started executing. Return the number of items successfully removed.
-    unsigned RemoveWorkItems(const Vector<SharedPtr<WorkItem>>& items);
+    i32 RemoveWorkItems(const Vector<SharedPtr<WorkItem>>& items);
     /// Pause worker threads.
     /// Pause worker threads.
     void Pause();
     void Pause();
     /// Resume worker threads.
     /// Resume worker threads.
     void Resume();
     void Resume();
     /// Finish all queued work which has at least the specified priority. Main thread will also execute priority work. Pause worker threads if no more work remains.
     /// Finish all queued work which has at least the specified priority. Main thread will also execute priority work. Pause worker threads if no more work remains.
-    void Complete(unsigned priority);
+    void Complete(i32 priority);
 
 
     /// Set the pool telerance before it starts deleting pool items.
     /// Set the pool telerance before it starts deleting pool items.
     void SetTolerance(int tolerance) { tolerance_ = tolerance; }
     void SetTolerance(int tolerance) { tolerance_ = tolerance; }
@@ -83,10 +85,10 @@ public:
     void SetNonThreadedWorkMs(int ms) { maxNonThreadedWorkMs_ = Max(ms, 1); }
     void SetNonThreadedWorkMs(int ms) { maxNonThreadedWorkMs_ = Max(ms, 1); }
 
 
     /// Return number of worker threads.
     /// Return number of worker threads.
-    unsigned GetNumThreads() const { return threads_.Size(); }
+    i32 GetNumThreads() const { return threads_.Size(); }
 
 
     /// Return whether all work with at least the specified priority is finished.
     /// Return whether all work with at least the specified priority is finished.
-    bool IsCompleted(unsigned priority) const;
+    bool IsCompleted(i32 priority) const;
     /// Return whether the queue is currently completing work in the main thread.
     /// Return whether the queue is currently completing work in the main thread.
     bool IsCompleting() const { return completing_; }
     bool IsCompleting() const { return completing_; }
 
 
@@ -98,9 +100,9 @@ public:
 
 
 private:
 private:
     /// Process work items until shut down. Called by the worker threads.
     /// Process work items until shut down. Called by the worker threads.
-    void ProcessItems(unsigned threadIndex);
+    void ProcessItems(i32 threadIndex);
     /// Purge completed work items which have at least the specified priority, and send completion events as necessary.
     /// Purge completed work items which have at least the specified priority, and send completion events as necessary.
-    void PurgeCompleted(unsigned priority);
+    void PurgeCompleted(i32 priority);
     /// Purge the pool to reduce allocation where its unneeded.
     /// Purge the pool to reduce allocation where its unneeded.
     void PurgePool();
     void PurgePool();
     /// Return a work item to the pool.
     /// Return a work item to the pool.
@@ -129,7 +131,7 @@ private:
     /// Tolerance for the shared pool before it begins to deallocate.
     /// Tolerance for the shared pool before it begins to deallocate.
     int tolerance_;
     int tolerance_;
     /// Last size of the shared pool.
     /// Last size of the shared pool.
-    unsigned lastSize_;
+    i32 lastSize_;
     /// Maximum milliseconds per frame to spend on low-priority work, when there are no worker threads.
     /// Maximum milliseconds per frame to spend on low-priority work, when there are no worker threads.
     int maxNonThreadedWorkMs_;
     int maxNonThreadedWorkMs_;
 };
 };

+ 1 - 1
Source/Urho3D/Graphics/Drawable.h

@@ -94,7 +94,7 @@ class URHO3D_API Drawable : public Component
 
 
     friend class Octant;
     friend class Octant;
     friend class Octree;
     friend class Octree;
-    friend void UpdateDrawablesWork(const WorkItem* item, unsigned threadIndex);
+    friend void UpdateDrawablesWork(const WorkItem* item, i32 threadIndex);
 
 
 public:
 public:
     /// Construct.
     /// Construct.

+ 3 - 3
Source/Urho3D/Graphics/OcclusionBuffer.cpp

@@ -25,7 +25,7 @@ enum ClipMask : unsigned
 };
 };
 URHO3D_FLAGSET(ClipMask, ClipMaskFlags);
 URHO3D_FLAGSET(ClipMask, ClipMaskFlags);
 
 
-void DrawOcclusionBatchWork(const WorkItem* item, unsigned threadIndex)
+void DrawOcclusionBatchWork(const WorkItem* item, i32 threadIndex)
 {
 {
     auto* buffer = reinterpret_cast<OcclusionBuffer*>(item->aux_);
     auto* buffer = reinterpret_cast<OcclusionBuffer*>(item->aux_);
     OcclusionBatch& batch = *reinterpret_cast<OcclusionBatch*>(item->start_);
     OcclusionBatch& batch = *reinterpret_cast<OcclusionBatch*>(item->start_);
@@ -196,14 +196,14 @@ void OcclusionBuffer::DrawTriangles()
         for (Vector<OcclusionBatch>::Iterator i = batches_.Begin(); i != batches_.End(); ++i)
         for (Vector<OcclusionBatch>::Iterator i = batches_.Begin(); i != batches_.End(); ++i)
         {
         {
             SharedPtr<WorkItem> item = queue->GetFreeItem();
             SharedPtr<WorkItem> item = queue->GetFreeItem();
-            item->priority_ = M_MAX_UNSIGNED;
+            item->priority_ = WI_MAX_PRIORITY;
             item->workFunction_ = DrawOcclusionBatchWork;
             item->workFunction_ = DrawOcclusionBatchWork;
             item->aux_ = this;
             item->aux_ = this;
             item->start_ = &(*i);
             item->start_ = &(*i);
             queue->AddWorkItem(item);
             queue->AddWorkItem(item);
         }
         }
 
 
-        queue->Complete(M_MAX_UNSIGNED);
+        queue->Complete(WI_MAX_PRIORITY);
 
 
         MergeBuffers();
         MergeBuffers();
         depthHierarchyDirty_ = true;
         depthHierarchyDirty_ = true;

+ 3 - 3
Source/Urho3D/Graphics/Octree.cpp

@@ -29,7 +29,7 @@ static const int DEFAULT_OCTREE_LEVELS = 8;
 
 
 extern const char* SUBSYSTEM_CATEGORY;
 extern const char* SUBSYSTEM_CATEGORY;
 
 
-void UpdateDrawablesWork(const WorkItem* item, unsigned threadIndex)
+void UpdateDrawablesWork(const WorkItem* item, i32 threadIndex)
 {
 {
     const FrameInfo& frame = *(reinterpret_cast<FrameInfo*>(item->aux_));
     const FrameInfo& frame = *(reinterpret_cast<FrameInfo*>(item->aux_));
     auto** start = reinterpret_cast<Drawable**>(item->start_);
     auto** start = reinterpret_cast<Drawable**>(item->start_);
@@ -369,7 +369,7 @@ void Octree::Update(const FrameInfo& frame)
         for (int i = 0; i < numWorkItems; ++i)
         for (int i = 0; i < numWorkItems; ++i)
         {
         {
             SharedPtr<WorkItem> item = queue->GetFreeItem();
             SharedPtr<WorkItem> item = queue->GetFreeItem();
-            item->priority_ = M_MAX_UNSIGNED;
+            item->priority_ = WI_MAX_PRIORITY;
             item->workFunction_ = UpdateDrawablesWork;
             item->workFunction_ = UpdateDrawablesWork;
             item->aux_ = const_cast<FrameInfo*>(&frame);
             item->aux_ = const_cast<FrameInfo*>(&frame);
 
 
@@ -384,7 +384,7 @@ void Octree::Update(const FrameInfo& frame)
             start = end;
             start = end;
         }
         }
 
 
-        queue->Complete(M_MAX_UNSIGNED);
+        queue->Complete(WI_MAX_PRIORITY);
         scene->EndThreadedUpdate();
         scene->EndThreadedUpdate();
     }
     }
 
 

+ 16 - 16
Source/Urho3D/Graphics/View.cpp

@@ -138,7 +138,7 @@ public:
     OcclusionBuffer* buffer_;
     OcclusionBuffer* buffer_;
 };
 };
 
 
-void CheckVisibilityWork(const WorkItem* item, unsigned threadIndex)
+void CheckVisibilityWork(const WorkItem* item, i32 threadIndex)
 {
 {
     auto* view = reinterpret_cast<View*>(item->aux_);
     auto* view = reinterpret_cast<View*>(item->aux_);
     auto** start = reinterpret_cast<Drawable**>(item->start_);
     auto** start = reinterpret_cast<Drawable**>(item->start_);
@@ -207,7 +207,7 @@ void CheckVisibilityWork(const WorkItem* item, unsigned threadIndex)
     }
     }
 }
 }
 
 
-void ProcessLightWork(const WorkItem* item, unsigned threadIndex)
+void ProcessLightWork(const WorkItem* item, i32 threadIndex)
 {
 {
     auto* view = reinterpret_cast<View*>(item->aux_);
     auto* view = reinterpret_cast<View*>(item->aux_);
     auto* query = reinterpret_cast<LightQueryResult*>(item->start_);
     auto* query = reinterpret_cast<LightQueryResult*>(item->start_);
@@ -215,7 +215,7 @@ void ProcessLightWork(const WorkItem* item, unsigned threadIndex)
     view->ProcessLight(*query, threadIndex);
     view->ProcessLight(*query, threadIndex);
 }
 }
 
 
-void UpdateDrawableGeometriesWork(const WorkItem* item, unsigned threadIndex)
+void UpdateDrawableGeometriesWork(const WorkItem* item, i32 threadIndex)
 {
 {
     const FrameInfo& frame = *(reinterpret_cast<FrameInfo*>(item->aux_));
     const FrameInfo& frame = *(reinterpret_cast<FrameInfo*>(item->aux_));
     auto** start = reinterpret_cast<Drawable**>(item->start_);
     auto** start = reinterpret_cast<Drawable**>(item->start_);
@@ -230,28 +230,28 @@ void UpdateDrawableGeometriesWork(const WorkItem* item, unsigned threadIndex)
     }
     }
 }
 }
 
 
-void SortBatchQueueFrontToBackWork(const WorkItem* item, unsigned threadIndex)
+void SortBatchQueueFrontToBackWork(const WorkItem* item, i32 threadIndex)
 {
 {
     auto* queue = reinterpret_cast<BatchQueue*>(item->start_);
     auto* queue = reinterpret_cast<BatchQueue*>(item->start_);
 
 
     queue->SortFrontToBack();
     queue->SortFrontToBack();
 }
 }
 
 
-void SortBatchQueueBackToFrontWork(const WorkItem* item, unsigned threadIndex)
+void SortBatchQueueBackToFrontWork(const WorkItem* item, i32 threadIndex)
 {
 {
     auto* queue = reinterpret_cast<BatchQueue*>(item->start_);
     auto* queue = reinterpret_cast<BatchQueue*>(item->start_);
 
 
     queue->SortBackToFront();
     queue->SortBackToFront();
 }
 }
 
 
-void SortLightQueueWork(const WorkItem* item, unsigned threadIndex)
+void SortLightQueueWork(const WorkItem* item, i32 threadIndex)
 {
 {
     auto* start = reinterpret_cast<LightBatchQueue*>(item->start_);
     auto* start = reinterpret_cast<LightBatchQueue*>(item->start_);
     start->litBaseBatches_.SortFrontToBack();
     start->litBaseBatches_.SortFrontToBack();
     start->litBatches_.SortFrontToBack();
     start->litBatches_.SortFrontToBack();
 }
 }
 
 
-void SortShadowQueueWork(const WorkItem* item, unsigned threadIndex)
+void SortShadowQueueWork(const WorkItem* item, i32 threadIndex)
 {
 {
     auto* start = reinterpret_cast<LightBatchQueue*>(item->start_);
     auto* start = reinterpret_cast<LightBatchQueue*>(item->start_);
     for (unsigned i = 0; i < start->shadowSplits_.Size(); ++i)
     for (unsigned i = 0; i < start->shadowSplits_.Size(); ++i)
@@ -891,7 +891,7 @@ void View::GetDrawables()
         for (int i = 0; i < numWorkItems; ++i)
         for (int i = 0; i < numWorkItems; ++i)
         {
         {
             SharedPtr<WorkItem> item = queue->GetFreeItem();
             SharedPtr<WorkItem> item = queue->GetFreeItem();
-            item->priority_ = M_MAX_UNSIGNED;
+            item->priority_ = WI_MAX_PRIORITY;
             item->workFunction_ = CheckVisibilityWork;
             item->workFunction_ = CheckVisibilityWork;
             item->aux_ = this;
             item->aux_ = this;
 
 
@@ -906,7 +906,7 @@ void View::GetDrawables()
             start = end;
             start = end;
         }
         }
 
 
-        queue->Complete(M_MAX_UNSIGNED);
+        queue->Complete(WI_MAX_PRIORITY);
     }
     }
 
 
     // Combine lights, geometries & scene Z range from the threads
     // Combine lights, geometries & scene Z range from the threads
@@ -973,7 +973,7 @@ void View::ProcessLights()
     for (unsigned i = 0; i < lightQueryResults_.Size(); ++i)
     for (unsigned i = 0; i < lightQueryResults_.Size(); ++i)
     {
     {
         SharedPtr<WorkItem> item = queue->GetFreeItem();
         SharedPtr<WorkItem> item = queue->GetFreeItem();
-        item->priority_ = M_MAX_UNSIGNED;
+        item->priority_ = WI_MAX_PRIORITY;
         item->workFunction_ = ProcessLightWork;
         item->workFunction_ = ProcessLightWork;
         item->aux_ = this;
         item->aux_ = this;
 
 
@@ -985,7 +985,7 @@ void View::ProcessLights()
     }
     }
 
 
     // Ensure all lights have been processed before proceeding
     // Ensure all lights have been processed before proceeding
-    queue->Complete(M_MAX_UNSIGNED);
+    queue->Complete(WI_MAX_PRIORITY);
 }
 }
 
 
 void View::GetLightBatches()
 void View::GetLightBatches()
@@ -1289,7 +1289,7 @@ void View::UpdateGeometries()
             if (command.type_ == CMD_SCENEPASS)
             if (command.type_ == CMD_SCENEPASS)
             {
             {
                 SharedPtr<WorkItem> item = queue->GetFreeItem();
                 SharedPtr<WorkItem> item = queue->GetFreeItem();
-                item->priority_ = M_MAX_UNSIGNED;
+                item->priority_ = WI_MAX_PRIORITY;
                 item->workFunction_ =
                 item->workFunction_ =
                     command.sortMode_ == SORT_FRONTTOBACK ? SortBatchQueueFrontToBackWork : SortBatchQueueBackToFrontWork;
                     command.sortMode_ == SORT_FRONTTOBACK ? SortBatchQueueFrontToBackWork : SortBatchQueueBackToFrontWork;
                 item->start_ = &batchQueues_[command.passIndex_];
                 item->start_ = &batchQueues_[command.passIndex_];
@@ -1300,7 +1300,7 @@ void View::UpdateGeometries()
         for (Vector<LightBatchQueue>::Iterator i = lightQueues_.Begin(); i != lightQueues_.End(); ++i)
         for (Vector<LightBatchQueue>::Iterator i = lightQueues_.Begin(); i != lightQueues_.End(); ++i)
         {
         {
             SharedPtr<WorkItem> lightItem = queue->GetFreeItem();
             SharedPtr<WorkItem> lightItem = queue->GetFreeItem();
-            lightItem->priority_ = M_MAX_UNSIGNED;
+            lightItem->priority_ = WI_MAX_PRIORITY;
             lightItem->workFunction_ = SortLightQueueWork;
             lightItem->workFunction_ = SortLightQueueWork;
             lightItem->start_ = &(*i);
             lightItem->start_ = &(*i);
             queue->AddWorkItem(lightItem);
             queue->AddWorkItem(lightItem);
@@ -1308,7 +1308,7 @@ void View::UpdateGeometries()
             if (i->shadowSplits_.Size())
             if (i->shadowSplits_.Size())
             {
             {
                 SharedPtr<WorkItem> shadowItem = queue->GetFreeItem();
                 SharedPtr<WorkItem> shadowItem = queue->GetFreeItem();
-                shadowItem->priority_ = M_MAX_UNSIGNED;
+                shadowItem->priority_ = WI_MAX_PRIORITY;
                 shadowItem->workFunction_ = SortShadowQueueWork;
                 shadowItem->workFunction_ = SortShadowQueueWork;
                 shadowItem->start_ = &(*i);
                 shadowItem->start_ = &(*i);
                 queue->AddWorkItem(shadowItem);
                 queue->AddWorkItem(shadowItem);
@@ -1343,7 +1343,7 @@ void View::UpdateGeometries()
                     end = start + drawablesPerItem;
                     end = start + drawablesPerItem;
 
 
                 SharedPtr<WorkItem> item = queue->GetFreeItem();
                 SharedPtr<WorkItem> item = queue->GetFreeItem();
-                item->priority_ = M_MAX_UNSIGNED;
+                item->priority_ = WI_MAX_PRIORITY;
                 item->workFunction_ = UpdateDrawableGeometriesWork;
                 item->workFunction_ = UpdateDrawableGeometriesWork;
                 item->aux_ = const_cast<FrameInfo*>(&frame_);
                 item->aux_ = const_cast<FrameInfo*>(&frame_);
                 item->start_ = &(*start);
                 item->start_ = &(*start);
@@ -1360,7 +1360,7 @@ void View::UpdateGeometries()
     }
     }
 
 
     // Finally ensure all threaded work has completed
     // Finally ensure all threaded work has completed
-    queue->Complete(M_MAX_UNSIGNED);
+    queue->Complete(WI_MAX_PRIORITY);
     geometriesUpdated_ = true;
     geometriesUpdated_ = true;
 }
 }
 
 

+ 2 - 2
Source/Urho3D/Graphics/View.h

@@ -89,8 +89,8 @@ static const unsigned MAX_VIEWPORT_TEXTURES = 2;
 /// Internal structure for 3D rendering work. Created for each backbuffer and texture viewport, but not for shadow cameras.
 /// Internal structure for 3D rendering work. Created for each backbuffer and texture viewport, but not for shadow cameras.
 class URHO3D_API View : public Object
 class URHO3D_API View : public Object
 {
 {
-    friend void CheckVisibilityWork(const WorkItem* item, unsigned threadIndex);
-    friend void ProcessLightWork(const WorkItem* item, unsigned threadIndex);
+    friend void CheckVisibilityWork(const WorkItem* item, i32 threadIndex);
+    friend void ProcessLightWork(const WorkItem* item, i32 threadIndex);
 
 
     URHO3D_OBJECT(View, Object);
     URHO3D_OBJECT(View, Object);
 
 

+ 3 - 3
Source/Urho3D/Urho2D/Renderer2D.cpp

@@ -284,7 +284,7 @@ SharedPtr<Material> Renderer2D::CreateMaterial(Texture2D* texture, BlendMode ble
     return newMaterial;
     return newMaterial;
 }
 }
 
 
-void CheckDrawableVisibilityWork(const WorkItem* item, unsigned threadIndex)
+void CheckDrawableVisibilityWork(const WorkItem* item, i32 threadIndex)
 {
 {
     auto* renderer = reinterpret_cast<Renderer2D*>(item->aux_);
     auto* renderer = reinterpret_cast<Renderer2D*>(item->aux_);
     auto** start = reinterpret_cast<Drawable2D**>(item->start_);
     auto** start = reinterpret_cast<Drawable2D**>(item->start_);
@@ -326,7 +326,7 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
         for (int i = 0; i < numWorkItems; ++i)
         for (int i = 0; i < numWorkItems; ++i)
         {
         {
             SharedPtr<WorkItem> item = queue->GetFreeItem();
             SharedPtr<WorkItem> item = queue->GetFreeItem();
-            item->priority_ = M_MAX_UNSIGNED;
+            item->priority_ = WI_MAX_PRIORITY;
             item->workFunction_ = CheckDrawableVisibilityWork;
             item->workFunction_ = CheckDrawableVisibilityWork;
             item->aux_ = this;
             item->aux_ = this;
 
 
@@ -341,7 +341,7 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
             start = end;
             start = end;
         }
         }
 
 
-        queue->Complete(M_MAX_UNSIGNED);
+        queue->Complete(WI_MAX_PRIORITY);
     }
     }
 
 
     ViewBatchInfo2D& viewBatchInfo = viewBatchInfos_[camera];
     ViewBatchInfo2D& viewBatchInfo = viewBatchInfos_[camera];

+ 1 - 1
Source/Urho3D/Urho2D/Renderer2D.h

@@ -51,7 +51,7 @@ class URHO3D_API Renderer2D : public Drawable
 {
 {
     URHO3D_OBJECT(Renderer2D, Drawable);
     URHO3D_OBJECT(Renderer2D, Drawable);
 
 
-    friend void CheckDrawableVisibilityWork(const WorkItem* item, unsigned threadIndex);
+    friend void CheckDrawableVisibilityWork(const WorkItem* item, i32 threadIndex);
 
 
 public:
 public:
     /// Construct.
     /// Construct.