VulkanRaytracingCycles 0.0.0
Cycles Render Engine With VulkanRaytracingShaderModules. ( Experiment , in progress)
front::heapQ< S > Struct Template Reference

#include <SignalVk.h>

Public Types

typedef int64_t c1type
 
typedef hq_elem< c1typeelemtype
 

Public Member Functions

 heapQ ()
 heapQ(CRITICAL_SECTION * cs) :critical(cs){}; More...
 
 ~heapQ ()
 
template<class T , class... _Valty>
bool push (T &&cls, _Valty &&... _Val)
 
bool pop (elemtype &el)
 
void print ()
 
int toRoot (size_t pos)
 
int toLeaf (size_t pos)
 
template<class T , class... _Valty>
bool pushmock (T &&cls, _Valty &&... _Val)
 
void popmock (elemtype &el)
 

Public Attributes

size_t len = 0
 
size_t pvt = 0
 
elemtype elem [S]
 
CRITICAL_SECTION critical
 
std::stringstream debug
 
long entering = 0
 

Detailed Description

template<size_t S>
struct front::heapQ< S >

Definition at line 193 of file SignalVk.h.

Member Typedef Documentation

◆ c1type

template<size_t S>
typedef int64_t front::heapQ< S >::c1type

Definition at line 195 of file SignalVk.h.

◆ elemtype

template<size_t S>
typedef hq_elem<c1type> front::heapQ< S >::elemtype

Definition at line 196 of file SignalVk.h.

Constructor & Destructor Documentation

◆ heapQ()

template<size_t S>
front::heapQ< S >::heapQ ( )
inline

heapQ(CRITICAL_SECTION * cs) :critical(cs){};

Definition at line 205 of file SignalVk.h.

205 {
206
207 InitializeCriticalSectionAndSpinCount(&critical, 8000);
208 };
CRITICAL_SECTION critical
Definition: SignalVk.h:201

◆ ~heapQ()

template<size_t S>
front::heapQ< S >::~heapQ ( )
inline

Definition at line 209 of file SignalVk.h.

209 {
210
211 DeleteCriticalSection(&critical);
212 };

Member Function Documentation

◆ pop()

template<size_t S>
bool front::heapQ< S >::pop ( elemtype el)
inline

log_allo("Q pop %p len %u \n", el,len);

log_allo("Q[%u] toLeaf len %u \n", pvt, len);

Definition at line 235 of file SignalVk.h.

235 {
236
237 EnterCriticalSection(&critical);
238
239 if (len <= 0){
240 LeaveCriticalSection(&critical);
241 return false;
242 }
243 el = std::move(elem[pvt]);
245 if (len == 1) {
246 len = 0;
247 LeaveCriticalSection(&critical);
248 return true;
249 }
250 elem[pvt] = std::move(elem[id2pv(len - 1)]);
251 len--;
252 toLeaf(pvt);
254
255 LeaveCriticalSection(&critical);
256
257 return true;
258 }
#define id2pv(p)
Definition: SignalVk.h:190
size_t pvt
Definition: SignalVk.h:199
size_t len
Definition: SignalVk.h:198
elemtype elem[S]
Definition: SignalVk.h:200
int toLeaf(size_t pos)
Definition: SignalVk.h:299

◆ popmock()

template<size_t S>
void front::heapQ< S >::popmock ( elemtype el)
inline

debug << "pop " <<pvt << " len "<< len <<" enteringNum " << entering << "\n";

Definition at line 344 of file SignalVk.h.

344 {
345
346 static int cnt = 0;
347
348
349 EnterCriticalSection(&critical);
350 InterlockedIncrement(&entering);
351 el = std::move(elem[pvt]);
352 pvt = (pvt + 1) % S;
353 len--;
355 InterlockedDecrement(&entering);
356 LeaveCriticalSection(&critical);
357
358 return;
359 };
long entering
Definition: SignalVk.h:203

◆ print()

template<size_t S>
void front::heapQ< S >::print ( )
inline

Definition at line 259 of file SignalVk.h.

259 {
260
261#define pushPRINT
262#ifdef pushPRINT
263 printf("################### pusher ##################\n");
264 int lev = 1;
265 int levsize = 1;
266 for (int i = 0; i < len; i++) {
267 if (levsize <= i) {
268 lev *= 2; levsize += lev; printf("\n");
269 }
270 for (int j = 0; j < (64 - 10 * lev); j++)printf(" ");
271 printf(" %lld ", elem[id2pv(i)].compare);
272
273 };
274 printf("\n");
275#endif
276 }

