This class implements a shared data item which can be protected against data corruption by pre-emptive multithreading. More...
Public Member Functions | |
def | __init__ (self, type_code, thread_protect=True, name=None) |
Allocate memory in which the shared data will be buffered. More... | |
def | put (self, data, in_ISR=False) |
Write an item of data into the share. More... | |
def | get (self, in_ISR=False) |
Read an item of data from the share. More... | |
def | __repr__ (self) |
This method puts diagnostic information about the share into a string. | |
Static Public Attributes | |
int | ser_num = 0 |
A counter used to give serial numbers to shares for diagnostic use. | |
This class implements a shared data item which can be protected against data corruption by pre-emptive multithreading.
Multithreading which can corrupt shared data includes the use of ordinary interrupts as well as the use of a Real-Time Operating System (RTOS).
def task_share.Share.__init__ | ( | self, | |
type_code, | |||
thread_protect = True , |
|||
name = None |
|||
) |
Allocate memory in which the shared data will be buffered.
The data type code is given as for the Python 'array' type, which can be any of
type_code | The type of data items which the share can hold |
thread_protect | True if mutual exclusion protection is used |
name | A short name for the share, default ShareN where N is a serial number for the share |
def task_share.Share.get | ( | self, | |
in_ISR = False |
|||
) |
Read an item of data from the share.
Interrupts are disabled as the data is read so as to prevent data corruption by changes in the data as it is being read.
in_ISR | Set this to True if calling from within an ISR |
def task_share.Share.put | ( | self, | |
data, | |||
in_ISR = False |
|||
) |
Write an item of data into the share.
Any old data is overwritten. This code disables interrupts during the writing so as to prevent data corrupting by an interrupt service routine which might access the same data.
data | The data to be put into this share |
in_ISR | Set this to True if calling from within an ISR |