16 oneWaitingForQueue =
false;
25 if (!mutex || !mutex->enter(1000))
35 serverHeader->lastUpdateTime = serverHeader->createdTime;
38 + (serverHeader->maxConnectionCount * serverHeader->eachConnectionSize);
49 while (conID <= serverHeader->maxConnectionCount) {
50 if (!conHeader->size || !conHeader->conid || !conHeader->createdTime) {
51 conHeader->size = serverHeader->eachConnectionSize;
52 conHeader->conid = conID;
53 conHeader->createdTime = conHeader->lastUpdateTime =
GetTimeNow();
54 conHeader->status = 1;
62 if (conID > serverHeader->maxConnectionCount) {
83 if (!mutex->enter(1000))
96 std::map<uint64, DataMessage*>::iterator i = replyCache.begin(), e = replyCache.end();
110 if (!mutex || !mutex->enter(1000))
112 uint32 to = msg->
getTo();
119 char* destQueueHeader = getQueueHeader(to);
140 if (!mutex || !mutex->enter(1000))
148DataMessage* MemoryRequestConnection::waitForQueue(uint32 ms) {
156 if (!mutex || !mutex->
enter(1000))
167 if (!mutex || !mutex->enter(1000))
185 if (!mutex || !mutex->enter(1000))
201 if (!mutex || !mutex->enter(1000))
214 if (!mutex || !mutex->enter(1000))
216 uint64 createdTime, lastUpdateTime;
223 uint32 to = msg->
getTo();
224 char* destQueueHeader = getQueueHeader(to);
246char* MemoryRequestConnection::getQueueHeader(uint32 otherConID) {
249 char* otherQueueHeader = ((
char*)serverHeader)
255 return otherQueueHeader;
261 if (!mutex || !mutex->enter(1000))
270 if (msg = replyCache[
id]) {
271 replyCache.erase(
id);
284 if (!oneWaitingForQueue) {
286 oneWaitingForQueue =
true;
287 msg = waitForQueue((uint32)timeLeft);
288 oneWaitingForQueue =
false;
303 replyCache[ref] = msg;
311 if (!cacheEvent.waitNext(timeLeft))
314 if (!mutex || !mutex->enter(1000))
Client-side endpoint of the named shared-memory request/reply service.
#define MEMORYREQUEST_RECEIVED
Dequeued by the server.
#define MEMORYREQUEST_ERROR
Error/invalid.
#define MEMORYREQUEST_INIT
Request being composed.
#define MEMORYREQUEST_SUBMITTED
Placed on the server's queue.
#define MEMORYREQUEST_REPLIED
Reply enqueued to the requester.
#define MEMORYREQUEST_REPLYRECEIVED
Requester consumed the reply.
The central Psyclone data container: a self-contained binary message with typed, named user entries.
uint64 getReference()
getReference() Get and return message reference id
bool setFrom(uint32 from)
setFrom(uint32 from)
bool setReference(uint64 ref)
setReference(uint64 ref) Set message reference
~MemoryRequestConnection()
bool replyToRequest(uint64 id, DataMessage *msg)
Server side: send the reply for id (copied).
bool setRequestStatus(uint64 id, uint16 status)
Server side: advance a request's status.
MemoryRequestConnection()
uint16 getRequestStatus(uint64 id, uint64 &createdTime, uint64 &lastUpdateTime)
Query a request's status.
DataMessage * waitForRequestReply(uint32 ms)
Wait for the reply to this connection's most recent request.
bool connect(const char *memoryName)
Attach to the named server segment and claim a connection slot.
bool shutdown()
Release the connection slot and detach.
uint64 makeRequest(DataMessage *msg)
Submit a request to the server.
DataMessage * waitForRequest(uint32 ms)
Server side: wait for the next incoming request.
static uint64 AddNewRequest(char *data, uint16 status, uint32 from, uint32 to)
Allocate a request slot.
static DataMessage * GetNextQueueMessage(char *data)
Pop the next message.
static bool AddToQueue(char *data, DataMessage *msg)
Append a copy of msg (caller keeps ownership).
static bool CloseRequest(char *data, uint64 id)
Release the request slot.
static bool SetRequestStatus(char *data, uint64 id, uint16 status)
Advance a request's MEMORYREQUEST_* status.
static uint32 GetRequestStatus(char *data, uint64 id, uint64 &createdTime, uint64 &lastUpdateTime)
static bool CheckQueue(char *data, uint32 size)
Validate an existing queue region.
static bool CheckRequestMap(char *data, uint32 count)
Validate an existing status map.
static bool InitQueue(char *data, uint32 size)
Initialise a queue region of size bytes.
Recursive mutual-exclusion lock, optionally named for cross-process use.
bool leave()
Release the mutex.
bool enter()
Block until the mutex is acquired.
uint64 GetTimeNow()
Return the current absolute time (µs since year 0) according to the TMC.
int32 GetTimeAgeMS(uint64 t)
Age of a timestamp relative to now, in milliseconds.
bool SignalSemaphore(const char *name)
Signal a named global semaphore.
bool WaitForSemaphore(const char *name, uint32 ms, bool autocreate=true)
Wait on a named global semaphore.
char * OpenSharedMemorySegment(const char *name, uint64 size)
Open and map an existing named shared memory segment.
bool CloseSharedMemorySegment(char *data, uint64 size)
Unmap a segment previously created/opened here.
std::string StringFormat(const char *format,...)
printf into a std::string.