Python semaphore C

I have C code in which I implemented a locking mechanism using a semaphore. The main stream, as shown below,

int s=1;
void wait(){

    while(s<=0);
    s--;
}

void pipeData(paTestData *data){

    wait();

    SAMPLE *tempBuff = (SAMPLE*)malloc(sizeof(SAMPLE)*FRAME_SIZE);
    int readCount   = FRAME_SIZE;

    while(readCount > 0){

        tempBuff[FRAME_SIZE - readCount] = data->sampleValues[data->readFromCB];        
        data->readFromCB++;
        readCount--;
    }

    fd = open(fifoPipe, O_WRONLY);

    write(fd, tempBuff, sizeof(tempBuff));
    close(fd);

    free(tempBuff);

}

int callBack(){

    // Perform data acquisition and call foo

   foo();

    // Rest code here
}

The python code at the end of the reader is as follows:

with open(FIFO, 'rb') as fifo:
                print("Pipe opened")
                count=0
                while count<framelen:
                    Rsample = fifo.read()
                    frame = np.fromstring(Rsample,dtype=np.float32)

                    if (len(frame)>0):
                        print(frame)
                        count=count + len(frame)

Data at the other end is PIPEprocessed using Python Script. The problem is that reading PIPE at the end of python does not allow you to get the full data set.

This is because I read that for named PIPEeach entry it is necessary that the reader or open channel is blocked during the next iteration.

In this case, after writing 10 samplesto PIPE, the python reader implementation can read only first two samples, and PIPE is easily accessible for the next write set.

That is why I was looking locking mechanismfor the same.

My doubts are

1) , s ( signal() C ) , python script PIPE.

2) , IPC C Python?

!

+4
1
write(fd, tempBuff, sizeof(tempBuff));

4/8 (32-/64-) tempBuff

tempBuff,

write(fd, tempBuff, sizeof(SAMPLE)*FRAME_SIZE);
+2

Source: https://habr.com/ru/post/1681334/


All Articles