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