Example #1
0
void sem_signal(struct Semaphore *s)
{
  lock_acquire(&s->locksem);
  if(!empty_q(&s->t_q))
  {
      twakeup(pop_q(&s->t_q));
  }
  else
  {
    s->count++;
  }
  lock_release(&s->locksem);
}
Example #2
0
PROC *get_next_from_pid_q(PIDQ_HEAD *q)
{
	PROC		*p;
	PIDQ		*tmp = q->head;

	if (!empty_q(q)) {
		p = q->head->proc;
		q->head = tmp->next;
		free(tmp);
		return p;
	}

	return NULL;
}
Example #3
0
static inline PROC *get_next_from_pid_q(PIDQ *q)
{
	PROC *p;
	PIDQ *tmp = q->front;

	if (!empty_q(q)) {
		p = q->front->proc;
		q->front = tmp->next;
		free(tmp);
		return p;
	}

	return NULL;
}
Example #4
0
void sem_signal(struct Semaphore *s) {
	lock_acquire(&s->lock);
	if (s->count > 0) {
		s->count++;
		lock_release(&s->lock);
	}
	else {
		if (empty_q(&s->q) == 1)
			s->count++;
		else
			twakeup(pop_q(&s->q));
		lock_release(&s->lock);
	}
}
Example #5
0
int pop_q(struct queue *q){
    int val;
    struct node *destroy;
    if(!empty_q(q)){
       val = q->head->value; 
       destroy = q->head;
       q->head = q->head->next;
       free(destroy);
       q->size--;
       if(q->size == 0){
            q->head = 0;
            q->tail = 0;
       }
       return val;
    }
    return -1;
}
Example #6
0
int travel(){
	int i,j;
	Point p;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			count[i][j] = wand[i][j] = visited[i][j] = 0;
		}
	}
	init_q();
	enqueue(hermione);
	visited[hermione.x][hermione.y] = 1;
	while(!empty_q()){
		p = dequeue();
		if(forest[p.x][p.y] == '*')
			break;
		isvalid(p);
	}
}
Example #7
0
int add_pid_to_q(PIDQ_HEAD *q, PROC *p)
{
	PIDQ *tmp;

	tmp = (PIDQ *)xmalloc(sizeof(PIDQ));

	tmp->proc = p;
	tmp->next = NULL;

	if (empty_q(q)) {
		q->head = tmp;
		q->tail  = tmp;
	} else {
		q->tail->next = tmp;
		q->tail = tmp;
	}
	return 0;
}
Example #8
0
static inline int add_pid_to_q(PIDQ *q, PROC *p)
{
	PIDQ *tmp;

	tmp = (PIDQ *)malloc(sizeof(PIDQ));

	tmp->proc = p;
	tmp->next = NULL;

	if (empty_q(q)) {
		q->front = tmp;
		q->rear  = tmp;
	} else {
		q->rear->next = tmp;
		q->rear = tmp;
	}
	return 0;
}
Example #9
0
Point dequeue(){
	if(!empty_q()){
		return queue[front++];
	}
}