-
Notifications
You must be signed in to change notification settings - Fork 1
/
BroadcastObject.h
50 lines (39 loc) · 1.26 KB
/
BroadcastObject.h
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
/**
*** Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by
*** The Board of Trustees of the University of Illinois.
*** All rights reserved.
**/
/*
Coordinates broadcast of a data type from a Controller/Seq
to all other Controller/Sequencer type objects (they must
run in a thread!)
*/
#ifndef _BCASTOBJ_H
#define _BCASTOBJ_H
#include "BroadcastMgr.h"
#include "BroadcastClient.h"
#include "LdbCoordinator.h"
#include "common.h"
template <class T> class SimpleBroadcastObject : public BroadcastClient {
public:
const LDObjHandle *ldObjPtr;
SimpleBroadcastObject(int id, const LDObjHandle *h = 0) : BroadcastClient(id), ldObjPtr(h) {
if ( sizeof(T) > BCASTMSGSIZE ) {
NAMD_bug("SimpleBroadcastObject instantiated on class larger than BCASTMSGSIZE");
}
}
~SimpleBroadcastObject() { }
T get(int tag) {
T tmp;
if ( ldObjPtr ) LdbCoordinator::Object()->pauseWork(*ldObjPtr);
while ( BroadcastMgr::Object()->getbuf(*this, tag, (void*)(&tmp)) < 0 ) {
suspendFor(tag);
}
if ( ldObjPtr ) LdbCoordinator::Object()->startWork(*ldObjPtr);
return tmp;
}
void publish(int tag,const T &t ) {
BroadcastMgr::Object()->send(*this, tag, (void*)(&t), sizeof(T));
}
};
#endif