[Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/pxa27x/lib queue.c, NONE, 1.1 queue.h, NONE, 1.1

Robbie Adler radler at users.sourceforge.net
Tue Sep 6 11:19:37 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/platform/pxa27x/lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27579

Added Files:
	queue.c queue.h 
Log Message:
initial commit of queue library functions and datatype


--- NEW FILE: queue.c ---
#include "queue.h"

int pushqueue(queue_t *queue, unsigned long val){
    //check to see if there is room in the queue
  unsigned short availableslots = (queue->head <= queue->tail) ? queue->size - queue->tail + queue->head: queue->head - queue->tail;
  //available entries in the queue is really size-1 since we need to guard against aliasing
  if(availableslots > 1 ){
    queue->entries[queue->tail] = val;
    queue->tail++;
    if(queue->tail >= queue->size){
      queue->tail = 0;
    }
    return 1;
    }
  else{
    return 0;
  }
}

int popqueue(queue_t *queue, unsigned long *val) {
  if(queue->head != queue->tail){
    *val = queue->entries[queue->head];
    queue->head++;
    if(queue->head >= queue->size){
      queue->head = 0;
    }
    return 1;
  }
  else{
    *val = 0;
    //queue is empty
    return 0;
  }
}

void initqueue(queue_t *queue, unsigned long size) {
  queue->head = 0;
  queue->tail = 0;
  queue->size = size;
}

--- NEW FILE: queue.h ---
#ifndef __QUEUE_H__
#define __QUEUE_H__

#define QUEUE_SIZE 256

enum{
  defaultQueueSize = QUEUE_SIZE
    };

typedef struct{
  unsigned long entries[QUEUE_SIZE];
  unsigned short head, tail;
  unsigned short size;
} queue_t;

int pushqueue(queue_t *queue, unsigned long val);
int popqueue(queue_t *queue, unsigned long *val);
void initqueue(queue_t *queue, unsigned long size);

#endif



More information about the Tinyos-beta-commits mailing list