ReactOS  0.4.14-dev-583-g2a1ba2c
dictlib.c
Go to the documentation of this file.
1 /*++
2 
3 Copyright (C) Microsoft Corporation, 1990 - 1999
4 
5 Module Name:
6 
7  dictlib.c
8 
9 Abstract:
10 
11  Support library for maintaining a dictionary list (list of objects
12  referenced by a key value).
13 
14 Environment:
15 
16  kernel mode only
17 
18 Notes:
19 
20  This module generates a static library
21 
22 Revision History:
23 
24 --*/
25 
26 #include "classp.h"
27 
28 #define DICTIONARY_SIGNATURE 'dsig'
29 
30 typedef struct _DICTIONARY_HEADER {
33  UCHAR Data[0];
35 
36 
37 VOID
38 NTAPI
40  IN PDICTIONARY Dictionary
41  )
42 {
43  RtlZeroMemory(Dictionary, sizeof(DICTIONARY));
44  Dictionary->Signature = DICTIONARY_SIGNATURE;
45  KeInitializeSpinLock(&Dictionary->SpinLock);
46  return;
47 }
48 
49 BOOLEAN
50 NTAPI
52  IN PDICTIONARY Dictionary
53  )
54 {
55  return Dictionary->Signature == DICTIONARY_SIGNATURE;
56 }
57 
59 NTAPI
61  IN PDICTIONARY Dictionary,
63  IN ULONG Size,
64  IN ULONG Tag,
65  OUT PVOID *Entry
66  )
67 {
69  KIRQL oldIrql;
71 
73 
74  *Entry = NULL;
75 
77  Size + sizeof(DICTIONARY_HEADER),
78  Tag);
79 
80  if(header == NULL) {
82  }
83 
85  header->Key = Key;
86 
87  //
88  // Find the correct location for this entry in the dictionary.
89  //
90 
91  KeAcquireSpinLock(&(Dictionary->SpinLock), &oldIrql);
92 
93  TRY {
94 
95  entry = &(Dictionary->List);
96 
97  while(*entry != NULL) {
98  if((*entry)->Key == Key) {
99 
100  //
101  // Dictionary must have unique keys.
102  //
103 
105  LEAVE;
106 
107  } else if ((*entry)->Key < Key) {
108 
109  //
110  // We will go ahead and insert the key in here.
111  //
112  break;
113  } else {
114  entry = &((*entry)->Next);
115  }
116  }
117 
118  //
119  // If we make it here then we will go ahead and do the insertion.
120  //
121 
122  header->Next = *entry;
123  *entry = header;
124 
125  } FINALLY {
126  KeReleaseSpinLock(&(Dictionary->SpinLock), oldIrql);
127 
128  if(!NT_SUCCESS(status)) {
130  } else {
131  *Entry = (PVOID) header->Data;
132  }
133  }
134  return status;
135 }
136 
137 PVOID
138 NTAPI
140  IN PDICTIONARY Dictionary,
142  )
143 {
145  PVOID data;
146  KIRQL oldIrql;
147 
148 
149  data = NULL;
150 
151  KeAcquireSpinLock(&(Dictionary->SpinLock), &oldIrql);
152 
153  entry = Dictionary->List;
154  while (entry != NULL) {
155 
156  if (entry->Key == Key) {
157  data = entry->Data;
158  break;
159  } else {
160  entry = entry->Next;
161  }
162  }
163 
164  KeReleaseSpinLock(&(Dictionary->SpinLock), oldIrql);
165 
166  return data;
167 }
168 
169 VOID
170 NTAPI
172  IN PDICTIONARY Dictionary,
173  IN PVOID Entry
174  )
175 {
178  KIRQL oldIrql;
179  BOOLEAN found;
180 
181  found = FALSE;
183 
184  KeAcquireSpinLock(&(Dictionary->SpinLock), &oldIrql);
185 
186  entry = &(Dictionary->List);
187  while(*entry != NULL) {
188 
189  if(*entry == header) {
190  *entry = header->Next;
191  found = TRUE;
192  break;
193  } else {
194  entry = &(*entry)->Next;
195  }
196  }
197 
198  KeReleaseSpinLock(&(Dictionary->SpinLock), oldIrql);
199 
200  //
201  // calling this w/an invalid pointer invalidates the dictionary system,
202  // so ASSERT() that we never try to Free something not in the list
203  //
204 
205  ASSERT(found);
206  if (found) {
208  }
209 
210  return;
211 
212 }
VOID NTAPI InitializeDictionary(IN PDICTIONARY Dictionary)
Definition: dictlib.c:39
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define FINALLY
Definition: classpnp.h:113
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG Key
Definition: fatprocs.h:2697
BOOLEAN NTAPI TestDictionarySignature(IN PDICTIONARY Dictionary)
Definition: dictlib.c:51
LONG NTSTATUS
Definition: precomp.h:26
#define LEAVE
Definition: classpnp.h:112
#define TRY(sps, bps)
struct _DICTIONARY_HEADER * Next
Definition: dictlib.c:31
PVOID NTAPI GetDictionaryEntry(IN PDICTIONARY Dictionary, IN ULONGLONG Key)
Definition: dictlib.c:139
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:65
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
NTSTATUS NTAPI AllocateDictionaryEntry(IN PDICTIONARY Dictionary, IN ULONGLONG Key, IN ULONG Size, IN ULONG Tag, OUT PVOID *Entry)
Definition: dictlib.c:60
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
uint32_t entry
Definition: isohybrid.c:63
struct _DICTIONARY_HEADER * PDICTIONARY_HEADER
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONGLONG Key
Definition: dictlib.c:32
struct _DICTIONARY_HEADER DICTIONARY_HEADER
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DICTIONARY_SIGNATURE
Definition: dictlib.c:28
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
struct CFHEADER header
Definition: fdi.c:101
base of all file and directory entries
Definition: entries.h:82
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID NTAPI FreeDictionaryEntry(IN PDICTIONARY Dictionary, IN PVOID Entry)
Definition: dictlib.c:171
Definition: ps.c:97