typedef struct _readyQ {
pcb_t *pcb;
struct _readyQ *next;
} readyQ;
static readyQ *ready_queue_head = NULL, *ready_queue_tail = NULL;
static void submit_ready_request(pcb_t *pcb);
static void submit_ready_request(pcb_t *pcb)
{
readyQ *r;
/* Build I/O Request */
r = malloc(sizeof(readyQ));
assert(r != NULL);
r->pcb = pcb;
r->next = NULL;
pthread_mutex_lock(&readyQ_mutex);
/* Add request to head of queue */
if (ready_queue_tail != NULL)
{
ready_queue_tail->next = r;
ready_queue_tail = r;
}
else
{
ready_queue_head = r;
ready_queue_tail = r;
}
pthread_mutex_unlock(&readyQ_mutex);
}
最初头/尾都是NULL。所以,当我第一次通过 submit_ready_request 添加时,我会去其他部分
ready_queue_head = r;
ready_queue_tail = r;
都指向同一个 readyQ r。
现在,当我添加另一个时,它将转到
ready_queue_tail->next = r;
ready_queue_tail = r;
我想知道在这种情况下,
ready_queue_head->next
执行上面的代码后会指向 r 吗?
因为我试图通过这个删除,但它不起作用
readyQ *r;
r = malloc(sizeof(readyQ));
if (ready_queue_head != NULL) { //not empty so remove
r = ready_queue_head;
if(ready_queue_head->next != NULL){
ready_queue_head = ready_queue_head->next;
} else { //only one in the queue
ready_queue_head = NULL;
ready_queue_tail = NULL;
}
}