win-pvdrivers

view liblfds.6/src/slist/slist_get_and_set.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 "slist_internal.h"
7 /****************************************************************************/
8 int slist_get_user_data_from_element( struct slist_element *se, void **user_data )
9 {
10 int
11 rv = 1;
13 assert( se != NULL );
14 assert( user_data != NULL );
16 *user_data = (void *) se->user_data_and_flags[SLIST_USER_DATA];
18 if( (atom_t) se->user_data_and_flags[SLIST_FLAGS] & SLIST_FLAG_DELETED )
19 rv = 0;
21 return( rv );
22 }
28 /****************************************************************************/
29 int slist_set_user_data_in_element( struct slist_element *se, void *user_data )
30 {
31 ALIGN(ALIGN_DOUBLE_POINTER) volatile void
32 *user_data_and_flags[2],
33 *new_user_data_and_flags[2];
35 int
36 rv = 1;
38 assert( se != NULL );
39 // TRD : user_data can be NULL
41 user_data_and_flags[SLIST_USER_DATA] = se->user_data_and_flags[SLIST_USER_DATA];
42 user_data_and_flags[SLIST_FLAGS] = se->user_data_and_flags[SLIST_FLAGS];
44 new_user_data_and_flags[SLIST_USER_DATA] = user_data;
46 do
47 {
48 new_user_data_and_flags[SLIST_FLAGS] = user_data_and_flags[SLIST_FLAGS];
49 }
50 while( !((atom_t) user_data_and_flags[SLIST_FLAGS] & SLIST_FLAG_DELETED) and 0 == abstraction_dcas((volatile atom_t *) se->user_data_and_flags, (atom_t *) new_user_data_and_flags, (atom_t *) user_data_and_flags) );
52 if( (atom_t) user_data_and_flags[SLIST_FLAGS] & SLIST_FLAG_DELETED )
53 rv = 0;
55 return( rv );
56 }
62 /****************************************************************************/
63 struct slist_element *slist_get_head( struct slist_state *ss, struct slist_element **se )
64 {
65 assert( ss != NULL );
66 assert( se != NULL );
68 *se = (struct slist_element *) ss->head;
70 slist_internal_move_to_first_undeleted_element( se );
72 return( *se );
73 }
79 /****************************************************************************/
80 struct slist_element *slist_get_next( struct slist_element *se, struct slist_element **next_se )
81 {
82 assert( se != NULL );
83 assert( next_se != NULL );
85 *next_se = (struct slist_element *) se->next;
87 slist_internal_move_to_first_undeleted_element( next_se );
89 return( *next_se );
90 }
96 /****************************************************************************/
97 struct slist_element *slist_get_head_and_then_next( struct slist_state *ss, struct slist_element **se )
98 {
99 assert( ss != NULL );
100 assert( se != NULL );
102 if( *se == NULL )
103 slist_get_head( ss, se );
104 else
105 slist_get_next( *se, se );
107 return( *se );
108 }
114 /****************************************************************************/
115 void slist_internal_move_to_first_undeleted_element( struct slist_element **se )
116 {
117 assert( se != NULL );
119 while( *se != NULL and (atom_t) (*se)->user_data_and_flags[SLIST_FLAGS] & SLIST_FLAG_DELETED )
120 (*se) = (struct slist_element *) (*se)->next;
122 return;
123 }