win-pvdrivers

view liblfds.6/src/single_dir_for_windows_kernel/stack_new.c @ 766:6300617040e0

Big changes - not ready for production use.
Removed all the custom DMA handling code as it was completely incompatible with the Windows verifier.
Added liblfds (using the lock free stack) from liblfds.org so that grant's can be obtained at DIRQL.
Fixed xennet and xenvbd to support the changes.
xenusb and xenscsi almost certainly will not yet work after the changes.
author James Harper <james.harper@bendigoit.com.au>
date Sun Jan 31 21:28:42 2010 +1100 (2010-01-31)
parents
children
line source
1 #include "stack_internal.h"
7 /****************************************************************************/
8 int stack_new( struct stack_state **ss, atom_t number_elements )
9 {
10 int
11 rv = 0;
13 assert( ss != NULL );
14 // TRD : number_elements can be any value in its range
16 *ss = (struct stack_state *) abstraction_aligned_malloc( sizeof(struct stack_state), ALIGN_DOUBLE_POINTER );
18 if( *ss != NULL )
19 {
20 // TRD : the size of the freelist is the size of the stack
21 freelist_new( &(*ss)->fs, number_elements, stack_internal_freelist_init_function, NULL );
23 if( (*ss)->fs == NULL )
24 {
25 abstraction_aligned_free( *ss );
26 *ss = NULL;
27 }
29 if( (*ss)->fs != NULL )
30 {
31 (*ss)->top[STACK_POINTER] = NULL;
32 (*ss)->top[STACK_COUNTER] = 0;
33 (*ss)->aba_counter = 0;
34 rv = 1;
35 }
36 }
38 return( rv );
39 }
45 /****************************************************************************/
46 #pragma warning( disable : 4100 )
48 int stack_internal_freelist_init_function( void **user_data, void *user_state )
49 {
50 int
51 rv = 0;
53 assert( user_data != NULL );
54 assert( user_state == NULL );
56 *user_data = abstraction_aligned_malloc( sizeof(struct stack_element), ALIGN_DOUBLE_POINTER );
58 if( *user_data != NULL )
59 rv = 1;
61 return( rv );
62 }
64 #pragma warning( default : 4100 )
70 /****************************************************************************/
71 void stack_internal_new_element_from_freelist( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE], void *user_data )
72 {
73 struct freelist_element
74 *fe;
76 assert( ss != NULL );
77 assert( se != NULL );
78 // TRD : user_data can be any value in its range
80 freelist_pop( ss->fs, &fe );
82 if( fe == NULL )
83 se[STACK_POINTER] = NULL;
85 if( fe != NULL )
86 stack_internal_init_element( ss, se, fe, user_data );
88 return;
89 }
95 /****************************************************************************/
96 void stack_internal_new_element( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE], void *user_data )
97 {
98 struct freelist_element
99 *fe;
101 assert( ss != NULL );
102 assert( se != NULL );
103 // TRD : user_data can be any value in its range
105 freelist_guaranteed_pop( ss->fs, &fe );
107 if( fe == NULL )
108 se[STACK_POINTER] = NULL;
110 if( fe != NULL )
111 stack_internal_init_element( ss, se, fe, user_data );
113 return;
114 }
120 /****************************************************************************/
121 void stack_internal_init_element( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE], struct freelist_element *fe, void *user_data )
122 {
123 assert( ss != NULL );
124 assert( se != NULL );
125 assert( fe != NULL );
126 // TRD : user_data can be any value in its range
128 freelist_get_user_data_from_element( fe, (void **) &se[STACK_POINTER] );
130 se[STACK_COUNTER] = (struct stack_element *) abstraction_increment( (atom_t *) &ss->aba_counter );
132 se[STACK_POINTER]->next[STACK_POINTER] = NULL;
133 se[STACK_POINTER]->next[STACK_COUNTER] = 0;
134 se[STACK_POINTER]->fe = fe;
135 se[STACK_POINTER]->user_data = user_data;
137 return;
138 }