win-pvdrivers

view liblfds.6/src/single_dir_for_windows_kernel/queue_new.c @ 1025:aa2e51f67f7c

Fix hibernate under Win8. Change debugprints.
author James Harper <james.harper@bendigoit.com.au>
date Tue Feb 19 15:14:53 2013 +1100 (2013-02-19)
parents 6300617040e0
children
line source
1 #include "queue_internal.h"
7 /****************************************************************************/
8 int queue_new( struct queue_state **qs, atom_t number_elements )
9 {
10 int
11 rv = 0;
13 struct queue_element
14 *qe[QUEUE_PAC_SIZE];
16 assert( qs != NULL );
17 // TRD : number_elements can be any value in its range
19 *qs = (struct queue_state *) abstraction_aligned_malloc( sizeof(struct queue_state), ALIGN_DOUBLE_POINTER );
21 if( *qs != NULL )
22 {
23 // TRD : the size of the freelist is the size of the queue (+1 for the leading dummy element, which is hidden from the caller)
24 freelist_new( &(*qs)->fs, number_elements+1, queue_internal_freelist_init_function, NULL );
26 if( (*qs)->fs != NULL )
27 {
28 queue_internal_new_element_from_freelist( *qs, qe, NULL );
29 (*qs)->enqueue[QUEUE_POINTER] = (*qs)->dequeue[QUEUE_POINTER] = qe[QUEUE_POINTER];
30 (*qs)->aba_counter = 0;
31 rv = 1;
32 }
34 if( (*qs)->fs == NULL )
35 {
36 abstraction_aligned_free( *qs );
37 *qs = NULL;
38 }
39 }
41 return( rv );
42 }
48 /****************************************************************************/
49 #pragma warning( disable : 4100 )
51 int queue_internal_freelist_init_function( void **user_data, void *user_state )
52 {
53 int
54 rv = 0;
56 assert( user_data != NULL );
57 assert( user_state == NULL );
59 *user_data = abstraction_aligned_malloc( sizeof(struct queue_element), ALIGN_DOUBLE_POINTER );
61 if( *user_data != NULL )
62 rv = 1;
64 return( rv );
65 }
67 #pragma warning( default : 4100 )
73 /****************************************************************************/
74 void queue_internal_new_element_from_freelist( struct queue_state *qs, struct queue_element *qe[QUEUE_PAC_SIZE], void *user_data )
75 {
76 struct freelist_element
77 *fe;
79 assert( qs != NULL );
80 assert( qe != NULL );
81 // TRD : user_data can be any value in its range
83 qe[QUEUE_POINTER] = NULL;
85 freelist_pop( qs->fs, &fe );
87 if( fe != NULL )
88 queue_internal_init_element( qs, qe, fe, user_data );
90 return;
91 }
97 /****************************************************************************/
98 void queue_internal_guaranteed_new_element_from_freelist( struct queue_state *qs, struct queue_element *qe[QUEUE_PAC_SIZE], void *user_data )
99 {
100 struct freelist_element
101 *fe;
103 assert( qs != NULL );
104 assert( qe != NULL );
105 // TRD : user_data can be any value in its range
107 qe[QUEUE_POINTER] = NULL;
109 freelist_guaranteed_pop( qs->fs, &fe );
111 if( fe != NULL )
112 queue_internal_init_element( qs, qe, fe, user_data );
114 return;
115 }
121 /****************************************************************************/
122 void queue_internal_init_element( struct queue_state *qs, struct queue_element *qe[QUEUE_PAC_SIZE], struct freelist_element *fe, void *user_data )
123 {
124 assert( qs != NULL );
125 assert( qe != NULL );
126 assert( fe != NULL );
127 // TRD : user_data can be any value in its range
129 freelist_get_user_data_from_element( fe, (void **) &qe[QUEUE_POINTER] );
130 qe[QUEUE_COUNTER] = (struct queue_element *) abstraction_increment( (atom_t *) &qs->aba_counter );
132 qe[QUEUE_POINTER]->next[QUEUE_POINTER] = NULL;
133 qe[QUEUE_POINTER]->next[QUEUE_COUNTER] = (struct queue_element *) abstraction_increment( (atom_t *) &qs->aba_counter );
135 qe[QUEUE_POINTER]->fe = fe;
136 qe[QUEUE_POINTER]->user_data = user_data;
138 return;
139 }