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*);
40 struct _SgenGrayQueue {
41 GrayQueueSection *first;
42 GrayQueueSection *free_list;
44 GrayQueueAllocPrepareFunc alloc_prepare_func;
45 void *alloc_prepare_data;
48 void sgen_gray_object_enqueue (SgenGrayQueue *queue, char *obj) MONO_INTERNAL;
49 char* sgen_gray_object_dequeue (SgenGrayQueue *queue) MONO_INTERNAL;
50 GrayQueueSection* sgen_gray_object_dequeue_section (SgenGrayQueue *queue) MONO_INTERNAL;
51 void sgen_gray_object_enqueue_section (SgenGrayQueue *queue, GrayQueueSection *section) MONO_INTERNAL;
52 void sgen_gray_object_queue_init (SgenGrayQueue *queue) MONO_INTERNAL;
53 void sgen_gray_object_queue_init_invalid (SgenGrayQueue *queue) MONO_INTERNAL;
54 void sgen_gray_object_queue_init_with_alloc_prepare (SgenGrayQueue *queue, GrayQueueAllocPrepareFunc func, void *data) MONO_INTERNAL;
55 void sgen_gray_object_alloc_queue_section (SgenGrayQueue *queue) MONO_INTERNAL;
56 void sgen_gray_object_free_queue_section (GrayQueueSection *section) MONO_INTERNAL;
57 gboolean sgen_drain_gray_stack (SgenGrayQueue *queue, int max_objs) MONO_INTERNAL;
59 static inline gboolean
60 sgen_gray_object_queue_is_empty (SgenGrayQueue *queue)
62 return queue->first == NULL;