Commit b4c12079 authored by Georg Martin Reinke's avatar Georg Martin Reinke
Browse files

ShmemInterface: optionally don't block when reading

parent 4478c769
......@@ -31,10 +31,12 @@ ShmemInterface::ShmemInterface(const char* wname, const char* rname) {
conf.queuelen = 512;
conf.samplelen = 64;
conf.polling = 0;
mBlocking = true;
init(wname, rname, &conf);
}
ShmemInterface::ShmemInterface(const char* wname, const char *rname, struct shmem_conf* conf) {
ShmemInterface::ShmemInterface(const char* wname, const char *rname, struct shmem_conf* conf, bool blocking) {
mBlocking = blocking;
init(wname, rname, conf);
}
......@@ -50,8 +52,14 @@ void ShmemInterface::readValues() {
struct sample *sample = nullptr;
int ret = 0;
try {
while (ret == 0)
if (mBlocking) {
ret = shmem_int_read(&mShmem, &sample, 1);
if (ret == 0)
return;
} else {
while (ret == 0)
ret = shmem_int_read(&mShmem, &sample, 1);
}
if (ret < 0) {
std::cerr << "Fatal error: failed to read sample from shmem interface" << std::endl;
std::exit(1);
......
......@@ -20,6 +20,7 @@ namespace DPsim {
struct shmem_int mShmem;
struct sample *mLastSample;
int mSeq;
bool mBlocking;
void init(const char *wname, const char *rname, struct shmem_conf *conf);
......@@ -33,8 +34,9 @@ namespace DPsim {
/** Create a ShmemInterface with a specific configuration for the output queue.
*
* @param conf The configuration object for the output queue (see VILLASnode's documentation).
* @param blocking If true, reading from this interface will block until a value is received. If false, reading will return immediately and not change any values if no value is currently enqueued.
*/
ShmemInterface(const char* wname, const char* rname, struct shmem_conf* conf);
ShmemInterface(const char* wname, const char* rname, struct shmem_conf* conf, bool blocking = true);
~ShmemInterface();
/** Read a single struct sample from the shared input queue and pass the contained
* values to all registered current/voltage sources.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment