[sgen] Fix weak tracking links in concurrent mark.
[mono.git] / mono / metadata / sgen-gray.h
1 /*
2  * sgen-gray.h: Gray queue management.
3  *
4  * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
5  * Copyright (C) 2012 Xamarin Inc
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License 2.0 as published by the Free Software Foundation;
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License 2.0 along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 #ifndef __MONO_SGEN_GRAY_H__
21 #define __MONO_SGEN_GRAY_H__
22
23 #define SGEN_GRAY_QUEUE_SECTION_SIZE    (128 - 3)
24
25 /*
26  * This is a stack now instead of a queue, so the most recently added items are removed
27  * first, improving cache locality, and keeping the stack size manageable.
28  */
29 typedef struct _GrayQueueSection GrayQueueSection;
30 struct _GrayQueueSection {
31         int end;
32         GrayQueueSection *next;
33         char *objects [SGEN_GRAY_QUEUE_SECTION_SIZE];
34 };
35
36 typedef struct _SgenGrayQueue SgenGrayQueue;
37
38 typedef void (*GrayQueueAllocPrepareFunc) (SgenGrayQueue*);
39 typedef void (*GrayQueueEnqueueCheckFunc) (char*);
40
41 struct _SgenGrayQueue {
42         GrayQueueSection *first;
43         GrayQueueSection *free_list;
44         GrayQueueAllocPrepareFunc alloc_prepare_func;
45 #ifdef SGEN_CHECK_GRAY_OBJECT_ENQUEUE
46         GrayQueueEnqueueCheckFunc enqueue_check_func;
47 #endif
48         void *alloc_prepare_data;
49 };
50
51 typedef struct _SgenSectionGrayQueue SgenSectionGrayQueue;
52
53 struct _SgenSectionGrayQueue {
54         GrayQueueSection *first;
55         gboolean locked;
56         mono_mutex_t lock;
57 #ifdef SGEN_CHECK_GRAY_OBJECT_ENQUEUE
58         GrayQueueEnqueueCheckFunc enqueue_check_func;
59 #endif
60 };
61
62 void sgen_gray_object_enqueue (SgenGrayQueue *queue, char *obj) MONO_INTERNAL;
63 char* sgen_gray_object_dequeue (SgenGrayQueue *queue) MONO_INTERNAL;
64 GrayQueueSection* sgen_gray_object_dequeue_section (SgenGrayQueue *queue) MONO_INTERNAL;
65 void sgen_gray_object_enqueue_section (SgenGrayQueue *queue, GrayQueueSection *section) MONO_INTERNAL;
66 void sgen_gray_object_queue_init (SgenGrayQueue *queue, GrayQueueEnqueueCheckFunc enqueue_check_func) MONO_INTERNAL;
67 void sgen_gray_object_queue_init_invalid (SgenGrayQueue *queue) MONO_INTERNAL;
68 void sgen_gray_object_queue_init_with_alloc_prepare (SgenGrayQueue *queue, GrayQueueEnqueueCheckFunc enqueue_check_func,
69                 GrayQueueAllocPrepareFunc func, void *data) MONO_INTERNAL;
70 void sgen_gray_object_queue_deinit (SgenGrayQueue *queue) MONO_INTERNAL;
71 void sgen_gray_object_alloc_queue_section (SgenGrayQueue *queue) MONO_INTERNAL;
72 void sgen_gray_object_free_queue_section (GrayQueueSection *section) MONO_INTERNAL;
73
74 void sgen_section_gray_queue_init (SgenSectionGrayQueue *queue, gboolean locked,
75                 GrayQueueEnqueueCheckFunc enqueue_check_func) MONO_INTERNAL;
76 gboolean sgen_section_gray_queue_is_empty (SgenSectionGrayQueue *queue) MONO_INTERNAL;
77 GrayQueueSection* sgen_section_gray_queue_dequeue (SgenSectionGrayQueue *queue) MONO_INTERNAL;
78 void sgen_section_gray_queue_enqueue (SgenSectionGrayQueue *queue, GrayQueueSection *section) MONO_INTERNAL;
79
80 static inline gboolean
81 sgen_gray_object_queue_is_empty (SgenGrayQueue *queue)
82 {
83         return queue->first == NULL;
84 }
85
86 #endif