win-pvdrivers

view liblfds.6/src/stack/stack_push_pop.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 "stack_internal.h"
7 /****************************************************************************/
8 int stack_push( struct stack_state *ss, void *user_data )
9 {
10 ALIGN(ALIGN_DOUBLE_POINTER) struct stack_element
11 *se[STACK_PAC_SIZE];
13 assert( ss != NULL );
14 // TRD : user_data can be NULL
16 stack_internal_new_element_from_freelist( ss, se, user_data );
18 if( se[STACK_POINTER] == NULL )
19 return( 0 );
21 stack_internal_push( ss, se );
23 return( 1 );
24 }
30 /****************************************************************************/
31 int stack_guaranteed_push( struct stack_state *ss, void *user_data )
32 {
33 ALIGN(ALIGN_DOUBLE_POINTER) struct stack_element
34 *se[STACK_PAC_SIZE];
36 assert( ss != NULL );
37 // TRD : user_data can be NULL
39 /* TRD : this function allocated a new freelist element and uses that
40 to push onto the stack, guaranteeing success (unless malloc()
41 fails of course)
42 */
44 stack_internal_new_element( ss, se, user_data );
46 // TRD : malloc failed
47 if( se[STACK_POINTER] == NULL )
48 return( 0 );
50 stack_internal_push( ss, se );
52 return( 1 );
53 }
59 /****************************************************************************/
60 void stack_internal_push( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE] )
61 {
62 ALIGN(ALIGN_DOUBLE_POINTER) struct stack_element
63 *original_se_next[STACK_PAC_SIZE];
65 assert( ss != NULL );
66 assert( se != NULL );
68 original_se_next[STACK_POINTER] = ss->top[STACK_POINTER];
69 original_se_next[STACK_COUNTER] = ss->top[STACK_COUNTER];
71 do
72 {
73 se[STACK_POINTER]->next[STACK_POINTER] = original_se_next[STACK_POINTER];
74 se[STACK_POINTER]->next[STACK_COUNTER] = original_se_next[STACK_COUNTER];
75 }
76 while( 0 == abstraction_dcas((volatile atom_t *) ss->top, (atom_t *) se, (atom_t *) original_se_next) );
78 return;
79 }
85 /****************************************************************************/
86 int stack_pop( struct stack_state *ss, void **user_data )
87 {
88 ALIGN(ALIGN_DOUBLE_POINTER) struct stack_element
89 *se[STACK_PAC_SIZE];
91 assert( ss != NULL );
92 assert( user_data != NULL );
94 se[STACK_COUNTER] = ss->top[STACK_COUNTER];
95 se[STACK_POINTER] = ss->top[STACK_POINTER];
97 do
98 {
99 if( se[STACK_POINTER] == NULL )
100 return( 0 );
101 }
102 while( 0 == abstraction_dcas((volatile atom_t *) ss->top, (atom_t *) se[STACK_POINTER]->next, (atom_t *) se) );
104 *user_data = se[STACK_POINTER]->user_data;
106 freelist_push( ss->fs, se[STACK_POINTER]->fe );
108 return( 1 );
109 }