Merge pull request #2832 from razzfazz/handle_eintr
[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
14 typedef struct _MonoLockFreeArrayChunk MonoLockFreeArrayChunk;
15
16 typedef struct {
17         size_t entry_size;
18         MonoLockFreeArrayChunk *chunk_list;
19 } MonoLockFreeArray;
20
21 typedef struct {
22         MonoLockFreeArray array;
23         gint32 num_used_entries;
24 } MonoLockFreeArrayQueue;
25
26 #define MONO_LOCK_FREE_ARRAY_INIT(entry_size)           { (entry_size), NULL }
27 #define MONO_LOCK_FREE_ARRAY_QUEUE_INIT(entry_size)     { MONO_LOCK_FREE_ARRAY_INIT ((entry_size) + sizeof (gpointer)), 0 }
28
29 gpointer mono_lock_free_array_nth (MonoLockFreeArray *arr, int index);
30
31 typedef gpointer (*MonoLockFreeArrayIterateFunc) (int index, gpointer entry_ptr, gpointer user_data);
32 gpointer mono_lock_free_array_iterate (MonoLockFreeArray *arr, MonoLockFreeArrayIterateFunc func, gpointer user_data);
33
34 void mono_lock_free_array_cleanup (MonoLockFreeArray *arr);
35
36 void mono_lock_free_array_queue_push (MonoLockFreeArrayQueue *q, gpointer entry_data_ptr);
37 gboolean mono_lock_free_array_queue_pop (MonoLockFreeArrayQueue *q, gpointer entry_data_ptr);
38
39 void mono_lock_free_array_queue_cleanup (MonoLockFreeArrayQueue *q);
40
41 #endif