Use a single name prefix for sgen symbols. All non private symbols myst be prefixed...
[mono.git] / mono / metadata / sgen-gray.h
1 /*
2  * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #ifndef __MONO_SGEN_GRAY_H__
24 #define __MONO_SGEN_GRAY_H__
25
26 #define SGEN_GRAY_QUEUE_SECTION_SIZE    (128 - 3)
27
28 /*
29  * This is a stack now instead of a queue, so the most recently added items are removed
30  * first, improving cache locality, and keeping the stack size manageable.
31  */
32 typedef struct _GrayQueueSection GrayQueueSection;
33 struct _GrayQueueSection {
34         int end;
35         GrayQueueSection *next;
36         char *objects [SGEN_GRAY_QUEUE_SECTION_SIZE];
37 };
38
39 typedef struct _SgenGrayQueue SgenGrayQueue;
40
41 typedef void (*GrayQueueAllocPrepareFunc) (SgenGrayQueue*);
42
43 struct _SgenGrayQueue {
44         GrayQueueSection *first;
45         GrayQueueSection *free_list;
46         int balance;
47         GrayQueueAllocPrepareFunc alloc_prepare_func;
48         void *alloc_prepare_data;
49 };
50
51 void sgen_gray_object_enqueue (SgenGrayQueue *queue, char *obj) MONO_INTERNAL;
52 char* sgen_gray_object_dequeue (SgenGrayQueue *queue) MONO_INTERNAL;
53 GrayQueueSection* sgen_gray_object_dequeue_section (SgenGrayQueue *queue) MONO_INTERNAL;
54 void sgen_gray_object_enqueue_section (SgenGrayQueue *queue, GrayQueueSection *section) MONO_INTERNAL;
55 void sgen_gray_object_queue_init (SgenGrayQueue *queue) MONO_INTERNAL;
56 void sgen_gray_object_queue_init_with_alloc_prepare (SgenGrayQueue *queue, GrayQueueAllocPrepareFunc func, void *data) MONO_INTERNAL;
57 void sgen_gray_object_alloc_queue_section (SgenGrayQueue *queue) MONO_INTERNAL;
58 void sgen_gray_object_free_queue_section (GrayQueueSection *section) MONO_INTERNAL;
59 gboolean sgen_drain_gray_stack (SgenGrayQueue *queue, int max_objs) MONO_INTERNAL;
60
61 static inline gboolean
62 sgen_gray_object_queue_is_empty (SgenGrayQueue *queue)
63 {
64         return queue->first == NULL;
65 }
66
67 #endif