Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / utils / lock-free-array-queue.h
1 /**
2  * \file
3  * A lock-free somewhat-queue that doesn't
4  * require hazard pointers.
5  *
6  * (C) Copyright 2011 Xamarin Inc.
7  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
8  */
9 #ifndef __MONO_LOCK_FREE_ARRAY_QUEUE_H__
10 #define __MONO_LOCK_FREE_ARRAY_QUEUE_H__
11
12 #include <glib.h>
13 #include <mono/utils/mono-compiler.h>
14 #include <mono/utils/mono-mmap.h>
15
16 typedef struct _MonoLockFreeArrayChunk MonoLockFreeArrayChunk;
17
18 typedef struct {
19         size_t entry_size;
20         MonoLockFreeArrayChunk *chunk_list;
21         MonoMemAccountType account_type;
22 } MonoLockFreeArray;
23
24 typedef struct {
25         MonoLockFreeArray array;
26         gint32 num_used_entries;
27 } MonoLockFreeArrayQueue;
28
29 #define MONO_LOCK_FREE_ARRAY_INIT(entry_size, account_type)             { (entry_size), NULL, (account_type) }
30 #define MONO_LOCK_FREE_ARRAY_QUEUE_INIT(entry_size, account_type)       { MONO_LOCK_FREE_ARRAY_INIT ((entry_size) + sizeof (gpointer), (account_type)), 0 }
31
32 gpointer mono_lock_free_array_nth (MonoLockFreeArray *arr, int index);
33
34 typedef gpointer (*MonoLockFreeArrayIterateFunc) (int index, gpointer entry_ptr, gpointer user_data);
35 gpointer mono_lock_free_array_iterate (MonoLockFreeArray *arr, MonoLockFreeArrayIterateFunc func, gpointer user_data);
36
37 void mono_lock_free_array_cleanup (MonoLockFreeArray *arr);
38
39 void mono_lock_free_array_queue_push (MonoLockFreeArrayQueue *q, gpointer entry_data_ptr);
40 gboolean mono_lock_free_array_queue_pop (MonoLockFreeArrayQueue *q, gpointer entry_data_ptr);
41
42 void mono_lock_free_array_queue_cleanup (MonoLockFreeArrayQueue *q);
43
44 #endif