◆ push()

template<size_t S>
template<class T , class... _Valty>
bool front::heapQ< S >::push ( T &&  cls,
_Valty &&...  _Val 
)
inline

Definition at line 215 of file SignalVk.h.

215 {
216
217
218 EnterCriticalSection(&critical);
219 if (len >= S) {
220 LeaveCriticalSection(&critical);
221 return false;
222 }
223
224 size_t pos = (pvt + len) % S;
225 elem[pos].set(std::forward<T>(cls));
226 elem[pos].setComp(_Val ...);
227
228 toRoot(pos);
229 len++;
230 LeaveCriticalSection(&critical);
231
232 return true;
233
234 };
int toRoot(size_t pos)
Definition: SignalVk.h:279
void setComp(C1 comp, C2 comp2=0, C3 comp3=0)
Definition: SignalVk.h:162
void set(T &&cls)
Definition: SignalVk.h:166

◆ pushmock()

template<size_t S>
template<class T , class... _Valty>
bool front::heapQ< S >::pushmock ( T &&  cls,
_Valty &&...  _Val 
)
inline

std::this_thread::sleep_for(std::chrono::milliseconds(1)); debug << "push " << pvt << " len " << len << " enteringNum " << entering << "\n";

Definition at line 324 of file SignalVk.h.

324 {
325
326
327 EnterCriticalSection(&critical);
328 if (len >= S) {
329 LeaveCriticalSection(&critical);
330 return false;
331 }
332 InterlockedIncrement(&entering);
333 size_t pos = (pvt + len) % S;
334 elem[pos].set(std::forward<T>(cls));
335 elem[pos].setComp(_Val ...);
336 len++;
337 //log_allo("push pvt %zu len %zu \n", pvt ,len);
340 InterlockedDecrement(&entering);
341 LeaveCriticalSection(&critical);
342 return true;
343 }

◆ toLeaf()

template<size_t S>
int front::heapQ< S >::toLeaf ( size_t  pos)
inline

Definition at line 299 of file SignalVk.h.

300 {
301 size_t _pos, startpos, endpos, childpos;
302 elemtype a, b;
303 endpos = len - 1;
304 _pos = startpos = pv2id(pos);
305 while (true) {
306 childpos = 2 * _pos + 1;
307 if (childpos > len - 1) {
308 break;
309 }
310 a = elem[id2pv(childpos)];
311 b = elem[id2pv(_pos)];
312 if (a < b) {
313 elem[id2pv(childpos)] = std::move(b);
314 elem[id2pv(_pos)] = std::move(a);
315 _pos = childpos;
316 }
317 else break;
318
319 };
320 return 0;
321 };
#define pv2id(p)
Definition: SignalVk.h:189
hq_elem< c1type > elemtype
Definition: SignalVk.h:196

◆ toRoot()

template<size_t S>
int front::heapQ< S >::toRoot ( size_t  pos)
inline

Definition at line 279 of file SignalVk.h.

280 {
281 size_t ppos;
282 elemtype newitem, parent;
283 newitem = elem[pos];
284 while (pos > 0) {
285 ppos = id2pv(((pv2id(pos) - 1) >> 1));
286 parent = elem[ppos];
287 if (newitem < parent) {
288 parent = std::move(elem[ppos]);
289 newitem = std::move(elem[pos]);
290 elem[ppos] = std::move(newitem);
291 elem[pos] = std::move(parent);
292 pos = ppos;
293 if (pos == 0)break;
294 }
295 else break;
296 }
297 return 0;
298 };

Member Data Documentation

◆ critical

template<size_t S>
CRITICAL_SECTION front::heapQ< S >::critical

Definition at line 201 of file SignalVk.h.

◆ debug

template<size_t S>
std::stringstream front::heapQ< S >::debug

Definition at line 202 of file SignalVk.h.

◆ elem

template<size_t S>
elemtype front::heapQ< S >::elem[S]

Definition at line 200 of file SignalVk.h.

◆ entering

template<size_t S>
long front::heapQ< S >::entering = 0

Definition at line 203 of file SignalVk.h.

◆ len

template<size_t S>
size_t front::heapQ< S >::len = 0

Definition at line 198 of file SignalVk.h.

◆ pvt

template<size_t S>
size_t front::heapQ< S >::pvt = 0

Definition at line 199 of file SignalVk.h.


The documentation for this struct was generated from the following file: