]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libbenchmark/src/libbenchmark_datastructures_freelist/libbenchmark_datastructure_freelist_windows_critical_section.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / test_and_benchmark / libbenchmark / src / libbenchmark_datastructures_freelist / libbenchmark_datastructure_freelist_windows_critical_section.c
1 /***** includes *****/
2 #include "libbenchmark_datastructure_freelist_internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 void libbenchmark_datastructure_freelist_windows_critical_section_init( struct libbenchmark_datastructure_freelist_windows_critical_section_state *fs, void *user_state )
10 {
11   LFDS710_PAL_ASSERT( fs != NULL );
12   LFDS710_PAL_ASSERT( user_state == NULL );
13
14   fs->top = NULL;
15   fs->user_state = user_state;
16
17   LIBBENCHMARK_PAL_LOCK_WINDOWS_CRITICAL_SECTION_CREATE( fs->lock );
18
19   LFDS710_MISC_BARRIER_STORE;
20
21   lfds710_misc_force_store();
22
23   return;
24 }
25
26
27
28
29
30 /****************************************************************************/
31 void libbenchmark_datastructure_freelist_windows_critical_section_cleanup( struct libbenchmark_datastructure_freelist_windows_critical_section_state *fs, void (*element_pop_callback)(struct libbenchmark_datastructure_freelist_windows_critical_section_state *fs, struct libbenchmark_datastructure_freelist_windows_critical_section_element *fe, void *user_state) )
32 {
33   struct libbenchmark_datastructure_freelist_windows_critical_section_element
34     *fe,
35     *fe_temp;
36
37   LFDS710_PAL_ASSERT( fs != NULL );
38   // TRD : element_pop_callback can be NULL
39
40   LFDS710_MISC_BARRIER_LOAD;
41
42   if( element_pop_callback != NULL )
43   {
44     fe = fs->top;
45
46     while( fe != NULL )
47     {
48       fe_temp = fe;
49       fe = fe->next;
50
51       element_pop_callback( fs, fe_temp, (void *) fs->user_state );
52     }
53   }
54
55   LIBBENCHMARK_PAL_LOCK_WINDOWS_CRITICAL_SECTION_DESTROY( fs->lock );
56
57   return;
58 }
59
60
61
62
63
64 /****************************************************************************/
65 void libbenchmark_datastructure_freelist_windows_critical_section_push( struct libbenchmark_datastructure_freelist_windows_critical_section_state *fs, struct libbenchmark_datastructure_freelist_windows_critical_section_element *fe )
66 {
67   LFDS710_PAL_ASSERT( fs != NULL );
68   LFDS710_PAL_ASSERT( fe != NULL );
69
70   LIBBENCHMARK_PAL_LOCK_WINDOWS_CRITICAL_SECTION_GET( fs->lock );
71
72   fe->next = fs->top;
73   fs->top = fe;
74
75   LIBBENCHMARK_PAL_LOCK_WINDOWS_CRITICAL_SECTION_RELEASE( fs->lock );
76
77   return;
78 }
79
80
81
82
83
84 /****************************************************************************/
85 #pragma warning( disable : 4100 )
86
87 int libbenchmark_datastructure_freelist_windows_critical_section_pop( struct libbenchmark_datastructure_freelist_windows_critical_section_state *fs, struct libbenchmark_datastructure_freelist_windows_critical_section_element **fe )
88 {
89   int
90     rv = 1;
91
92   LFDS710_PAL_ASSERT( fs != NULL );
93   LFDS710_PAL_ASSERT( fe != NULL );
94
95   LIBBENCHMARK_PAL_LOCK_WINDOWS_CRITICAL_SECTION_GET( fs->lock );
96
97   *fe = fs->top;
98
99   if( fs->top != NULL )
100     fs->top = fs->top->next;
101   else
102     rv = 0;
103
104   LIBBENCHMARK_PAL_LOCK_WINDOWS_CRITICAL_SECTION_RELEASE( fs->lock );
105
106   return rv;
107 }
108
109 #pragma warning( default : 4100 )
110