@@ -303,11 +303,20 @@ lfqueue_deq(lfqueue_t *lfqueue) {
303303 __LFQ_FETCH_AND_ADD (& lfqueue -> size , -1 );
304304 return v ;
305305 }
306- // Rest the thread for other thread, to avoid keep looping force
307- lfqueue_sleep (1 );
308306 return NULL ;
309307}
310308
309+ void *
310+ lfqueue_deq_must (lfqueue_t * lfqueue ) {
311+ void * v ;
312+ while ( !(v = _dequeue (lfqueue )) ) {
313+ // Rest the thread for other thread, to avoid keep looping force
314+ lfqueue_sleep (1 );
315+ }
316+ __LFQ_FETCH_AND_ADD (& lfqueue -> size , -1 );
317+ return v ;
318+ }
319+
311320/**This is only applicable when only single thread consume only**/
312321void *
313322lfqueue_single_deq (lfqueue_t * lfqueue ) {
@@ -319,17 +328,27 @@ lfqueue_single_deq(lfqueue_t *lfqueue) {
319328 __LFQ_FETCH_AND_ADD (& lfqueue -> size , -1 );
320329 return v ;
321330 }
322- // Rest the thread for other thread, to avoid keep looping force
323- lfqueue_sleep (1 );
324331 return NULL ;
325332}
326333
334+ /**This is only applicable when only single thread consume only**/
335+ void *
336+ lfqueue_single_deq_must (lfqueue_t * lfqueue ) {
337+ void * v ;
338+ while ( !(v = _single_dequeue (lfqueue )) ) {
339+ // Rest the thread for other thread, to avoid keep looping force
340+ lfqueue_sleep (1 );
341+ }
342+ __LFQ_FETCH_AND_ADD (& lfqueue -> size , -1 );
343+ return v ;
344+ }
345+
327346size_t
328347lfqueue_size (lfqueue_t * lfqueue ) {
329348 return __LFQ_ADD_AND_FETCH (& lfqueue -> size , 0 );
330349}
331350
332- void
351+ void
333352lfqueue_sleep (unsigned int milisec ) {
334353#if defined __GNUC__ || defined __CYGWIN__ || defined __MINGW32__ || defined __APPLE__
335354#pragma GCC diagnostic push
0 commit comments