tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
lehigh.h
Go to the documentation of this file.
1 /**
2  * Copyright (C) 2011
3  * University of Rochester Department of Computer Science
4  * and
5  * Lehigh University Department of Computer Science and Engineering
6  *
7  * License: Modified BSD
8  * Please see the file LICENSE.RSTM for licensing information
9  */
10 
11 #ifndef LEHIGH_H__
12 #define LEHIGH_H__
13 
14 #include "pair.h"
15 
16 /**
17  * STAMP does some odd things with function pointers, which makes g++ unhappy
18  * and makes it very hard to reason about the correctness of code. The most
19  * offensive is that STAMP may coerce a function pointer for a 3-argument
20  * comparison function into a 2-argument comparison function.
21  *
22  * We avoid this situation by saying that rather than store a function pointer
23  * within a collection's root node, we'll store a pointer to a struct, where
24  * the struct has two function pointers: one for transactional code, one for
25  * nontransactional code, with 3 and 2 parameters, respectively. This adds a
26  * level of indirection (though only once per collection traversal, if we are
27  * careful), but increases safety and allows better reasoning.
28  */
29 typedef struct comparator
30 {
31  /*** two functions that return {-1,0,1}, where 0 -> equal ***/
32  /*** the non-transactional version */
33  union {
34  long int (*compare_notm)(const void*, const void*);
35  long int (*compare_pair_notm)(const pair_t*, const pair_t*);
36  };
37 
38  /*** the transactional version */
39  union {
40  TM_CALLABLE long int (*compare_tm)(TM_ARGDECL const void*, const void*);
41  TM_CALLABLE long int (*compare_pair_tm)(TM_ARGDECL const pair_t*, const pair_t*);
42  };
43 
44  /*** the unions necessitate use of constructors :( */
45  comparator (long int (*c1)(const void*, const void*),
46  TM_CALLABLE long int (*c2)(TM_ARGDECL const void*, const void*))
47  {
48  compare_notm = c1;
49  compare_tm = c2;
50  }
51  comparator (long int (*c1)(const pair_t*, const pair_t*),
52  TM_CALLABLE long int (*c2)(TM_ARGDECL const pair_t*, const pair_t*))
53  {
54  compare_pair_notm = c1;
55  compare_pair_tm = c2;
56  }
57 
58 } comparator_t;
59 
60 #endif // LEHIGH_H__
comparator(long int(*c1)(const void *, const void *), TM_CALLABLE long int(*c2)(TM_ARGDECL const void *, const void *))
Definition: lehigh.h:45
#define TM_CALLABLE
Definition: cxxtm.hpp:32
TM_CALLABLE long int(* compare_pair_tm)(TM_ARGDECL const pair_t *, const pair_t *)
Definition: lehigh.h:41
long int(* compare_pair_notm)(const pair_t *, const pair_t *)
Definition: lehigh.h:35
comparator(long int(*c1)(const pair_t *, const pair_t *), TM_CALLABLE long int(*c2)(TM_ARGDECL const pair_t *, const pair_t *))
Definition: lehigh.h:51
#define TM_ARGDECL
Definition: tm.h:532
long int(* compare_notm)(const void *, const void *)
Definition: lehigh.h:34
struct comparator comparator_t
TM_CALLABLE long int(* compare_tm)(TM_ARGDECL const void *, const void *)
Definition: lehigh.h:40
Definition: lehigh.h:29
Definition: pair.h:82