Class shared_memory::Exchange_manager_producer¶
-
template<class
Serializable
, intQUEUE_SIZE
>
classshared_memory
::
Exchange_manager_producer
¶ Public Functions
-
Exchange_manager_producer
(std::string segment_id, std::string object_id, bool leading, bool autolock = true)¶ An exchange_manager_producer writes in the shared memory serialized items expected to be consumed by an instance of exchange_manager_consumer (which should use the same segment_id and object_id), possibly running in a separate process.
- Parameters
segment_id
: id of the shared memory segmentobject_id
: id of the shared memory object prefixautolock
: mutex locking mechanism internally managed by the producer. If false, lock has to be “manually” called. This allows for example to set several items in one shotclean_memory_on_exit.
: If true, the destructor will clean the underlined shared memory items.
-
~Exchange_manager_producer
()¶
-
bool
ready_to_produce
()¶ returns true if a consumer is also running.
‘set’ should be called only if ready_to_produce returns true.
-
void
lock
()¶ lock the mutex required for writting in the shared memory without any collision with any consumer.
Should be called before calls to “set”. Not required if the constructor was called with autolock set to true
-
void
unlock
()¶ unlock the mutex for writting in the shared memory without any collision with any consumer.
Not required if the constructor was called with autolock set to true
-
bool
set
(const Serializable &serializable)¶ Set this serializable to be consumed.
Throws shared_memory::Memory_overflow_exception if the shared memory is full. Some of the shared memory should get free once items have been consumed by a consumer. This method should be called only if ‘ready_to_produce’ returns true; Returns true if all data could be written in the shared memory, false if some data required to be buffered (any following call to set, if any, will perform a new attempt to write remaining buffer to the shared memory)
-
void
clear
()¶ removed all elements from the shared queue
-
void
get
(std::deque<int> &get_consumed_ids)¶ write into get_consumed_ids the ids of serialized items that have been successfully consumed by a consumer
-
int
nb_char_written
()¶ returns the number of characters that have been serialized and written to the exchange queue.
For debug purposes.
-
void
reset_char_count
()¶ reset the count of characters written to the exchange queue to zero
-
bool
producer_queue_empty
() const¶
-
bool
consumer_queue_empty
() const¶
Public Static Functions
-
void
clean_mutex
(std::string segment_id)¶ (unlock) and erase the mutex from the shared memory.
To be used if some executable using the exchange manager crashed without calls to destructors.
-
void
clean_memory
(std::string segment_id)¶ wipe out the corresponding shared memory.
To be used if some executable using the exchange manager crashed without calls to destructors.
Private Types
-
typedef Exchange_manager_memory<Serializable, QUEUE_SIZE>
Memory
¶
Private Functions
-
void
reset
()¶
-