SST/macro
context_util.h
Go to the documentation of this file.
1 /*
2  * This file is part of SST/macroscale:
3  * The macroscale architecture simulator from the SST suite.
4  * Copyright (c) 2009 Sandia Corporation.
5  * This software is distributed under the BSD License.
6  * Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7  * the U.S. Government retains certain rights in this software.
8  * For more information, see the LICENSE file in the top
9  * SST/macroscale directory.
10  */
11 
12 #ifndef SSTMAC_SOFTWARE_THREADING_CONTEXT_UTIL_H_INCLUDED
13 #define SSTMAC_SOFTWARE_THREADING_CONTEXT_UTIL_H_INCLUDED
14 
16 #include <sprockit/errors.h>
17 #include <assert.h>
18 
19 namespace sstmac {
20 namespace sw {
21 
22 /**
23  * A set of utilities to deal with the odd arguments to makecontext.
24  */
25 
26 // We assume that we can always fit a pointer (void* or void (*ptr)(void*))
27 // into two integers. This should ideally be tested by autoconf.
28 struct intpair {
29  int a;
30  int b;
31 };
32 
33 /// Pack a void* argument into a pair of integers.
34 union voidptr {
36  void *vpointer;
37  voidptr() {
38  vpair.a = 0;
39  vpair.b = 0;
40  vpointer = 0;
41  }
42  voidptr(void *ptr) {
43  assert(sizeof(void*) <= (2*sizeof(int)));
44  vpair.a = 0;
45  vpair.b = 0;
46  vpointer = ptr;
47  }
48  voidptr(int a, int b) {
49  vpointer = 0;
50  vpair.a = a;
51  vpair.b = b;
52  }
53 };
54 
55 /// Pack a function pointer of the form void(*)(void*) as a pair of integers.
56 union funcptr {
58  void (*fpointer)(void*);
59  funcptr() {
60  fpair.a = 0;
61  fpair.b = 0;
62  fpointer = 0;
63  }
64  funcptr(void (*ptr)(void*)) {
65  assert(sizeof(void(*)(void*)) <= (2*sizeof(int)));
66  fpair.a = 0;
67  fpair.b = 0;
68  fpointer = ptr;
69  }
70  funcptr(int a, int b) {
71  fpointer = 0;
72  fpair.a = a;
73  fpair.b = b;
74  }
75  void call(const voidptr &arg) {
76  if(fpointer == 0) {
78  "union functpr::call(const voidptr&): NULL function pointer");
79  }
80  (*fpointer)(arg.vpointer);
81  }
82 };
83 
84 /// Springboard routine to wrap a makecontext call.
85 /// We have to be able to take a pointer to this function
86 /// (so no inline).
87 void context_springboard(int func_ptr_a, int func_ptr_b,
88  int arg_ptr_a, int arg_ptr_b);
89 
90 }
91 } // end of namespace sstmac
92 
93 #endif
94 
Pack a void* argument into a pair of integers.
Definition: context_util.h:34
voidptr(void *ptr)
Definition: context_util.h:42
funcptr(int a, int b)
Definition: context_util.h:70
funcptr(void(*ptr)(void *))
Definition: context_util.h:64
void context_springboard(int func_ptr_a, int func_ptr_b, int arg_ptr_a, int arg_ptr_b)
Springboard routine to wrap a makecontext call.
Error indicating something was null and shouldn&#39;t have been.
Definition: errors.h:71
voidptr(int a, int b)
Definition: context_util.h:48
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
void call(const voidptr &arg)
Definition: context_util.h:75
Pack a function pointer of the form void(*)(void*) as a pair of integers.
Definition: context_util.h:56
#define spkt_throw(exc,...)
Definition: errors.h:44
A set of utilities to deal with the odd arguments to makecontext.
Definition: context_util.h:28