The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/sound/midi/midiq.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2003 Mathew Kanner
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  *
   26  * $FreeBSD: stable/11/sys/dev/sound/midi/midiq.h 331722 2018-03-29 02:50:57Z eadler $
   27  */
   28 
   29 #ifndef MIDIQ_H
   30 #define MIDIQ_H
   31 
   32 #define MIDIQ_MOVE(a,b,c) bcopy(b,a,c)
   33 
   34 #define MIDIQ_HEAD(name, type)          \
   35 struct name {                           \
   36         int h, t, s;                    \
   37         type * b;                        \
   38 }
   39 
   40 #define MIDIQ_INIT(head, buf, size) do {                \
   41         (head).h=(head).t=0;                          \
   42         (head).s=size;                                 \
   43         (head).b=buf;                                  \
   44 } while (0)
   45 
   46 #define MIDIQ_EMPTY(head)       ((head).h == (head).t )
   47 
   48 #define MIDIQ_LENBASE(head)         ((head).h - (head).t < 0 ? \
   49                                         (head).h - (head).t + (head).s : \
   50                                         (head).h - (head).t)
   51 
   52 #define MIDIQ_FULL(head)        ((head).h == -1)
   53 #define MIDIQ_AVAIL(head)       (MIDIQ_FULL(head) ? 0 : (head).s - MIDIQ_LENBASE(head))
   54 #define MIDIQ_LEN(head)         ((head).s - MIDIQ_AVAIL(head))
   55 #define MIDIQ_DEBUG 0
   56 /*
   57  * No protection against overflow, underflow
   58  */
   59 #define MIDIQ_ENQ(head, buf, size) do {                                                                 \
   60                 if(MIDIQ_DEBUG)\
   61                         printf("#1 %p %p bytes copied %jd tran req s %d h %d t %d\n",            \
   62                                &(head).b[(head).h], (buf),                                        \
   63                                (intmax_t)(sizeof(*(head).b) *                                     \
   64                                           MIN( (size), (head).s - (head).h) ),                   \
   65                                (size), (head).h, (head).t);               \
   66                 MIDIQ_MOVE(&(head).b[(head).h], (buf), sizeof(*(head).b) * MIN((size), (head).s - (head).h));                       \
   67                 if( (head).s - (head).h < (size) ) {                                                    \
   68                         if(MIDIQ_DEBUG) \
   69                                 printf("#2 %p %p bytes copied %jd\n",  (head).b, (buf) + (head).s - (head).h, (intmax_t)sizeof(*(head).b) * ((size) - (head).s + (head).h) );      \
   70                         MIDIQ_MOVE((head).b, (buf) + (head).s - (head).h, sizeof(*(head).b) * ((size) - (head).s + (head).h) );      \
   71                 } \
   72                 (head).h+=(size);                                                                         \
   73                 (head).h%=(head).s;                                                                     \
   74                 if(MIDIQ_EMPTY(head)) (head).h=-1; \
   75                 if(MIDIQ_DEBUG)\
   76                         printf("#E h %d t %d\n", (head).h, (head).t);                       \
   77 } while (0)
   78 
   79 #define MIDIQ_DEQ_I(head, buf, size, move, update) do {                                                                 \
   80                 if(MIDIQ_FULL(head)) (head).h=(head).t; \
   81                 if(MIDIQ_DEBUG)\
   82                         printf("#1 %p %p bytes copied %jd tran req s %d h %d t %d\n", &(head).b[(head).t], (buf), (intmax_t)sizeof(*(head).b) * MIN((size), (head).s - (head).t), (size), (head).h, (head).t);                       \
   83                 if (move) MIDIQ_MOVE((buf), &(head).b[(head).t], sizeof(*(head).b) * MIN((size), (head).s - (head).t));                       \
   84                 if( (head).s - (head).t < (size) ) {                                                    \
   85                         if(MIDIQ_DEBUG) \
   86                                 printf("#2 %p %p bytes copied %jd\n",  (head).b, (buf) + (head).s - (head).t, (intmax_t)sizeof(*(head).b) * ((size) - (head).s + (head).t) );      \
   87                         if (move) MIDIQ_MOVE((buf) + (head).s - (head).t, (head).b, sizeof(*(head).b) * ((size) - (head).s + (head).t) );      \
   88                 } \
   89                 if (update) { \
   90                 (head).t+=(size);                                                                         \
   91                 (head).t%=(head).s;                                                                     \
   92                 } else { \
   93                   if (MIDIQ_EMPTY(head)) (head).h=-1; \
   94                 } \
   95                 if(MIDIQ_DEBUG)\
   96                         printf("#E h %d t %d\n", (head).h, (head).t);                       \
   97 } while (0)
   98 
   99 #define MIDIQ_SIZE(head) ((head).s)
  100 #define MIDIQ_CLEAR(head) ((head).h = (head).t = 0)
  101 #define MIDIQ_BUF(head) ((head).b)
  102 #define MIDIQ_DEQ(head, buf, size) MIDIQ_DEQ_I(head, buf, size, 1, 1)
  103 #define MIDIQ_PEEK(head, buf, size) MIDIQ_DEQ_I(head, buf, size, 1, 0)
  104 #define MIDIQ_POP(head, size) MIDIQ_DEQ_I(head, &head, size, 0, 1)
  105 
  106 #endif

Cache object: c0a1c7597a01a92fcc3566218a6b0877


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.