10 extern inline void LockUIntMapRead(UIntMap
*map
);
11 extern inline void UnlockUIntMapRead(UIntMap
*map
);
12 extern inline void LockUIntMapWrite(UIntMap
*map
);
13 extern inline void UnlockUIntMapWrite(UIntMap
*map
);
16 void InitUIntMap(UIntMap
*map
, ALsizei limit
)
22 RWLockInit(&map
->lock
);
25 void ResetUIntMap(UIntMap
*map
)
27 WriteLock(&map
->lock
);
32 WriteUnlock(&map
->lock
);
35 ALenum
InsertUIntMapEntry(UIntMap
*map
, ALuint key
, ALvoid
*value
)
39 WriteLock(&map
->lock
);
43 ALsizei high
= map
->size
- 1;
46 ALsizei mid
= low
+ (high
-low
)/2;
47 if(map
->array
[mid
].key
< key
)
52 if(map
->array
[low
].key
< key
)
57 if(pos
== map
->size
|| map
->array
[pos
].key
!= key
)
59 if(map
->size
== map
->limit
)
61 WriteUnlock(&map
->lock
);
62 return AL_OUT_OF_MEMORY
;
65 if(map
->size
== map
->maxsize
)
70 newsize
= (map
->maxsize
? (map
->maxsize
<<1) : 4);
71 if(newsize
>= map
->maxsize
)
72 temp
= realloc(map
->array
, newsize
*sizeof(map
->array
[0]));
75 WriteUnlock(&map
->lock
);
76 return AL_OUT_OF_MEMORY
;
79 map
->maxsize
= newsize
;
83 memmove(&map
->array
[pos
+1], &map
->array
[pos
],
84 (map
->size
-pos
)*sizeof(map
->array
[0]));
87 map
->array
[pos
].key
= key
;
88 map
->array
[pos
].value
= value
;
89 WriteUnlock(&map
->lock
);
94 ALvoid
*RemoveUIntMapKey(UIntMap
*map
, ALuint key
)
97 WriteLock(&map
->lock
);
101 ALsizei high
= map
->size
- 1;
104 ALsizei mid
= low
+ (high
-low
)/2;
105 if(map
->array
[mid
].key
< key
)
110 if(map
->array
[low
].key
== key
)
112 ptr
= map
->array
[low
].value
;
113 if(low
< map
->size
-1)
114 memmove(&map
->array
[low
], &map
->array
[low
+1],
115 (map
->size
-1-low
)*sizeof(map
->array
[0]));
119 WriteUnlock(&map
->lock
);
123 ALvoid
*LookupUIntMapKey(UIntMap
*map
, ALuint key
)
126 ReadLock(&map
->lock
);
130 ALsizei high
= map
->size
- 1;
133 ALsizei mid
= low
+ (high
-low
)/2;
134 if(map
->array
[mid
].key
< key
)
139 if(map
->array
[low
].key
== key
)
140 ptr
= map
->array
[low
].value
;
142 ReadUnlock(&map
->lock
);