• 沒有找到結果。

format is ready for reading. If the data stored in data relay is not complete or its format

N/A
N/A
Protected

Academic year: 2021

Share "format is ready for reading. If the data stored in data relay is not complete or its format "

Copied!
3
0
0

加載中.... (立即查看全文)

全文

(1)

38

Chapter 6 Implementation details

When we read data from audio data relay, we have to make sure that correct data

format is ready for reading. If the data stored in data relay is not complete or its format

is wrong, we couldn’t parse correct data information from it and fail to write data to

sound device. For solving the problem, using semaphore and blocking signals are used

in our system. Besides, we create a special mechanism, delay close, for another

problem that has been happened.

6.1. Using Semaphore

A semaphore is a general mechanism for controlling access to resources. We know

that there are different M-protocol formats for different system calls. If two system

calls write their data to audio relay at the same time, the data would be written to the

audio relay interactively. Then, the audio receiving daemon couldn’t write correct

system call to

/dev/dsp

, because the data receiving from network is not fit our

M-protocol format. We give a simple example: ioctl system call and write system call

are writing data to the data relay in turn. The data of ioctl and write system call are

alternate stored in data relay. This makes our audio-receiving daemon couldn’t

correctly parse these data receving from audio-sending daemon via network. Therefore,

we have to prevent from simultaneously running the same code or accessing the same

(2)

39

data, and a semaphore is used for this situation.

Semaphores in Linux are defined in <asm/semaphore.h>. The following call is used

when the semaphores are initialized.

#include <asm/semaphore.h>

struct semaphore sema;

sema_init(&sema, 1);

A process wishing to enter a section of code protected by a semaphore must first

ensure that no other process is already there. In Linux, we call

down

function.

#include <asm/semaphore.h>

struct semaphore sema;

down(&sema);

The functions test the value of the semaphore to see if it is greater than 0; if so, they

decrement the semaphore and return. If the semaphore is 0, the functions will sleep and

try again after some other process.

A process that obtains a semaphore must always release it afterward. Linux uses

function

up

. A simple call like

#include <asm/semaphore.h>

struct semaphore sema;

up(&sema);

will increment the value of the semaphore and wake up any processes that are

waiting for the semaphore to become available.

6.2. Forbid Signals

We solve the problem that two or more system calls simultaneously accessing the

(3)

40

same data by using semaphore. But it is interrupted by a signal when we are writing

system call, the data stored in data relay will not be complete M-protocol formats. In

the same way, our audio-receiving daemon couldn’t recognize the data format as well.

For the reason, we have to block signals during when we are writing data to data relay

or reading data from it.

Signal functions are defined in <linux/signal.h>. the system call

sys_rt_sigprocmask

is used to block or unblock signals.

#include <linux/signal.h>

struct sigset_t oldsig, newsig;

/* BLOCK signals */

if ((sys_rt_sigprocmask(SIG_BLOCK, &newsig, &oldsig, sizeof(newsig)) < 0) printk(“ Blocking signals is failed \n” );

/* Writing data to audio data relay or Reading data from it. */

/* Unblock signals */

if ((sys_rt_sigprocmask(SIG_UNBLOCK, &oldsig, NULL, sizeof(oldsig)) < 0) printk(“ Unblocking signals is failed \n” );

6.3. A Special Mechanism : Delay close

A process would be exited, it turns off resources, such as the file descriptor table.

We couldn’t take advantage of files including audio data relay then. So, the close

system calls could not be sent to receiving daemon during the time of terminating, we

delay the close system call sending until a new system call running.

參考文獻

相關文件

we use data (random sample) to test if the data provides significant evidence to reject the null hypothesis.. If X &gt; c reject

Now, nearly all of the current flows through wire S since it has a much lower resistance than the light bulb. The light bulb does not glow because the current flowing through it

● In computer science, a data structure is a data organization, management, and storage format that enables efficient access and

• But, If the representation of the data type is changed, the program needs to be verified, revised, or completely re- written... Abstract

To complete the “plumbing” of associating our vertex data with variables in our shader programs, you need to tell WebGL where in our buffer object to find the vertex data, and

A=fscanf(fid , format, size) reads data from the file specified by file identifier fid , converts it according to the specified format string, and returns it in matrix A..

Following the supply by the school of a copy of personal data in compliance with a data access request, the requestor is entitled to ask for correction of the personal data

• Use table to create a table for column-oriented or tabular data that is often stored as columns in a spreadsheet.. • Use detectImportOptions to create import options based on