Hi, any experts there willing to help:
I am a new grad trying to learn how to write linux device
driver and started reading the kernel code.
I first try to understand how semaphore is implemented (kernel/sched.c
and includ/asm-i386/semaphore.h) and have encounted several problems:
(1) The meaning of "__asm__" & "__volatile_()" which is used to define
down and up. (primitive or directive of assembly? or compiler?)
I cannot find their definitions in (a)*.h file (b) C reference
mannul (c) the index of a 386/486 assembly book.
(2) why there are two sets of semaphore. down/up and __down/__up.
(3) what does " struct wait_queue **p" point to, which is often the
first argument passed to functions operating on wait_queue, e.g,
extern inline void __add_wait_queue(struct wait_queue ** p,
struct wait_queue * wait)
{
struct wait_queue *head = *p;
struct wait_queue *next = WAIT_QUEUE_HEAD(p);
if (head)
next = head;
*p = wait;
wait->next = next;
* Is the address of p always related to the head of queue:Quote:}
&p = &head + sizeof(struct wait_queue)?
* Does p always point to the tail of the queue?
* Or is there any order for the queue? It's a circularly linked list.
One field in the semaphore structure is of "struct wait_queue":
struct semaphore {
int count;
int waiting;
struct wait_queue * wait;
and is used asQuote:};
add_wait_queue(&sem->wait, &wait);