The shared buffer of JES software is implemented by ‘jbuffer’. ‘jbuffer’ defines two roles: data producer and data consumer.
Data producer creates a ring buffer, and publicizes the name of this ring buffer. ‘jbuffer’ manages the ring buffer like a queue. Data producer appends the generated data to the end of the queue, and doesn’t check if data there has been all fetched. If the ring buffer is full, the new data will overwrite the old one, and update the status of the ring buffer.
Data consumer will open a buffer by the name of the ring buffer, and fetch the data from the head. The buffer opened by the data consumer is independent to each other, i.e., fetch data from an opened buffer will not effect the buffer opened by another data consumer using the same name. In the logic sense, this buffer is private to each data consumer. Data consumer will always fetch data from the head. Of the data producer overwrite the head and update the queue, the data consumer will miss the data and has to fetch the data from the updated head of the queue.
In a system, depending on the size of the buffer, it is allowed for the data consumer to fetch data in a non-smooth speed (if the buffer is large enough, it can wait for data consumer to consume data longer). In a given time period, the speed of the data consumer should be faster or equal to that of the data producer, otherwise, it’s a design flaw of the system.
When using ‘jbuffer’, it should first start ‘jbased’, which is the deamon process of jbase.
Jbuffer Interface Reference
Operations of data producer:
- jbuffer_create: create the shared buffer
- jbuffer_destroy: destroy the shared buffer
- jbuffer_set_options: set the options of shared buffer
- jbuffer_alloc: allocate a zone from the shared buffer
- jbuffer_release: release the allocated zone from the shared buffer
Operations of data consumer:
- jbuffer_open: open the shared buffer
- jbuffer_close: close the shared buffer
- jbuffer_get: fetch data from the shared buffer