win-pvdrivers

view liblfds.6/src/single_dir_for_windows_kernel/slist_new.c @ 1106:2d392ecdd366

Fix race is xenvbd causing 30 second freeze under high load
author James Harper <james.harper@bendigoit.com.au>
date Tue Nov 11 23:08:11 2014 +1100 (2014-11-11)
parents 6300617040e0
children
line source
1 #include "slist_internal.h"
7 /****************************************************************************/
8 int slist_new( struct slist_state **ss, void (*user_data_delete_function)(void *user_data, void *user_state), void *user_state )
9 {
10 int
11 rv = 0;
13 assert( ss != NULL );
14 // TRD : user_data_delete_function can be NULL
15 // TRD : user_state can be NULL
17 *ss = (struct slist_state *) abstraction_aligned_malloc( sizeof(struct slist_state), ALIGN_SINGLE_POINTER );
19 if( *ss != NULL )
20 {
21 slist_internal_init_slist( *ss, user_data_delete_function, user_state );
22 rv = 1;
23 }
25 return( rv );
26 }
32 /****************************************************************************/
33 void slist_internal_init_slist( struct slist_state *ss, void (*user_data_delete_function)(void *user_data, void *user_state), void *user_state )
34 {
35 assert( ss != NULL );
36 // TRD : user_data_delete_function can be NULL
37 // TRD : user_state can be NULL
39 ss->head = NULL;
40 ss->user_data_delete_function = user_data_delete_function;
41 ss->user_state = user_state;
43 return;
44 }
50 /****************************************************************************/
51 struct slist_element *slist_new_head( struct slist_state *ss, void *user_data )
52 {
53 ALIGN(ALIGN_SINGLE_POINTER) struct slist_element
54 *volatile se;
56 assert( ss != NULL );
57 // TRD : user_data can be NULL
59 se = (struct slist_element *) abstraction_aligned_malloc( sizeof(struct slist_element), ALIGN_DOUBLE_POINTER );
61 if( se != NULL )
62 {
63 se->user_data_and_flags[SLIST_USER_DATA] = user_data;
64 se->user_data_and_flags[SLIST_FLAGS] = SLIST_NO_FLAGS;
66 slist_internal_link_element_to_head( ss, se );
67 }
69 return( (struct slist_element *) se );
70 }
76 /****************************************************************************/
77 struct slist_element *slist_new_next( struct slist_element *se, void *user_data )
78 {
79 ALIGN(ALIGN_SINGLE_POINTER) struct slist_element
80 *volatile se_next;
82 assert( se != NULL );
83 // TRD : user_data can be NULL
85 se_next = (struct slist_element *) abstraction_aligned_malloc( sizeof(struct slist_element), ALIGN_DOUBLE_POINTER );
87 if( se_next != NULL )
88 {
89 se_next->user_data_and_flags[SLIST_USER_DATA] = user_data;
90 se_next->user_data_and_flags[SLIST_FLAGS] = SLIST_NO_FLAGS;
92 slist_internal_link_element_after_element( se, se_next );
93 }
95 return( (struct slist_element *) se_next );
96 }