tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
common.hpp
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 /* common.hpp
12  *
13  * Global definitions.
14  */
15 
16 #ifndef MESH_CONFIG_HPP__
17 #define MESH_CONFIG_HPP__
18 
19 #include <iostream>
20  using std::cerr;
21 #include <cassert>
22 
23 #include "common/platform.hpp"
24 #include "common/ThreadLocal.hpp"
25 #include "lock.hpp" // pthread locks
26 
27 #ifdef __APPLE__
28 inline void* memalign(size_t alignment, size_t size)
29 {
30  return malloc(size);
31 }
32 #elif defined(sparc) && defined(sun)
33 # include <stdlib.h>
34 #else
35 # include <malloc.h> // some systems need this for memalign()
36 #endif
37 
38 extern int num_points; // number of points
39 extern int num_workers; // threads
40 extern bool output_incremental; // dump edges as we go along
41 extern bool output_end; // dump edges at end
42 extern bool verbose; // print stats
43  // verbose <- (output_incremental || output_end)
44 
45 static const int MAX_WORKERS = 32;
46 
47 extern d_lock io_lock;
48 extern unsigned long long start_time;
49 extern unsigned long long last_time;
50 
51 
52 /// We piggyback on the libstm configuration in order to chose a thread-local
53 /// storage mechanism.
54 class thread;
55 extern THREAD_LOCAL_DECL_TYPE(thread*) currentThread;
56 
57 #ifdef CGL
58 # define BEGIN_TRANSACTION(TYPE) {with_lock tx_cs(io_lock);
59 # define END_TRANSACTION }
60 #endif
61 
62 #ifdef ITM
63 # include <new>
64  [[transaction_safe]]
65  void* operator new (std::size_t size) throw (std::bad_alloc);
66  [[transaction_safe]] void operator delete(void* ptr) throw();
67 # define BEGIN_TRANSACTION(TYPE) \
68  currentThread->enter_transaction(); \
69  currentThread->erase_buffered_output(); \
70  __transaction [[TYPE]] {
71 # define END_TRANSACTION } \
72  currentThread->dump_buffered_output(); \
73  currentThread->leave_transaction();
74 # define TRANSACTION_SAFE [[transaction_safe]]
75 # define TRANSACTION_PURE [[transaction_pure]]
76 # define TRANSACTION_WAIVER __transaction [[waiver]]
77 
78 #include "itm.h"
79 
80 # define SYS_INIT _ITM_initializeProcess
81 # define THREAD_INIT _ITM_initializeThread
82 # define THREAD_SHUTDOWN _ITM_finalizeThread
83 # define SYS_SHUTDOWN _ITM_finalizeProcess
84 
85 #else
86 
87 # define TRANSACTION_SAFE
88 # define TRANSACTION_PURE
89 # define TRANSACTION_WAIVER
90 
91 # define SYS_INIT()
92 # define THREAD_INIT()
93 # define THREAD_SHUTDOWN()
94 # define SYS_SHUTDOWN()
95 
96 #endif
97 
98 #endif // MESH_CONFIG_HPP__
void *volatile ptr
Definition: counted_ptr.hpp:57
unsigned long long start_time
Definition: mesh.cpp:34
bool verbose
Definition: mesh.cpp:44
bool output_incremental
Definition: mesh.cpp:42
int num_points
Definition: mesh.cpp:38
Definition: my_thread.hpp:41
static const int MAX_WORKERS
Definition: common.hpp:45
Definition: lock.hpp:24
d_lock io_lock
Definition: mesh.cpp:33
THREAD_LOCAL_DECL_TYPE(thread *) currentThread
bool output_end
Definition: mesh.cpp:43
int num_workers
Definition: mesh.cpp:39
unsigned long long last_time
Definition: mesh.cpp:35