mardi 27 avril 2021

Implementation of Mailbox in C

I have a client program which reads the data from the server and then gives the data to the application.I need to design such that application program and client program have to decoupled though they might belong to the same executable.So, I tried to simulate something like a dpm layer in between.For that I implemented a queue with a buffer element void** data so that I am able to store any type of data that is passed.

typedef struct QueueStruct {
    int size;
    int head;
    int tail;
    void** data;
} Queue;

I implemented functions memory_read and memory_write to read and write to the buffer.The client program calls the memory_write function and puts the data into the buffer and the application reads the latest data from the buffer by calling the memory_read function.I am able to achieve this much. Now I want to improve this design and implement mailbox in place of FIFO. This is what I want to acheive:

  1. Once the client writes the packet to the buffer in dpm file(queue is implemented in this file), I need to inform the application that the new data is available.
  2. Then the application reads the packet and then gives an acknowledgement to the dpm file that the data is read. So the data now can be discarded.
  3. To hide the shared memory in dpm and only give access to memory_read and memory_write functions.

I am not using any microcontroller so I do not know how to generate interrupts in simple C program to inform the application that new data is available and how to provide acknowledgement back .Should threads be created for client program and application program to decouple them? I read about named pipes and shared memory implementation in C.Are these the best ways to implement mailbox?Or there are any other better approaches available.

Edit : To read about mailbox design http://tool-support.renesas.com/autoupdate/support/onlinehelp/csp/V4.01.00/CS+.chm/Coding-RI600V4.chm/Output/MAILBOX.html

Aucun commentaire:

Enregistrer un commentaire