H3D API  2.4.1
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
H3D::ThreadSafeMField< BaseField > Class Template Reference

<> More...

#include <H3D/ThreadSafeFields.h>

Inheritance diagram for H3D::ThreadSafeMField< BaseField >:
Inheritance graph

Public Member Functions

 ThreadSafeMField ()
 Constructor.
 
virtual void setValue (const vector< typename BaseField::value_type > &v, int id=0)
 Set the value of the field. More...
 
virtual void setValue (typename BaseField::size_type i, const typename BaseField::value_type &t, int id=0)
 Change the value of one element in the MField. More...
 
virtual void swap (typename BaseField::vector_type &x, int id=0)
 Swaps the contents of two vectors.
 
virtual void push_back (const typename BaseField::value_type &x, int id=0)
 Inserts a new element at the end.
 
void pop_back (int id=0)
 Removed the last element.
 
virtual void clear (int id=0)
 Erases all of the elements.
 
virtual BaseField::const_iterator begin (int id=0)
 Returns a const_iterator pointing to the beginning of the vector.
 
virtual BaseField::const_iterator end (int id=0)
 Returns a const_iterator pointing to the end of the vector.
 
virtual BaseField::const_reverse_iterator rbegin (int id=0)
 Returns a const_reverse_iterator pointing to the beginning of the reversed vector. More...
 
virtual BaseField::const_reverse_iterator rend (int id=0)
 Returns a const_reverse_iterator pointing to the end of the reversed vector. More...
 
virtual unsigned int size ()
 Returns the size of the vector.
 
virtual BaseField::size_type max_size ()
 Returns the largest possible size of the vector.
 
virtual BaseField::size_type capacity ()
 Number of elements for which memory has been allocated. More...
 
virtual bool empty ()
 true if the vector's size is 0.
 
virtual BaseField::const_reference operator[] (typename BaseField::size_type n)
 Returns the n'th element.
 
virtual BaseField::const_reference front (int id=0)
 Returns the first element.
 
virtual BaseField::const_reference back (int id=0)
 Returns the last element.
 
virtual const BaseField::vector_type & getValue (int id=0)
 Gets the value of the field.
 
virtual void upToDate ()
 Make sure that the field is up-to-date. More...
 
- Public Member Functions inherited from H3D::PeriodicUpdate< BaseField >
 PeriodicUpdate (H3DFloat _period=0, PeriodType _period_type=COUNT)
 Constructor.
 
 ~PeriodicUpdate ()
 Destructor.
 
virtual bool timeToUpdate ()
 Determines if it is time to check that the field is updated. More...
 
void setPeriodType (PeriodType type)
 Set the type of the period.
 
void setPeriod (H3DFloat _period)
 Set the period for the update.
 
- Public Member Functions inherited from H3D::PeriodicUpdateField
virtual ~PeriodicUpdateField ()
 Destructor.
 

Protected Member Functions

virtual void update ()
 The update function is specialized to synchronize with the haptics threads and copy the new value of the field to the rt_value member in a thread safe way.
 

Static Protected Member Functions

static H3DUtil::PeriodicThread::CallbackCode transferValue (void *_data)
 Callback function to transfer copy a value between two pointers of the same type.
 

Protected Attributes

BaseField::vector_type rt_value
 The copy of the field value to be used in the haptics threads.
 
bool rt_value_changed
 Flag indicating if the rt_value has been changed by a haptics thread.
 
- Protected Attributes inherited from H3D::PeriodicUpdate< BaseField >
PeriodType period_type
 The tye of the period.
 
H3DFloat period
 The period of automatic updates/.
 
TimeStamp last_up_to_date
 The time of the last call to upToDate.
 
unsigned int counter
 The number of calls to timeToUpdate() since the last update.
 

Additional Inherited Members

- Public Types inherited from H3D::PeriodicUpdate< BaseField >
enum  PeriodType
 Type defining how the period should be interpreted.
 

Detailed Description

template<class BaseField>
class H3D::ThreadSafeMField< BaseField >

<>

A template modifier to add thread safety to an MField type. The field network should never be accessed from anything else than the main thread. Often though values provided by fields control behaviour of things happening in the haptic threads. Therefore separate copies of the field values have to be maintained for usage in the haptics thread. This field template modifies a normal MField class to contain such a copy. The getValue() and setValue() functions can then be used by both the haptics thread and the main thread and depending on from which thread it is called the copy or the field value is returned. Once per scene-graph loop it is checked whether either the copy or the field network value has changed since last loop and if it has the values are updated in a thread safe manner to contain the same value.

Member Function Documentation

◆ capacity()

template<class BaseField >
virtual BaseField::size_type H3D::ThreadSafeMField< BaseField >::capacity ( )
inlinevirtual

Number of elements for which memory has been allocated.

capacity() is always greater than or equal to size().

References H3DUtil::HapticThreadBase::inHapticThread(), H3DUtil::ThreadBase::inMainThread(), and H3D::ThreadSafeMField< BaseField >::rt_value.

◆ rbegin()

template<class BaseField >
virtual BaseField::const_reverse_iterator H3D::ThreadSafeMField< BaseField >::rbegin ( int  id = 0)
inlinevirtual

Returns a const_reverse_iterator pointing to the beginning of the reversed vector.

Parameters
idId of the node calling this function. Used to check access type.

References H3DUtil::HapticThreadBase::inHapticThread(), H3DUtil::ThreadBase::inMainThread(), and H3D::ThreadSafeMField< BaseField >::rt_value.

◆ rend()

template<class BaseField >
virtual BaseField::const_reverse_iterator H3D::ThreadSafeMField< BaseField >::rend ( int  id = 0)
inlinevirtual

Returns a const_reverse_iterator pointing to the end of the reversed vector.

Parameters
idId of the node calling this function. Used to check access type.

References H3DUtil::HapticThreadBase::inHapticThread(), H3DUtil::ThreadBase::inMainThread(), and H3D::ThreadSafeMField< BaseField >::rt_value.

◆ setValue() [1/2]

template<class BaseField >
virtual void H3D::ThreadSafeMField< BaseField >::setValue ( const vector< typename BaseField::value_type > &  v,
int  id = 0 
)
inlinevirtual

◆ setValue() [2/2]

template<class BaseField >
virtual void H3D::ThreadSafeMField< BaseField >::setValue ( typename BaseField::size_type  i,
const typename BaseField::value_type &  t,
int  id = 0 
)
inlinevirtual

Change the value of one element in the MField.

Parameters
iThe index of the value to set.
tThe new value.
idId of the node calling this function. Used to check access type.

References H3DUtil::HapticThreadBase::inHapticThread(), H3DUtil::ThreadBase::inMainThread(), H3D::ThreadSafeMField< BaseField >::rt_value, H3D::ThreadSafeMField< BaseField >::rt_value_changed, H3DUtil::HapticThreadBase::synchronousHapticCB(), and H3D::ThreadSafeMField< BaseField >::transferValue().

◆ upToDate()

template<class BaseField >
virtual void H3D::ThreadSafeMField< BaseField >::upToDate ( )
inlinevirtual

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