1/* 2 * LICENSE NOTICE. 3 * 4 * Use of the Microsoft Windows Rally Development Kit is covered under 5 * the Microsoft Windows Rally Development Kit License Agreement, 6 * which is provided within the Microsoft Windows Rally Development 7 * Kit or at http://www.microsoft.com/whdc/rally/rallykit.mspx. If you 8 * want a license from Microsoft to use the software in the Microsoft 9 * Windows Rally Development Kit, you must (1) complete the designated 10 * "licensee" information in the Windows Rally Development Kit License 11 * Agreement, and (2) sign and return the Agreement AS IS to Microsoft 12 * at the address provided in the Agreement. 13 */ 14 15/* 16 * Copyright (c) Microsoft Corporation 2005. All rights reserved. 17 * This software is provided with NO WARRANTY. 18 */ 19 20#include "globals.h" 21 22#include "seeslist.h" 23 24struct topo_seeslist_st 25{ 26 topo_recvee_desc_t *data; /* data buffer */ 27 int count; /* how big data buffer is, in topo_recvee_desc_t units */ 28 int wr; /* next free slot for writing to buffer */ 29 int rd; /* next slot to read from buffer */ 30 /* wr == rd implies buffer empty */ 31}; 32 33#define sl g_sees 34 35topo_seeslist_t * 36seeslist_new(int count) 37{ 38 sl = xmalloc(sizeof(*sl) + count * sizeof(topo_recvee_desc_t)); 39 40 sl->data = (topo_recvee_desc_t*)(sl+1); 41 sl->count = count; 42 sl->wr = 0; 43 sl->rd = 0; 44 45 return sl; 46} 47 48 49bool_t 50seeslist_enqueue(bool_t isARP, etheraddr_t *realsrc) 51{ 52 topo_recvee_desc_t *desc; 53 54 if (((sl->wr + 1) % sl->count) == sl->rd) 55 return FALSE; /* circular buffer full */ 56 57 desc = &sl->data[sl->wr]; 58 sl->wr = (sl->wr + 1) % sl->count; 59 60 desc->rd_type = htons((uint16_t)!!isARP); 61 desc->rd_realsrc = *realsrc; 62 desc->rd_src = g_ethernet_hdr->eh_src; 63 desc->rd_dst = g_ethernet_hdr->eh_dst; 64 65 return TRUE; 66} 67 68bool_t 69seeslist_dequeue(/*OUT*/ topo_recvee_desc_t *dest) 70{ 71 if (sl->rd == sl->wr) 72 return FALSE; /* buffer empty */ 73 74 *dest = sl->data[sl->rd]; 75 sl->rd = (sl->rd + 1) % sl->count; 76 77 return TRUE; 78} 79 80 81void 82seeslist_clear(void) 83{ 84 sl->rd = 0; 85 sl->wr = 0; 86} 87 88bool_t 89seeslist_is_empty(void) 90{ 91 return (sl->rd == sl->wr); 92} 93 94 95 96void 97seeslist_free(void) 98{ 99 xfree(sl); 100} 101