JANA2
JMailbox< T > Class Template Reference
Inheritance diagram for JMailbox< T >:
Collaboration diagram for JMailbox< T >:

Public Types

enum  Status {
  Ready,
  Congested,
  Empty,
  Full,
  Finished
}
 
- Public Types inherited from JActivable
enum  Status {
  Unopened,
  Inactive,
  Running,
  Draining,
  Drained,
  Finished,
  Closed
}
 

Public Member Functions

 JMailbox (size_t threshold=100, size_t locations_count=1, bool enable_work_stealing=false)
 threshold: the (soft) maximum number of items in the queue at any time domain_count: the number of domains enable_work_stealing: allow domains to pop from other domains' queues when theirs is empty
 
size_t size ()
 size() counts the number of items in the queue across all domains This should be used sparingly because it will mess up a bunch of caches. More...
 
size_t size (size_t domain)
 size(domain) counts the number of items in the queue for a particular domain Meant to be used by Scheduler::next_assignment() and measure_perf(), eventually
 
size_t reserve (size_t requested_count, size_t domain=0)
 reserve(requested_count) keeps our queues bounded in size. More...
 
Status push (std::vector< T > &buffer, size_t reserved_count=0, size_t domain=0)
 push(items, reserved_count, domain) This function will always succeed, although it may exceed the threshold if the caller didn't reserve space, and it may take a long time because it will wait on a mutex. More...
 
Status push (T &item, size_t reserved_count=0, size_t domain=0)
 
Status pop (std::vector< T > &buffer, size_t requested_count, size_t location_id=0)
 pop() will pop up to requested_count items for the desired domain. More...
 
Status pop (T &item, bool &success, size_t location_id=0)
 
size_t get_threshold ()
 
void set_threshold (size_t threshold)
 
- Public Member Functions inherited from JActivable
virtual bool is_active ()
 
virtual void set_active (bool is_active)
 
void update_activeness (bool is_active)
 
void notify_downstream (bool is_active)
 
void attach_upstream (JActivable *activable)
 
void attach_downstream (JActivable *activable)
 

Friends

std::ostream & operator<< (std::ostream &os, const Status &s)
 

Additional Inherited Members

- Protected Attributes inherited from JActivable
std::atomic< Status > _status {Status::Unopened}
 

Member Function Documentation

template<typename T>
Status JMailbox< T >::pop ( std::vector< T > &  buffer,
size_t  requested_count,
size_t  location_id = 0 
)
inline

pop() will pop up to requested_count items for the desired domain.

If many threads are contending for the queue, this will fail with Status::Contention, in which case the caller should probably consult the Scheduler.

Referenced by JMailbox< Event >::pop().

Here is the caller graph for this function:

template<typename T>
Status JMailbox< T >::push ( std::vector< T > &  buffer,
size_t  reserved_count = 0,
size_t  domain = 0 
)
inline

push(items, reserved_count, domain) This function will always succeed, although it may exceed the threshold if the caller didn't reserve space, and it may take a long time because it will wait on a mutex.

Note that if the caller had called reserve(), they must pass in the reserved_count here.

Referenced by JMailbox< Event >::push().

Here is the caller graph for this function:

template<typename T>
size_t JMailbox< T >::reserve ( size_t  requested_count,
size_t  domain = 0 
)
inline

reserve(requested_count) keeps our queues bounded in size.

The caller should reserve their desired chunk size on the output queue first. The output queue will return a reservation which is less than or equal to requested_count. The caller may then request as many items from the input queue as have been reserved on the output queue. Note that because the input queue may return fewer items than requested, the caller must push their original reserved_count alongside the items, to avoid a "reservation leak".

template<typename T>
size_t JMailbox< T >::size ( )
inline

size() counts the number of items in the queue across all domains This should be used sparingly because it will mess up a bunch of caches.

Meant to be used by measure_perf()

Referenced by JMailbox< Event >::pop(), and JMailbox< Event >::push().

Here is the caller graph for this function:


The documentation for this class was generated from the following file: