0027202: Visualization - add sensitivity Select3D_SensitivePrimitiveArray for Graphic...
[occt.git] / src / BVH / BVH_BuildQueue.cxx
1 // Created on: 2015-05-27
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2015 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BVH_BuildQueue.hxx>
17
18 // =======================================================================
19 // function : Size
20 // purpose  : Returns current size of BVH build queue
21 // =======================================================================
22 Standard_Integer BVH_BuildQueue::Size()
23 {
24   Standard_Integer aSize;
25
26   myMutex.Lock();
27   {
28     aSize = myQueue.Size();
29   }
30   myMutex.Unlock();
31
32   return aSize;
33 }
34
35 // =======================================================================
36 // function : Enqueue
37 // purpose  : Enqueues new work-item onto BVH build queue
38 // =======================================================================
39 void BVH_BuildQueue::Enqueue (const Standard_Integer& theWorkItem)
40 {
41   myMutex.Lock();
42   {
43     myQueue.Append (theWorkItem);
44   }
45   myMutex.Unlock();
46 }
47
48 // =======================================================================
49 // function : Fetch
50 // purpose  : Fetches first work-item from BVH build queue
51 // =======================================================================
52 Standard_Integer BVH_BuildQueue::Fetch (Standard_Boolean& wasBusy)
53 {
54   Standard_Integer aQuery = -1;
55   {
56     Standard_Mutex::Sentry aSentry (myMutex);
57
58     if (!myQueue.IsEmpty())
59     {
60       aQuery = myQueue.First();
61
62       myQueue.Remove (1); // remove item from queue
63     }
64
65     if (aQuery != -1)
66     {
67       if (!wasBusy)
68       {
69         ++myNbThreads;
70       }
71     }
72     else if (wasBusy)
73     {
74       --myNbThreads;
75     }
76
77     wasBusy = aQuery != -1;
78   }
79
80   return aQuery;
81 }