win-pvdrivers

view liblfds.6/src/single_dir_for_windows_kernel/freelist_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 "freelist_internal.h"
7 /****************************************************************************/
8 int freelist_new( struct freelist_state **fs, atom_t number_elements, int (*user_data_init_function)(void **user_data, void *user_state), void *user_state )
9 {
10 int
11 rv = 0;
13 atom_t
14 element_count;
16 assert( fs != NULL );
17 // TRD : number_elements can be any value in its range
18 // TRD : user_data_init_function can be NULL
20 *fs = (struct freelist_state *) abstraction_aligned_malloc( sizeof(struct freelist_state), ALIGN_DOUBLE_POINTER );
22 if( (*fs) != NULL )
23 {
24 (*fs)->top[FREELIST_POINTER] = NULL;
25 (*fs)->top[FREELIST_COUNTER] = 0;
26 (*fs)->user_data_init_function = user_data_init_function;
27 (*fs)->user_state = user_state;
28 (*fs)->aba_counter = 0;
29 (*fs)->element_count = 0;
31 element_count = freelist_new_elements( *fs, number_elements );
33 if( element_count == number_elements )
34 rv = 1;
36 if( element_count != number_elements )
37 {
38 abstraction_aligned_free( (*fs) );
39 *fs = NULL;
40 }
41 }
43 return( rv );
44 }
50 /****************************************************************************/
51 atom_t freelist_new_elements( struct freelist_state *fs, atom_t number_elements )
52 {
53 struct freelist_element
54 *fe;
56 atom_t
57 loop,
58 count = 0;
60 assert( fs != NULL );
61 // TRD : number_elements can be any value in its range
62 // TRD : user_data_init_function can be NULL
64 for( loop = 0 ; loop < number_elements ; loop++ )
65 if( freelist_internal_new_element(fs, &fe) )
66 {
67 freelist_push( fs, fe );
68 count++;
69 }
71 return( count );
72 }
78 /****************************************************************************/
79 atom_t freelist_internal_new_element( struct freelist_state *fs, struct freelist_element **fe )
80 {
81 atom_t
82 rv = 0;
84 assert( fs != NULL );
85 assert( fe != NULL );
87 /* TRD : basically, does what you'd expect;
89 allocates an element
90 calls the user init function
91 if anything fails, cleans up,
92 sets *fe to NULL
93 and returns 0
94 */
96 *fe = (struct freelist_element *) abstraction_aligned_malloc( sizeof(struct freelist_element), ALIGN_DOUBLE_POINTER );
98 if( *fe != NULL )
99 {
100 if( fs->user_data_init_function == NULL )
101 {
102 (*fe)->user_data = NULL;
103 rv = 1;
104 }
106 if( fs->user_data_init_function != NULL )
107 {
108 rv = fs->user_data_init_function( &(*fe)->user_data, fs->user_state );
110 if( rv == 0 )
111 {
112 abstraction_aligned_free( *fe );
113 *fe = NULL;
114 }
115 }
116 }
118 if( rv == 1 )
119 abstraction_increment( (atom_t *) &fs->element_count );
121 return( rv );
122 }