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/libprop/prop_stack.c

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 /* $NetBSD: prop_stack.c,v 1.2 2007/08/30 12:23:54 joerg Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>.
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  *
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in
   15  *    the documentation and/or other materials provided with the
   16  *    distribution.
   17  *
   18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
   22  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   23  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
   24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
   26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   28  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  */
   31 
   32 #include "prop_stack.h"
   33 #include "prop_object_impl.h"
   34 
   35 void
   36 _prop_stack_init(prop_stack_t stack)
   37 {
   38         stack->used_intern_elems = 0;
   39         SLIST_INIT(&stack->extern_elems);
   40 }
   41 
   42 bool
   43 _prop_stack_push(prop_stack_t stack, prop_object_t obj, void *data1,
   44     void *data2, void *data3)
   45 {
   46         struct _prop_stack_extern_elem *eelem;
   47         struct _prop_stack_intern_elem *ielem;
   48 
   49         if (stack->used_intern_elems == PROP_STACK_INTERN_ELEMS) {
   50                 eelem = _PROP_MALLOC(sizeof(*eelem), M_TEMP);
   51 
   52                 if (eelem == NULL)
   53                         return false;
   54 
   55                 eelem->object = obj;
   56                 eelem->object_data[0] = data1;
   57                 eelem->object_data[1] = data2;
   58                 eelem->object_data[2] = data3;
   59 
   60                 SLIST_INSERT_HEAD(&stack->extern_elems, eelem, stack_link);
   61 
   62                 return true;
   63         }
   64 
   65         _PROP_ASSERT(stack->used_intern_elems < PROP_STACK_INTERN_ELEMS);
   66         _PROP_ASSERT(SLIST_EMPTY(&stack->extern_elems));
   67 
   68         ielem = &stack->intern_elems[stack->used_intern_elems];
   69         ielem->object = obj;
   70         ielem->object_data[0] = data1;
   71         ielem->object_data[1] = data2;
   72         ielem->object_data[2] = data3;
   73 
   74         ++stack->used_intern_elems;
   75 
   76         return true;
   77 }
   78 
   79 bool
   80 _prop_stack_pop(prop_stack_t stack, prop_object_t *obj, void **data1,
   81     void **data2, void **data3)
   82 {
   83         struct _prop_stack_extern_elem *eelem;
   84         struct _prop_stack_intern_elem *ielem;
   85 
   86         if (stack->used_intern_elems == 0)
   87                 return false;
   88 
   89         if ((eelem = SLIST_FIRST(&stack->extern_elems)) != NULL) {
   90                 _PROP_ASSERT(stack->used_intern_elems == PROP_STACK_INTERN_ELEMS);
   91 
   92                 SLIST_REMOVE_HEAD(&stack->extern_elems, stack_link);
   93                 if (obj)
   94                         *obj = eelem->object;
   95                 if (data1)
   96                         *data1 = eelem->object_data[0];
   97                 if (data2)
   98                         *data2 = eelem->object_data[1];
   99                 if (data3)
  100                         *data3 = eelem->object_data[2];
  101                 _PROP_FREE(eelem, M_TEMP);
  102                 return true;
  103         }
  104 
  105         --stack->used_intern_elems;
  106         ielem = &stack->intern_elems[stack->used_intern_elems];
  107 
  108         if (obj)
  109                 *obj = ielem->object;
  110         if (data1)
  111                 *data1 = ielem->object_data[0];
  112         if (data2)
  113                 *data2 = ielem->object_data[1];
  114         if (data3)
  115                 *data3 = ielem->object_data[2];
  116 
  117         return true;
  118 }

Cache object: 0b393f7bdb26e9e3f1900f9f33e0dc13


[ 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.