[merp] Remove dead code (#20043)
[mono-project.git] / mono / metadata / property-bag.c
blob9dc0634ec008703f14058f5bc701641d45e8f628
1 /**
2 * \file
3 * Linearizable property bag.
5 * Authors:
6 * Rodrigo Kumpera (kumpera@gmail.com)
8 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
9 */
10 #include <mono/metadata/property-bag.h>
11 #include <mono/utils/atomic.h>
12 #include <mono/utils/mono-membar.h>
15 * mono_property_bag_get:
17 * Return the value of the property with TAG or NULL.
18 * This doesn't take any locks.
20 void*
21 mono_property_bag_get (MonoPropertyBag *bag, int tag)
23 MonoPropertyBagItem *item;
25 for (item = bag->head; item && item->tag <= tag; item = item->next) {
26 if (item->tag == tag)
27 return item;
29 return NULL;
33 * mono_property_bag_add:
35 * Store VALUE in the property bag. Return the previous value
36 * with the same tag, or NULL. VALUE should point to a structure
37 * extending the MonoPropertyBagItem structure with the 'tag'
38 * field set.
39 * This doesn't take any locks.
41 void*
42 mono_property_bag_add (MonoPropertyBag *bag, void *value)
44 MonoPropertyBagItem *cur, **prev, *item = (MonoPropertyBagItem*)value;
45 int tag = item->tag;
46 mono_memory_barrier (); //publish the values in value
48 retry:
49 prev = &bag->head;
50 while (1) {
51 cur = *prev;
52 if (!cur || cur->tag > tag) {
53 item->next = cur;
54 if (mono_atomic_cas_ptr ((void**)prev, item, cur) == cur)
55 return item;
56 goto retry;
57 } else if (cur->tag == tag) {
58 return cur;
59 } else {
60 prev = &cur->next;
63 return value;