public
Description: Message passing, Work-Stealing, Lock-Free, Dynamic Scheduling, and other buzzwords for GLib
Homepage:
Clone URL: git://github.com/chergert/iris.git
chergert (author)
Wed Sep 23 22:59:57 -0700 2009
commit  36b7a5499c0923e5e697c7ea3033dbcd735b6d05
tree    cde11dffda17b70c839ef63db6d74e84638258ab
parent  75fcca0e799e0e1ee825f311bfb57b53839c4031
iris / iris / gstamppointer.h
100644 55 lines (46 sloc) 2.202 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* gstamppointer.h
*
* Copyright (C) 2009 Christian Hergert <chris@dronelabs.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
* 02110-1301 USA
*/
 
#ifndef __G_STAMP_POINTER_H__
#define __G_STAMP_POINTER_H__
 
#include <glib.h>
 
/* #gstamppointer is a pointer that uses the lower 2 bits of the pointer
* for a stamp. The stamp is a simple counter that can be incremented
* repeatedly, and will roll over.
*
* This is used to help mitigate the ABA problem that is common in
* lock-free data structures. However, if the ABA problem occurs 4 times
* repeatedly during the 1st threads pre-emption, the problem still exists.
*
* This requires that the destination of the pointer is aligned to at least
* a 32bit integer such as sizeof(void*). Our pointers used for link->next
* are more IrisLink nodes, which are allocated by the slice allocator.
* The GSlice allocator provides alignment to sizeof(void*).
*/
 
G_BEGIN_DECLS
 
typedef gpointer gstamppointer;
 
#define G_STAMP_POINTER(p) ((gstamppointer)p)
#define G_STAMP_POINTER_GET_POINTER(p) ((gstamppointer)(((gulong)p) & ((gulong)~0x03)))
#define G_STAMP_POINTER_GET_STAMP(p) ((gulong) (((gulong)p) & ((gulong) 0x03)))
#define G_STAMP_POINTER_INCREMENT(p) ((gstamppointer) \
(((gulong)((G_STAMP_POINTER_GET_STAMP(p) + 1) & 0x03)) \
|((gulong)(G_STAMP_POINTER_GET_POINTER(p)))))
#define G_STAMP_POINTER_GET_LINK(p) ((IrisLink*)G_STAMP_POINTER_GET_POINTER(p))
 
G_END_DECLS
 
#endif /* __G_STAMP_POINTER_H__ */