[Tinyos-2-commits] CVS: tinyos-2.x/tos/system AsyncFcfsQueueC.nc, NONE, 1.1.2.1 AsyncRoundRobinQueueC.nc, NONE, 1.1.2.1 FcfsQueueC.nc, NONE, 1.1.2.1 RoundRobinQueueC.nc, NONE, 1.1.2.1

Kevin Klues klueska at users.sourceforge.net
Mon May 15 11:16:19 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/tos/system
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11748/tos/system

Added Files:
      Tag: tos-2-resource-pm-eval-cand
	AsyncFcfsQueueC.nc AsyncRoundRobinQueueC.nc FcfsQueueC.nc 
	RoundRobinQueueC.nc 
Log Message:
Queues supporting new arbiters

--- NEW FILE: AsyncFcfsQueueC.nc ---
/*
 * "Copyright (c) 2005 Washington University in St. Louis.
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 *
 * IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
 * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
 * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
 * MODIFICATIONS."
 */

/**
 *
 * @author Kevin Klues (klueska at cs.wustl.edu)
 * @version $Revision: 1.1.2.1 $
 * @date $Date: 2006/05/15 18:16:17 $
 */
 
generic module AsyncFcfsQueueC(uint8_t size) {
  provides {
    interface Init;
    interface AsyncQueue as FcfsQueue;
  }
}
implementation {
  enum {NO_ENTRY = 0xFF};

  uint8_t resQ[size];
  uint8_t qHead = NO_ENTRY;
  uint8_t qTail = NO_ENTRY;
  
  bool inQueue(uint8_t id) {
    return resQ[id] != NO_ENTRY || qTail == id;
  }

  command error_t Init.init() {
    memset(resQ, NO_ENTRY, sizeof(resQ));
    return SUCCESS;
  }  

  async command uint8_t FcfsQueue.pop() {
    atomic {
      if(qHead != NO_ENTRY) {
        uint8_t id = qHead;
        qHead = resQ[qHead];
        if(qHead == NO_ENTRY)
          qTail = NO_ENTRY;
        resQ[id] = NO_ENTRY;
        return id;
      }
      return NO_ENTRY;
    }
  }
  
  async command error_t FcfsQueue.push(uint8_t id) {
    atomic {
      if(!inQueue(id)) {
        if(qHead == NO_ENTRY)
	        qHead = id;
	      else
  	      resQ[qTail] = id;
	      qTail = id;
        return SUCCESS;
      }
      return EBUSY;
    }
  }

  async command bool FcfsQueue.isEmpty() {
    atomic {
      if(qHead == NO_ENTRY) return TRUE;
      return FALSE;
    }
  }
}

--- NEW FILE: AsyncRoundRobinQueueC.nc ---
/*
 * "Copyright (c) 2005 Washington University in St. Louis.
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 *
 * IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
 * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
 * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
 * MODIFICATIONS."
 */

/**
 *
 * @author Kevin Klues (klueska at cs.wustl.edu)
 * @version $Revision: 1.1.2.1 $
 * @date $Date: 2006/05/15 18:16:17 $
 */
 
generic module AsyncRoundRobinQueueC(uint8_t size) {
  provides {
    interface Init;
    interface AsyncQueue as RoundRobinQueue;
  }
}
implementation {
  enum {NO_ENTRY = 0xFF};

  uint8_t resQ[(size-1)/8 + 1];
  uint8_t last = 0;
  
  bool inQueue(uint8_t id) {
    return resQ[id / 8] & (1 << (id % 8));
  }

  void clearEntry(uint8_t id) {
    resQ[id / 8] &= ~(1 << (id % 8));
  }

  command error_t Init.init() {
    memset(resQ, NO_ENTRY, sizeof(resQ));
    return SUCCESS;
  }  

  async command uint8_t RoundRobinQueue.pop() {
    int i;

    atomic {
      for (i = last+1; ; i++) {
        if(i == size)
          i = 0;
        if (i == last)
          break;
        if (inQueue(i)) {
          clearEntry(i);
          last = i;
          return i;
        }
      }
      return NO_ENTRY;
    }
  }
  
  async command error_t RoundRobinQueue.push(uint8_t id) {
    atomic {
      if (!inQueue(id)) {
        resQ[id / 8] |=  1 << (id % 8);
        return SUCCESS;
      }
      return EBUSY;
    }
  }

  async command bool RoundRobinQueue.isEmpty() {
    int i;
    atomic {
      for (i = 0; i<sizeof(resQ); i++)
        if(resQ[i] > 0) return FALSE;
      return TRUE;
    }
  }
}

