NAMD
OwnerBox.h
Go to the documentation of this file.
1 
7 #ifndef OWNERBOX_H
8 #define OWNERBOX_H
9 
10 #include "charm++.h"
11 
12 template <class Owner, class Data> class Box;
13 
14 template <class Owner, class Data> class OwnerBox {
15 
16  friend class Box<Owner,Data>;
17 
18  int bid, type;
19 
20  public:
21 
22  OwnerBox(Owner *o, void (Owner::*fn)() ) :
23  bid(-1), type(-1),
24  owner(o), callback(fn), data(0),
25  numberUsers(0), openCount(0), closeCount(0) {};
26 
27  OwnerBox(Owner *o, void (Owner::*fn)(), int id ,int tp) :
28  bid(id), type(tp),
29  owner(o), callback(fn), data(0),
30  numberUsers(0), openCount(0), closeCount(0) {};
31 
32 
33  ~OwnerBox(void) {
34  if (numberUsers) {
35  CkPrintf("OwnerBox::~OwnerBox() - still have boxes out there!\n");
36  }
37  }
38 
39  void open(Data* d) {
40  closeCount = openCount = numberUsers;
41  data = d;
42  if ( ! closeCount ) close();
43  }
44 
45  inline void close(void);
46 
47  inline Box<Owner,Data> *checkOut(int id);
48 
49  inline void checkIn(Box<Owner,Data> * box);
50 
51  int isOpen() {
52  return (closeCount != numberUsers || openCount != numberUsers);
53  }
54 
55  // manipulate counters without Box object
56  void clientAdd();
57  void clientRemove();
58  Data* clientOpen(int count=1) {
59  openCount -= count;
60  return data;
61  }
62  void clientClose(int count=1) {
63  if ( ! (closeCount -= count) ) close();
64  }
65 
66  private:
67  Owner *owner;
68  void (Owner::*callback)(void);
69  Data* data;
70  int numberUsers, openCount, closeCount;
71 };
72 
73 template <class Owner, class Data>
75  if (closeCount != numberUsers || openCount != numberUsers) {
76  CkPrintf("OwnerBox::clientAdd() while in use\n");
77  }
78  ++numberUsers; ++closeCount; ++openCount;
79 }
80 
81 template <class Owner, class Data>
83  clientAdd();
84  return (new Box<Owner,Data>(this,id));
85 }
86 
87 template <class Owner, class Data>
89  if (closeCount != numberUsers || openCount != numberUsers) {
90  CkPrintf("OwnerBox::clientRemove() while in use\n");
91  }
92  if ( ! numberUsers-- ) {
93  CkPrintf("OwnerBox::clientRemove() - no registrants remaining\n");
94  numberUsers = 0;
95  } else {
96  closeCount--; openCount--;
97  }
98 }
99 
100 template <class Owner, class Data>
102  delete box;
103  clientRemove();
104 }
105 
106 template <class Owner, class Data>
107 inline void OwnerBox<Owner,Data>::close(void) {
108  if (!closeCount && !openCount) {
109  data = 0; closeCount = openCount = numberUsers;
110  (owner->*callback)();
111  } else {
112  CkPrintf("OwnerBox::close() - close called, but closeCount %d openCount %d\n", closeCount, openCount);
113  }
114 }
115 
116 #endif
Data * clientOpen(int count=1)
Definition: OwnerBox.h:58
static __global__ void(const patch_pair *patch_pairs, const atom *atoms, const atom_param *atom_params, const int *vdw_types, unsigned int *plist, float4 *tmpforces, float4 *slow_tmpforces, float4 *forces, float4 *slow_forces, float *tmpvirials, float *slow_tmpvirials, float *virials, float *slow_virials, unsigned int *global_counters, int *force_ready_queue, const unsigned int *overflow_exclusions, const int npatches, const int block_begin, const int total_block_count, int *block_order, exclmask *exclmasks, const int lj_table_size, const float3 lata, const float3 latb, const float3 latc, const float cutoff2, const float plcutoff2, const int doSlow)
void checkIn(Box< Owner, Data > *box)
Definition: OwnerBox.h:101
void clientRemove()
Definition: OwnerBox.h:88
OwnerBox(Owner *o, void(Owner::*fn)())
Definition: OwnerBox.h:22
void open(Data *d)
Definition: OwnerBox.h:39
~OwnerBox(void)
Definition: OwnerBox.h:33
OwnerBox(Owner *o, void(Owner::*fn)(), int id, int tp)
Definition: OwnerBox.h:27
void close(void)
Definition: OwnerBox.h:107
void clientClose(int count=1)
Definition: OwnerBox.h:62
Box< Owner, Data > * checkOut(int id)
Definition: OwnerBox.h:82
Definition: Box.h:14
void clientAdd()
Definition: OwnerBox.h:74
int isOpen()
Definition: OwnerBox.h:51