]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.0.0/liblfds700/src/lfds700_freelist/lfds700_freelist_pop.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.0.0 / liblfds700 / src / lfds700_freelist / lfds700_freelist_pop.c
1 /***** includes *****/
2 #include "lfds700_freelist_internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 int lfds700_freelist_pop( struct lfds700_freelist_state *fs, struct lfds700_freelist_element **fe, struct lfds700_misc_prng_state *ps )
10 {
11   char unsigned
12     result;
13
14   lfds700_pal_uint_t
15     backoff_iteration = LFDS700_MISC_ABSTRACTION_BACKOFF_INITIAL_VALUE;
16
17   struct lfds700_freelist_element LFDS700_PAL_ALIGN(LFDS700_PAL_ALIGN_DOUBLE_POINTER)
18     *new_top[PAC_SIZE],
19     *volatile original_top[PAC_SIZE];
20
21   LFDS700_PAL_ASSERT( fs != NULL );
22   LFDS700_PAL_ASSERT( fe != NULL );
23   LFDS700_PAL_ASSERT( ps != NULL );
24
25   LFDS700_PAL_BARRIER_PROCESSOR_LOAD;
26
27   original_top[COUNTER] = fs->top[COUNTER];
28   original_top[POINTER] = fs->top[POINTER];
29
30   do
31   {
32     if( original_top[POINTER] == NULL )
33     {
34       *fe = NULL;
35       return( 0 );
36     }
37
38     new_top[COUNTER] = original_top[COUNTER] + 1;
39     new_top[POINTER] = original_top[POINTER]->next;
40
41     LFDS700_PAL_ATOMIC_DWCAS_WITH_BACKOFF( &fs->top, original_top, new_top, LFDS700_MISC_CAS_STRENGTH_WEAK, result, backoff_iteration, ps );
42
43     if( result != 1 )
44       LFDS700_PAL_BARRIER_PROCESSOR_LOAD;
45   }
46   while( result != 1 );
47
48   *fe = original_top[POINTER];
49
50   return( 1 );
51 }
52