Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
msgqueue.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file msgqueue.C
1 
2 #include <msgqueue.h>
3 
4 msgqueue::msgqueue ( char * token, const int id,
5  int &status, const int inew )
6 {
7 
8  int ishmflg;
9 
10  tokenid = ftok ( token, id);
11  wasnew = inew;
12  if (inew)
13  {
14  ishmflg = 0666 | IPC_CREAT;
15  }
16  else
17  {
18  ishmflg = 0666;
19  }
20  msgid = msgget(tokenid,ishmflg);
21 
22  if (msgid < 0)
23  {
24  status = msgid;
25  return;
26  }
27 
28  status = 0;
29 }
30 
31 msgqueue::~msgqueue()
32 {
33  if (wasnew)
34  {
35 
36 #if defined(SunOS) || defined(Linux)
37  struct msqid_ds msgb;
38  msgctl (msgid, IPC_RMID,&msgb);
39 
40 #else
41  msgctl (msgid, IPC_RMID);
42 
43 #endif
44 
45  }
46 }
47 
48 int msgqueue::receive( struct msgbuf *structure, int size)
49 {
50  return msgrcv(msgid, structure, size, 0, 0);
51 }
52 
53 int msgqueue::receive_nowait( struct msgbuf* structure, int size)
54 {
55  return msgrcv(msgid, structure, size, 0, IPC_NOWAIT);
56 }
57 
58 int msgqueue::send( struct msgbuf * structure, int size)
59 {
60  return msgsnd(msgid, structure, size, 0);
61 }
62 
63 int msgqueue::wait_for_ping()
64 {
65  int i[2];
66  return msgrcv(msgid, (struct msgbuf *) i, 8, 0, 0);
67 }
68 
69 int msgqueue::send_ping()
70 {
71  int i[2];
72  i[0]= 1;
73  i[1]= 0;
74 
75  return msgsnd(msgid, (struct msgbuf *) i , 8, 0);
76 }
77 
78 
79 
80 
81 
82