--- NEW FILE: FcfsQueueC.nc ---
/*
 * "Copyright (c) 2005 Washington University in St. Louis.
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 *
 * IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
 * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
 * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
 * MODIFICATIONS."
 */

/**
 *
 * @author Kevin Klues (klueska at cs.wustl.edu)
 * @version $Revision: 1.1.2.1 $
 * @date $Date: 2006/05/15 18:16:17 $
 */
 
generic module FcfsQueueC(uint8_t size) {
  provides {
    interface Init;
    interface Queue as FcfsQueue;
  }
}
implementation {
  enum {NO_ENTRY = 0xFF};

  uint8_t resQ[size];
  uint8_t qHead = NO_ENTRY;
  uint8_t qTail = NO_ENTRY;
  
  bool inQueue(uint8_t id) {
    return resQ[id] != NO_ENTRY || qTail == id;
  }

  command error_t Init.init() {
    memset(resQ, NO_ENTRY, sizeof(resQ));
    return SUCCESS;
  }  

  command uint8_t FcfsQueue.pop() {
    if(qHead != NO_ENTRY) {
      uint8_t id = qHead;
      qHead = resQ[qHead];
      if(qHead == NO_ENTRY)
        qTail = NO_ENTRY;
      resQ[id] = NO_ENTRY;
      return id;
    }
    return NO_ENTRY;
  }
  
  command error_t FcfsQueue.push(uint8_t id) {
    if(!inQueue(id)) {
      if(qHead == NO_ENTRY)
	      qHead = id;
	    else
	      resQ[qTail] = id;
	    qTail = id;
      return SUCCESS;
    }
    return EBUSY;
  }

  command bool FcfsQueue.isEmpty() {
    if(qHead == NO_ENTRY) return TRUE;
    return FALSE;
  }
}

--- NEW FILE: RoundRobinQueueC.nc ---
/*
 * "Copyright (c) 2005 Washington University in St. Louis.
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 *
 * IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
 * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
 * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
 * MODIFICATIONS."
 */

/**
 *
 * @author Kevin Klues (klueska at cs.wustl.edu)
 * @version $Revision: 1.1.2.1 $
 * @date $Date: 2006/05/15 18:16:17 $
 */
 
generic module RoundRobinQueueC(uint8_t size) {
  provides {
    interface Init;
    interface Queue as RoundRobinQueue;
  }
}
implementation {
  enum {NO_ENTRY = 0xFF};

  uint8_t resQ[(size-1)/8 + 1];
  uint8_t last = 0;
  
  bool inQueue(uint8_t id) {
    return resQ[id / 8] & (1 << (id % 8));
  }

  void clearEntry(uint8_t id) {
    resQ[id / 8] &= ~(1 << (id % 8));
  }

  command error_t Init.init() {
    memset(resQ, NO_ENTRY, sizeof(resQ));
    return SUCCESS;
  }  

  command uint8_t RoundRobinQueue.pop() {
    int i;
    
    for (i = last+1; ; i++) {
      if(i == size)
        i = 0;
      if (i == last)
        break;
      if (inQueue(i)) {
        clearEntry(i);
        last = i;
        return i;
      }
    }
    return NO_ENTRY;
  }
  
  command error_t RoundRobinQueue.push(uint8_t id) {
    if (!inQueue(id)) {
      resQ[id / 8] |=  1 << (id % 8);
      return SUCCESS;
    }
    return EBUSY;
  }

  command bool RoundRobinQueue.isEmpty() {
    int i;
    for (i = 0; i<sizeof(resQ); i++)
      if(resQ[i] > 0) return FALSE;
    return TRUE;
  }
}



More information about the Tinyos-2-commits mailing list