2 * sgen-gray.h: Gray queue management.
4 * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
5 * Copyright (C) 2012 Xamarin Inc
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;
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.
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.
20 #ifndef __MONO_SGEN_GRAY_H__
21 #define __MONO_SGEN_GRAY_H__
23 #define SGEN_GRAY_QUEUE_SECTION_SIZE (128 - 3)
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.
29 typedef struct _GrayQueueSection GrayQueueSection;
30 struct _GrayQueueSection {
32 GrayQueueSection *next;
33 char *objects [SGEN_GRAY_QUEUE_SECTION_SIZE];
36 typedef struct _SgenGrayQueue SgenGrayQueue;
38 typedef void (*GrayQueueAllocPrepareFunc) (SgenGrayQueue*);
39 typedef void (*GrayQueueEnqueueCheckFunc) (char*);
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;
48 void *alloc_prepare_data;
51 typedef struct _SgenSectionGrayQueue SgenSectionGrayQueue;
53 struct _SgenSectionGrayQueue {
54 GrayQueueSection *first;
57 #ifdef SGEN_CHECK_GRAY_OBJECT_ENQUEUE
58 GrayQueueEnqueueCheckFunc enqueue_check_func;
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_queue_disable_alloc_prepare (SgenGrayQueue *queue) MONO_INTERNAL;
72 void sgen_gray_object_alloc_queue_section (SgenGrayQueue *queue) MONO_INTERNAL;
73 void sgen_gray_object_free_queue_section (GrayQueueSection *section) MONO_INTERNAL;
75 void sgen_section_gray_queue_init (SgenSectionGrayQueue *queue, gboolean locked,
76 GrayQueueEnqueueCheckFunc enqueue_check_func) MONO_INTERNAL;
77 gboolean sgen_section_gray_queue_is_empty (SgenSectionGrayQueue *queue) MONO_INTERNAL;
78 GrayQueueSection* sgen_section_gray_queue_dequeue (SgenSectionGrayQueue *queue) MONO_INTERNAL;
79 void sgen_section_gray_queue_enqueue (SgenSectionGrayQueue *queue, GrayQueueSection *section) MONO_INTERNAL;
81 static inline gboolean
82 sgen_gray_object_queue_is_empty (SgenGrayQueue *queue)
84 return queue->first == NULL;