]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/liblfds710/src/lfds710_ringbuffer/lfds710_ringbuffer_cleanup.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / liblfds710 / src / lfds710_ringbuffer / lfds710_ringbuffer_cleanup.c
1 /***** includes *****/
2 #include "lfds710_ringbuffer_internal.h"
3
4 /***** private prototypes *****/
5 static void lfds710_ringbuffer_internal_queue_umm_element_cleanup_callback( struct lfds710_queue_umm_state *qumms,
6                                                                             struct lfds710_queue_umm_element *qumme,
7                                                                             enum lfds710_misc_flag dummy_element_flag );
8 static void lfds710_ringbuffer_internal_freelist_element_cleanup_callback( struct lfds710_freelist_state *fs,
9                                                                            struct lfds710_freelist_element *fe );
10
11
12
13
14
15 /****************************************************************************/
16 void lfds710_ringbuffer_cleanup( struct lfds710_ringbuffer_state *rs,
17                                  void (*element_cleanup_callback)(struct lfds710_ringbuffer_state *rs, void *key, void *value, enum lfds710_misc_flag unread_flag) )
18 {
19   LFDS710_PAL_ASSERT( rs != NULL );
20   // TRD : element_cleanup_callback can be NULL
21
22   if( element_cleanup_callback != NULL )
23   {
24     rs->element_cleanup_callback = element_cleanup_callback;
25     lfds710_queue_umm_cleanup( &rs->qumms, lfds710_ringbuffer_internal_queue_umm_element_cleanup_callback );
26     lfds710_freelist_cleanup( &rs->fs, lfds710_ringbuffer_internal_freelist_element_cleanup_callback );
27   }
28
29   return;
30 }
31
32
33
34
35
36 /****************************************************************************/
37 #pragma warning( disable : 4100 )
38
39 static void lfds710_ringbuffer_internal_queue_umm_element_cleanup_callback( struct lfds710_queue_umm_state *qumms,
40                                                                             struct lfds710_queue_umm_element *qumme,
41                                                                             enum lfds710_misc_flag dummy_element_flag )
42 {
43   struct lfds710_ringbuffer_element
44     *re;
45
46   struct lfds710_ringbuffer_state
47     *rs;
48
49   LFDS710_PAL_ASSERT( qumms != NULL );
50   LFDS710_PAL_ASSERT( qumme != NULL );
51   // TRD : dummy_element can be any value in its range
52
53   rs = (struct lfds710_ringbuffer_state *) LFDS710_QUEUE_UMM_GET_USER_STATE_FROM_STATE( *qumms );
54   re = (struct lfds710_ringbuffer_element *) LFDS710_QUEUE_UMM_GET_VALUE_FROM_ELEMENT( *qumme );
55
56   if( dummy_element_flag == LFDS710_MISC_FLAG_LOWERED )
57     rs->element_cleanup_callback( rs, re->key, re->value, LFDS710_MISC_FLAG_RAISED );
58
59   return;
60 }
61
62 #pragma warning( default : 4100 )
63
64
65
66
67
68 /****************************************************************************/
69 #pragma warning( disable : 4100 )
70
71 static void lfds710_ringbuffer_internal_freelist_element_cleanup_callback( struct lfds710_freelist_state *fs,
72                                                                            struct lfds710_freelist_element *fe )
73 {
74   struct lfds710_ringbuffer_element
75     *re;
76
77   struct lfds710_ringbuffer_state
78     *rs;
79
80   LFDS710_PAL_ASSERT( fs != NULL );
81   LFDS710_PAL_ASSERT( fe != NULL );
82
83   rs = (struct lfds710_ringbuffer_state *) LFDS710_FREELIST_GET_USER_STATE_FROM_STATE( *fs );
84   re = (struct lfds710_ringbuffer_element *) LFDS710_FREELIST_GET_VALUE_FROM_ELEMENT( *fe );
85
86   rs->element_cleanup_callback( rs, re->key, re->value, LFDS710_MISC_FLAG_LOWERED );
87
88   return;
89 }
90
91 #pragma warning( default : 4100 )
92