Skip to content

Commit

Permalink
dds-#1174 Remove storage for iox structs
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
  • Loading branch information
MatthiasKillat committed Mar 7, 2022
1 parent 1734d9e commit 15d8a9b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 56 deletions.
2 changes: 0 additions & 2 deletions src/core/ddsc/src/dds__types.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ typedef struct dds_reader {
uint32_t m_loan_size;
unsigned m_wrapped_sertopic : 1; /* set iff reader's topic is a wrapped ddsi_sertopic for backwards compatibility */
#ifdef DDS_HAS_SHM
iox_sub_storage_t m_iox_sub_storage;
iox_sub_context_t m_iox_sub_context;
iox_sub_t m_iox_sub;
#endif
Expand All @@ -357,7 +356,6 @@ typedef struct dds_writer {
struct whc *m_whc; /* FIXME: ownership still with underlying DDSI writer (cos of DDSI built-in writers )*/
bool whc_batch; /* FIXME: channels + latency budget */
#ifdef DDS_HAS_SHM
iox_pub_storage_t m_iox_pub_stor;
iox_pub_t m_iox_pub;
void *m_iox_pub_loans[MAX_PUB_LOANS];
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/core/ddsc/src/dds_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,9 @@ static dds_entity_t dds_create_reader_int (dds_entity_t participant_or_subscribe
// NB: This may fail due to icoeryx being out of internal resources for subsribers.
// In this case terminate is called by iox_sub_init.
// it is currently (iceoryx 2.0 and lower) not possible to change this to
// e.g. return a nullptr and handle the error here.
rd->m_iox_sub = iox_sub_init(&rd->m_iox_sub_storage, gv->config.iceoryx_service, rd->m_topic->m_stype->type_name, rd->m_topic->m_name, &opts);
// e.g. return a nullptr and handle the error here.
iox_sub_storage_t s; // storage is ignored internally now but we cannot pass a nullptr
rd->m_iox_sub = iox_sub_init(&s, gv->config.iceoryx_service, rd->m_topic->m_stype->type_name, rd->m_topic->m_name, &opts);

// NB: Due to some storage paradigm change of iceoryx structs
// we now have a pointer 8 bytes before m_iox_sub
Expand Down
3 changes: 2 additions & 1 deletion src/core/ddsc/src/dds_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ dds_entity_t dds_create_writer (dds_entity_t participant_or_publisher, dds_entit
// In this case terminate is called by iox_pub_init.
// it is currently (iceoryx 2.0 and lower) not possible to change this to
// e.g. return a nullptr and handle the error here.
wr->m_iox_pub = iox_pub_init(&wr->m_iox_pub_stor, gv->config.iceoryx_service, wr->m_topic->m_stype->type_name, wr->m_topic->m_name, &opts);
iox_pub_storage_t s; // storage is ignored internally now but we cannot pass a nullptr
wr->m_iox_pub = iox_pub_init(&s, gv->config.iceoryx_service, wr->m_topic->m_stype->type_name, wr->m_topic->m_name, &opts);
memset(wr->m_iox_pub_loans, 0, sizeof(wr->m_iox_pub_loans));
dds_sleepfor(DDS_MSECS(10));
}
Expand Down
27 changes: 4 additions & 23 deletions src/core/ddsc/src/shm__monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@ extern "C" {
#define SHM_MAX_NUMBER_OF_READERS 127

struct dds_reader;
struct shm_monitor ;

typedef struct {
iox_user_trigger_storage_t storage;
struct shm_monitor* monitor;

//we cannot use those in concurrent wakeups (i.e. only one user callback can be invoked per trigger)
void (*call) (void*);
void* arg;
} iox_user_trigger_storage_extension_t;
struct shm_monitor;

enum shm_monitor_states {
SHM_MONITOR_NOT_RUNNING = 0,
Expand All @@ -48,16 +39,12 @@ enum shm_monitor_states {
/// @brief abstraction for monitoring the shared memory communication with an internal
/// thread responsible for reacting on received data via shared memory
struct shm_monitor {
ddsrt_mutex_t m_lock; //currently not needed but we keep it until finalized

iox_listener_storage_t m_listener_storage;
ddsrt_mutex_t m_lock;
iox_listener_t m_listener;

//use this if we wait but want to wake up for some reason e.g. terminate
iox_user_trigger_storage_extension_t m_wakeup_trigger_storage;
//use this if we wait but want to wake up for some reason e.g. terminate
iox_user_trigger_t m_wakeup_trigger;

//TODO: atomics

uint32_t m_number_of_attached_readers;
uint32_t m_state;
};
Expand All @@ -72,12 +59,6 @@ void shm_monitor_init(shm_monitor_t* monitor);
/// @param monitor self
void shm_monitor_destroy(shm_monitor_t* monitor);

/// @brief wake up the internal listener and invoke a function in the listener thread
/// @param monitor self
/// @param function function to invoke
/// @param arg generic argument for the function (lifetime must be ensured by the user)
dds_return_t shm_monitor_wake_and_invoke(shm_monitor_t* monitor, void (*function) (void*), void* arg);

/// @brief wake up the internal listener and disable execution of listener callbacks
/// due to received data
/// @param monitor self
Expand Down
34 changes: 6 additions & 28 deletions src/core/ddsc/src/shm_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,17 @@
extern "C" {
#endif

static void shm_wakeup_trigger_callback(iox_user_trigger_t trigger, void * context_data);
static void shm_subscriber_callback(iox_sub_t subscriber, void * context_data);

void shm_monitor_init(shm_monitor_t* monitor)
{
ddsrt_mutex_init(&monitor->m_lock);

monitor->m_listener = iox_listener_init(&monitor->m_listener_storage);
monitor->m_wakeup_trigger = iox_user_trigger_init(&monitor->m_wakeup_trigger_storage.storage);
monitor->m_wakeup_trigger_storage.monitor = monitor;
iox_listener_attach_user_trigger_event_with_context_data(monitor->m_listener,
monitor->m_wakeup_trigger,
shm_wakeup_trigger_callback,
&monitor->m_wakeup_trigger_storage);

// storage is ignored internally now but we cannot pass a nullptr
iox_listener_storage_t s;
monitor->m_listener = iox_listener_init(&s);
iox_user_trigger_storage_t t;
monitor->m_wakeup_trigger = iox_user_trigger_init(&t);

monitor->m_state = SHM_MONITOR_RUNNING;
}
Expand All @@ -59,15 +56,6 @@ void shm_monitor_destroy(shm_monitor_t* monitor)
ddsrt_mutex_destroy(&monitor->m_lock);
}

dds_return_t shm_monitor_wake_and_invoke(shm_monitor_t* monitor, void (*function) (void*), void* arg)
{
iox_user_trigger_storage_extension_t* storage = (iox_user_trigger_storage_extension_t*) monitor->m_wakeup_trigger;
storage->call = function;
storage->arg = arg;
iox_user_trigger_trigger(monitor->m_wakeup_trigger);
return DDS_RETCODE_OK;
}

dds_return_t shm_monitor_wake_and_disable(shm_monitor_t* monitor)
{
monitor->m_state = SHM_MONITOR_NOT_RUNNING;
Expand Down Expand Up @@ -190,16 +178,6 @@ static void receive_data_wakeup_handler(struct dds_reader* rd)
thread_state_asleep(lookup_thread_state());
}

static void shm_wakeup_trigger_callback(iox_user_trigger_t trigger, void * context_data)
{
(void)trigger;
// we know it is actually in extended storage since we created it like this
iox_user_trigger_storage_extension_t* storage = (iox_user_trigger_storage_extension_t*) context_data;
if(storage->monitor->m_state == SHM_MONITOR_RUNNING && storage->call) {
storage->call(storage->arg);
}
}

static void shm_subscriber_callback(iox_sub_t subscriber, void * context_data)
{
(void)subscriber;
Expand Down

0 comments on commit 15d8a9b

Please sign in to comment.