Improve a safety check when writing data into StatBuffer
[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  */
7 #ifndef __MONO_LOCK_FREE_ARRAY_QUEUE_H__
8 #define __MONO_LOCK_FREE_ARRAY_QUEUE_H__
9
10 #include <glib.h>
11 #include <mono/utils/mono-compiler.h>
12
13 typedef struct _MonoLockFreeArrayChunk MonoLockFreeArrayChunk;
14
15 typedef struct {
16         size_t entry_size;
17         MonoLockFreeArrayChunk *chunk_list;
18 } MonoLockFreeArray;
19
20 typedef struct {
21         MonoLockFreeArray array;
22         gint32 num_used_entries;
23 } MonoLockFreeArrayQueue;
24
25 #define MONO_LOCK_FREE_ARRAY_INIT(entry_size)           { (entry_size), NULL }
26 #define MONO_LOCK_FREE_ARRAY_QUEUE_INIT(entry_size)     { MONO_LOCK_FREE_ARRAY_INIT ((entry_size) + sizeof (gpointer)), 0 }
27
28 gpointer mono_lock_free_array_nth (MonoLockFreeArray *arr, int index);
29
30 typedef gpointer (*MonoLockFreeArrayIterateFunc) (int index, gpointer entry_ptr, gpointer user_data);
31 gpointer mono_lock_free_array_iterate (MonoLockFreeArray *arr, MonoLockFreeArrayIterateFunc func, gpointer user_data);
32
33 void mono_lock_free_array_cleanup (MonoLockFreeArray *arr);
34
35 void mono_lock_free_array_queue_push (MonoLockFreeArrayQueue *q, gpointer entry_data_ptr);
36 gboolean mono_lock_free_array_queue_pop (MonoLockFreeArrayQueue *q, gpointer entry_data_ptr);
37
38 void mono_lock_free_array_queue_cleanup (MonoLockFreeArrayQueue *q);
39
40 #endif