code:
/*-
 * Copyright (c) 2005 Robert N. M. Watson
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/lib/libmemstat/memstat.h 224569 2011-08-01 09:43:35Z pluknet $
 */

#ifndef _MEMSTAT_H_
#define	_MEMSTAT_H_

/*
 * Amount of caller data to maintain for each caller data slot.  Applications
 * must not request more than this number of caller save data, or risk
 * corrupting internal libmemstat(3) data structures.  A compile time check
 * in the application is probably appropriate.
 */
#define	MEMSTAT_MAXCALLER	16

/*
 * libmemstat(3) is able to extract memory data from different allocators;
 * when it does so, it tags which allocator it got the data from so that
 * consumers can determine which fields are usable, as data returned varies
 * some.
 */
#define	ALLOCATOR_UNKNOWN	0
#define	ALLOCATOR_MALLOC	1
#define	ALLOCATOR_UMA		2
#define	ALLOCATOR_ANY		255

/*
 * Library maximum type name.  Should be max(set of name maximums over
 * various allocators).
 */
#define	MEMTYPE_MAXNAME		32

/*
 * Library error conditions, mostly from the underlying data sources.  On
 * failure, functions typically return (-1) or (NULL); on success, (0) or a
 * valid data pointer.  The error from the last operation is stored in
 * struct memory_type_list, and accessed via memstat_get_error(list).
 */
#define	MEMSTAT_ERROR_UNDEFINED		0	/* Initialization value. */
#define	MEMSTAT_ERROR_NOMEMORY		1	/* Out of memory. */
#define	MEMSTAT_ERROR_VERSION		2	/* Unsupported version. */
#define	MEMSTAT_ERROR_PERMISSION	3	/* Permission denied. */
#define	MEMSTAT_ERROR_DATAERROR		5	/* Error in stat data. */
#define	MEMSTAT_ERROR_KVM		6	/* See kvm_geterr() for err. */
#define	MEMSTAT_ERROR_KVM_NOSYMBOL	7	/* Symbol not available. */
#define	MEMSTAT_ERROR_KVM_SHORTREAD	8	/* Short kvm_read return. */

/*
 * Forward declare struct memory_type, which holds per-type properties and
 * statistics.  This is an opaque type, to be frobbed only from within the
 * library, in order to avoid building ABI assumptions into the application.
 * Accessor methods should be used to get and sometimes set the fields from
 * consumers of the library.
 */
struct memory_type;

/*
 * struct memory_type_list is the head of a list of memory types and
 * statistics.
 */
struct memory_type_list;

__BEGIN_DECLS
/*
 * Functions that operate without memory type or memory type list context.
 */
const char	*memstat_strerror(int error);

/*
 * Functions for managing memory type and statistics data.
 */
struct memory_type_list	*memstat_mtl_alloc(void);
struct memory_type	*memstat_mtl_first(struct memory_type_list *list);
struct memory_type	*memstat_mtl_next(struct memory_type *mtp);
struct memory_type	*memstat_mtl_find(struct memory_type_list *list,
			    int allocator, const char *name);
void	memstat_mtl_free(struct memory_type_list *list);
int	memstat_mtl_geterror(struct memory_type_list *list);

/*
 * Functions to retrieve data from a live kernel using sysctl.
 */
int	memstat_sysctl_all(struct memory_type_list *list, int flags);
int	memstat_sysctl_malloc(struct memory_type_list *list, int flags);
int	memstat_sysctl_uma(struct memory_type_list *list, int flags);

/*
 * Functions to retrieve data from a kernel core (or /dev/kmem).
 */
int	memstat_kvm_all(struct memory_type_list *list, void *kvm_handle);
int	memstat_kvm_malloc(struct memory_type_list *list, void *kvm_handle);
int	memstat_kvm_uma(struct memory_type_list *list, void *kvm_handle);

/*
 * Accessor methods for struct memory_type.
 */
const char	*memstat_get_name(const struct memory_type *mtp);
int		 memstat_get_allocator(const struct memory_type *mtp);
uint64_t	 memstat_get_countlimit(const struct memory_type *mtp);
uint64_t	 memstat_get_byteslimit(const struct memory_type *mtp);
uint64_t	 memstat_get_sizemask(const struct memory_type *mtp);
uint64_t	 memstat_get_size(const struct memory_type *mtp);
uint64_t	 memstat_get_memalloced(const struct memory_type *mtp);
uint64_t	 memstat_get_memfreed(const struct memory_type *mtp);
uint64_t	 memstat_get_numallocs(const struct memory_type *mtp);
uint64_t	 memstat_get_numfrees(const struct memory_type *mtp);
uint64_t	 memstat_get_bytes(const struct memory_type *mtp);
uint64_t	 memstat_get_count(const struct memory_type *mtp);
uint64_t	 memstat_get_free(const struct memory_type *mtp);
uint64_t	 memstat_get_failures(const struct memory_type *mtp);
uint64_t	 memstat_get_sleeps(const struct memory_type *mtp);
void		*memstat_get_caller_pointer(const struct memory_type *mtp,
		    int index);
void		 memstat_set_caller_pointer(struct memory_type *mtp,
		    int index, void *value);
uint64_t	 memstat_get_caller_uint64(const struct memory_type *mtp,
		    int index);
void		 memstat_set_caller_uint64(struct memory_type *mtp, int index,
		    uint64_t value);
uint64_t	 memstat_get_zonefree(const struct memory_type *mtp);
uint64_t	 memstat_get_kegfree(const struct memory_type *mtp);
uint64_t	 memstat_get_percpu_memalloced(const struct memory_type *mtp,
		    int cpu);
uint64_t	 memstat_get_percpu_memfreed(const struct memory_type *mtp,
		    int cpu);
uint64_t	 memstat_get_percpu_numallocs(const struct memory_type *mtp,
		    int cpu);
uint64_t	 memstat_get_percpu_numfrees(const struct memory_type *mtp,
		    int cpu);
uint64_t	 memstat_get_percpu_sizemask(const struct memory_type *mtp,
		    int cpu);
void		*memstat_get_percpu_caller_pointer(
		    const struct memory_type *mtp, int cpu, int index);
void		 memstat_set_percpu_caller_pointer(struct memory_type *mtp,
		    int cpu, int index, void *value);
uint64_t	 memstat_get_percpu_caller_uint64(
		    const struct memory_type *mtp, int cpu, int index);
void		 memstat_set_percpu_caller_uint64(struct memory_type *mtp,
		    int cpu, int index, uint64_t value);
uint64_t	 memstat_get_percpu_free(const struct memory_type *mtp,
		    int cpu);
__END_DECLS

#endif /* !_MEMSTAT_H_ */


code:
/****************************************************************************
 * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc.              *
 *                                                                          *
 * Permission is hereby granted, free of charge, to any person obtaining a  *
 * copy of this software and associated documentation files (the            *
 * "Software"), to deal in the Software without restriction, including      *
 * without limitation the rights to use, copy, modify, merge, publish,      *
 * distribute, distribute with modifications, sublicense, and/or sell       *
 * copies of the Software, and to permit persons to whom the Software is    *
 * furnished to do so, subject to the following conditions:                 *
 *                                                                          *
 * The above copyright notice and this permission notice shall be included  *
 * in all copies or substantial portions of the Software.                   *
 *                                                                          *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
 *                                                                          *
 * Except as contained in this notice, the name(s) of the above copyright   *
 * holders shall not be used in advertising or otherwise to promote the     *
 * sale, use or other dealings in this Software without prior written       *
 * authorization.                                                           *
 ****************************************************************************/

/****************************************************************************
 *   Author:  Juergen Pfeifer, 1995,1997                                    *
 ****************************************************************************/

/* $Id: menu.h,v 1.19 2007/02/24 17:32:13 tom Exp $ */

#ifndef ETI_MENU
#define ETI_MENU

#ifdef AMIGA
#define TEXT TEXT_ncurses
#endif

#include <curses.h>
#include <eti.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef int Menu_Options;
typedef int Item_Options;

/* Menu options: */
#define O_ONEVALUE      (0x01)
#define O_SHOWDESC      (0x02)
#define O_ROWMAJOR      (0x04)
#define O_IGNORECASE    (0x08)
#define O_SHOWMATCH     (0x10)
#define O_NONCYCLIC     (0x20)

/* Item options: */
#define O_SELECTABLE    (0x01)

typedef struct
{
  const char* str;
  unsigned short length;
} TEXT;

typedef struct tagITEM
{
  TEXT           name;        /* name of menu item                         */
  TEXT           description; /* description of item, optional in display  */
  struct tagMENU *imenu;      /* Pointer to parent menu                    */
  void           *userptr;    /* Pointer to user defined per item data     */
  Item_Options   opt;         /* Item options                              */
  short          index;       /* Item number if connected to a menu        */
  short          y;           /* y and x location of item in menu          */
  short          x;
  bool           value;       /* Selection value                           */

  struct tagITEM *left;       /* neighbor items                            */
  struct tagITEM *right;
  struct tagITEM *up;
  struct tagITEM *down;

} ITEM;

typedef void (*Menu_Hook)(struct tagMENU *);

typedef struct tagMENU
{
  short          height;                /* Nr. of chars high               */
  short          width;                 /* Nr. of chars wide               */
  short          rows;                  /* Nr. of items high               */
  short          cols;                  /* Nr. of items wide               */
  short          frows;                 /* Nr. of formatted items high     */
  short          fcols;                 /* Nr. of formatted items wide     */
  short          arows;                 /* Nr. of items high (actual)      */
  short          namelen;               /* Max. name length                */
  short          desclen;               /* Max. description length         */
  short          marklen;               /* Length of mark, if any          */
  short          itemlen;               /* Length of one item              */
  short          spc_desc;              /* Spacing for descriptor          */
  short          spc_cols;              /* Spacing for columns             */
  short          spc_rows;              /* Spacing for rows                */
  char          *pattern;               /* Buffer to store match chars     */
  short          pindex;                /* Index into pattern buffer       */
  WINDOW        *win;                   /* Window containing menu          */
  WINDOW        *sub;                   /* Subwindow for menu display      */
  WINDOW        *userwin;               /* User's window                   */
  WINDOW        *usersub;               /* User's subwindow                */
  ITEM          **items;                /* array of items                  */
  short          nitems;                /* Nr. of items in menu            */
  ITEM          *curitem;               /* Current item                    */
  short          toprow;                /* Top row of menu                 */
  chtype         fore;                  /* Selection attribute             */
  chtype         back;                  /* Nonselection attribute          */
  chtype         grey;                  /* Inactive attribute              */
  unsigned char  pad;                   /* Pad character                   */

  Menu_Hook      menuinit;              /* User hooks                      */
  Menu_Hook      menuterm;
  Menu_Hook      iteminit;
  Menu_Hook      itemterm;

  void          *userptr;               /* Pointer to menus user data      */
  char          *mark;                  /* Pointer to marker string        */

  Menu_Options   opt;                   /* Menu options                    */
  unsigned short status;                /* Internal state of menu          */

} MENU;

/* Define keys */

#define REQ_LEFT_ITEM           (KEY_MAX + 1)
#define REQ_RIGHT_ITEM          (KEY_MAX + 2)
#define REQ_UP_ITEM             (KEY_MAX + 3)
#define REQ_DOWN_ITEM           (KEY_MAX + 4)
#define REQ_SCR_ULINE           (KEY_MAX + 5)
#define REQ_SCR_DLINE           (KEY_MAX + 6)
#define REQ_SCR_DPAGE           (KEY_MAX + 7)
#define REQ_SCR_UPAGE           (KEY_MAX + 8)
#define REQ_FIRST_ITEM          (KEY_MAX + 9)
#define REQ_LAST_ITEM           (KEY_MAX + 10)
#define REQ_NEXT_ITEM           (KEY_MAX + 11)
#define REQ_PREV_ITEM           (KEY_MAX + 12)
#define REQ_TOGGLE_ITEM         (KEY_MAX + 13)
#define REQ_CLEAR_PATTERN       (KEY_MAX + 14)
#define REQ_BACK_PATTERN        (KEY_MAX + 15)
#define REQ_NEXT_MATCH          (KEY_MAX + 16)
#define REQ_PREV_MATCH          (KEY_MAX + 17)

#define MIN_MENU_COMMAND        (KEY_MAX + 1)
#define MAX_MENU_COMMAND        (KEY_MAX + 17)

/*
 * Some AT&T code expects MAX_COMMAND to be out-of-band not
 * just for menu commands but for forms ones as well.
 */
#if defined(MAX_COMMAND)
#  if (MAX_MENU_COMMAND > MAX_COMMAND)
#    error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND
#  elif (MAX_COMMAND != (KEY_MAX + 128))
#    error Something is wrong -- MAX_COMMAND is already inconsistently defined.
#  endif
#else
#  define MAX_COMMAND (KEY_MAX + 128)
#endif

/* --------- prototypes for libmenu functions ----------------------------- */

extern NCURSES_EXPORT(ITEM **)	menu_items (const MENU *);
extern NCURSES_EXPORT(ITEM *)	current_item (const MENU *);
extern NCURSES_EXPORT(ITEM *)	new_item (const char *,const char *);

extern NCURSES_EXPORT(MENU *)	new_menu (ITEM **);

extern NCURSES_EXPORT(Item_Options)	item_opts (const ITEM *);
extern NCURSES_EXPORT(Menu_Options)	menu_opts (const MENU *);

extern NCURSES_EXPORT(Menu_Hook)	item_init (const MENU *);
extern NCURSES_EXPORT(Menu_Hook)	item_term (const MENU *);
extern NCURSES_EXPORT(Menu_Hook)	menu_init (const MENU *);
extern NCURSES_EXPORT(Menu_Hook)	menu_term (const MENU *);

extern NCURSES_EXPORT(WINDOW *)	menu_sub (const MENU *);
extern NCURSES_EXPORT(WINDOW *)	menu_win (const MENU *);

extern NCURSES_EXPORT(const char *)	item_description (const ITEM *);
extern NCURSES_EXPORT(const char *)	item_name (const ITEM *);
extern NCURSES_EXPORT(const char *)	menu_mark (const MENU *);
extern NCURSES_EXPORT(const char *)	menu_request_name (int);

extern NCURSES_EXPORT(char *)	menu_pattern (const MENU *);

extern NCURSES_EXPORT(void *)	menu_userptr (const MENU *);
extern NCURSES_EXPORT(void *)	item_userptr (const ITEM *);

extern NCURSES_EXPORT(chtype)	menu_back (const MENU *);
extern NCURSES_EXPORT(chtype)	menu_fore (const MENU *);
extern NCURSES_EXPORT(chtype)	menu_grey (const MENU *);

extern NCURSES_EXPORT(int)	free_item (ITEM *);
extern NCURSES_EXPORT(int)	free_menu (MENU *);
extern NCURSES_EXPORT(int)	item_count (const MENU *);
extern NCURSES_EXPORT(int)	item_index (const ITEM *);
extern NCURSES_EXPORT(int)	item_opts_off (ITEM *,Item_Options);
extern NCURSES_EXPORT(int)	item_opts_on (ITEM *,Item_Options);
extern NCURSES_EXPORT(int)	menu_driver (MENU *,int);
extern NCURSES_EXPORT(int)	menu_opts_off (MENU *,Menu_Options);
extern NCURSES_EXPORT(int)	menu_opts_on (MENU *,Menu_Options);
extern NCURSES_EXPORT(int)	menu_pad (const MENU *);
extern NCURSES_EXPORT(int)	pos_menu_cursor (const MENU *);
extern NCURSES_EXPORT(int)	post_menu (MENU *);
extern NCURSES_EXPORT(int)	scale_menu (const MENU *,int *,int *);
extern NCURSES_EXPORT(int)	set_current_item (MENU *menu,ITEM *item);
extern NCURSES_EXPORT(int)	set_item_init (MENU *, Menu_Hook);
extern NCURSES_EXPORT(int)	set_item_opts (ITEM *,Item_Options);
extern NCURSES_EXPORT(int)	set_item_term (MENU *, Menu_Hook);
extern NCURSES_EXPORT(int)	set_item_userptr (ITEM *, void *);
extern NCURSES_EXPORT(int)	set_item_value (ITEM *,bool);
extern NCURSES_EXPORT(int)	set_menu_back (MENU *,chtype);
extern NCURSES_EXPORT(int)	set_menu_fore (MENU *,chtype);
extern NCURSES_EXPORT(int)	set_menu_format (MENU *,int,int);
extern NCURSES_EXPORT(int)	set_menu_grey (MENU *,chtype);
extern NCURSES_EXPORT(int)	set_menu_init (MENU *, Menu_Hook);
extern NCURSES_EXPORT(int)	set_menu_items (MENU *,ITEM **);
extern NCURSES_EXPORT(int)	set_menu_mark (MENU *, const char *);
extern NCURSES_EXPORT(int)	set_menu_opts (MENU *,Menu_Options);
extern NCURSES_EXPORT(int)	set_menu_pad (MENU *,int);
extern NCURSES_EXPORT(int)	set_menu_pattern (MENU *,const char *);
extern NCURSES_EXPORT(int)	set_menu_sub (MENU *,WINDOW *);
extern NCURSES_EXPORT(int)	set_menu_term (MENU *, Menu_Hook);
extern NCURSES_EXPORT(int)	set_menu_userptr (MENU *,void *);
extern NCURSES_EXPORT(int)	set_menu_win (MENU *,WINDOW *);
extern NCURSES_EXPORT(int)	set_top_row (MENU *,int);
extern NCURSES_EXPORT(int)	top_row (const MENU *);
extern NCURSES_EXPORT(int)	unpost_menu (MENU *);
extern NCURSES_EXPORT(int)	menu_request_by_name (const char *);
extern NCURSES_EXPORT(int)	set_menu_spacing (MENU *,int,int,int);
extern NCURSES_EXPORT(int)	menu_spacing (const MENU *,int *,int *,int *);

extern NCURSES_EXPORT(bool)	item_value (const ITEM *);
extern NCURSES_EXPORT(bool)	item_visible (const ITEM *);

extern NCURSES_EXPORT(void)	menu_format (const MENU *,int *,int *);

#ifdef __cplusplus
  }
#endif

#endif /* ETI_MENU */

repo_name: veiledmerc/mira

license: mit


code:
/*-
 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/include/monetary.h 103667 2002-09-20 08:22:48Z mike $
 */

#ifndef _MONETARY_H_
#define	_MONETARY_H_

#include <sys/cdefs.h>
#include <sys/_types.h>

#ifndef _SIZE_T_DECLARED
typedef	__size_t	size_t;
#define	_SIZE_T_DECLARED
#endif

#ifndef _SSIZE_T_DECLARED
typedef	__ssize_t	ssize_t;
#define	_SSIZE_T_DECLARED
#endif

__BEGIN_DECLS
ssize_t	strfmon(char * __restrict, size_t, const char * __restrict, ...);
__END_DECLS

#endif /* !_MONETARY_H_ */


code:
/* $FreeBSD: release/9.0.0/lib/libmp/mp.h 189092 2009-02-26 21:43:15Z ed $ */

#ifndef _MP_H_
#define _MP_H_

#ifndef HEADER_BN_H_
#include <openssl/bn.h>
#endif

typedef struct _mint {
	BIGNUM *bn;
} MINT;

void mp_gcd(const MINT *, const MINT *, MINT *);
MINT *mp_itom(short);
void mp_madd(const MINT *, const MINT *, MINT *);
int mp_mcmp(const MINT *, const MINT *);
void mp_mdiv(const MINT *, const MINT *, MINT *, MINT *);
void mp_mfree(MINT *);
void mp_min(MINT *);
void mp_mout(const MINT *);
void mp_move(const MINT *, MINT *);
void mp_msqrt(const MINT *, MINT *, MINT *);
void mp_msub(const MINT *, const MINT *, MINT *);
char *mp_mtox(const MINT *);
void mp_mult(const MINT *, const MINT *, MINT *);
void mp_pow(const MINT *, const MINT *, const MINT *, MINT *);
void mp_rpow(const MINT *, short, MINT *);
void mp_sdiv(const MINT *, short, MINT *, short *);
MINT *mp_xtom(const char *);

#endif /* !_MP_H_ */


code:
/*-
 * Copyright (c) 1991, 1993, 1994
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)mpool.h	8.4 (Berkeley) 11/2/95
 * $FreeBSD: release/9.0.0/include/mpool.h 203964 2010-02-16 19:39:50Z imp $
 */

#ifndef _MPOOL_H_
#define _MPOOL_H_

#include <sys/queue.h>

/*
 * The memory pool scheme is a simple one.  Each in-memory page is referenced
 * by a bucket which is threaded in up to two of three ways.  All active pages
 * are threaded on a hash chain (hashed by page number) and an lru chain.
 * Inactive pages are threaded on a free chain.  Each reference to a memory
 * pool is handed an opaque MPOOL cookie which stores all of this information.
 */
#define	HASHSIZE	128
#define	HASHKEY(pgno)	((pgno - 1 + HASHSIZE) % HASHSIZE)

/* The BKT structures are the elements of the queues. */
typedef struct _bkt {
	TAILQ_ENTRY(_bkt) hq;		/* hash queue */
	TAILQ_ENTRY(_bkt) q;		/* lru queue */
	void    *page;			/* page */
	pgno_t   pgno;			/* page number */

#define	MPOOL_DIRTY	0x01		/* page needs to be written */
#define	MPOOL_PINNED	0x02		/* page is pinned into memory */
#define	MPOOL_INUSE	0x04		/* page address is valid */
	u_int8_t flags;			/* flags */
} BKT;

typedef struct MPOOL {
	TAILQ_HEAD(_lqh, _bkt) lqh;	/* lru queue head */
					/* hash queue array */
	TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE];
	pgno_t	curcache;		/* current number of cached pages */
	pgno_t	maxcache;		/* max number of cached pages */
	pgno_t	npages;			/* number of pages in the file */
	unsigned long	pagesize;	/* file page size */
	int	fd;			/* file descriptor */
					/* page in conversion routine */
	void    (*pgin)(void *, pgno_t, void *);
					/* page out conversion routine */
	void    (*pgout)(void *, pgno_t, void *);
	void	*pgcookie;		/* cookie for page in/out routines */
#ifdef STATISTICS
	unsigned long	cachehit;
	unsigned long	cachemiss;
	unsigned long	pagealloc;
	unsigned long	pageflush;
	unsigned long	pageget;
	unsigned long	pagenew;
	unsigned long	pageput;
	unsigned long	pageread;
	unsigned long	pagewrite;
#endif
} MPOOL;

#define	MPOOL_IGNOREPIN	0x01		/* Ignore if the page is pinned. */
#define	MPOOL_PAGE_REQUEST	0x01	/* Allocate a new page with a
					   specific page number. */
#define	MPOOL_PAGE_NEXT		0x02	/* Allocate a new page with the next
					  page number. */

__BEGIN_DECLS
MPOOL	*mpool_open(void *, int, pgno_t, pgno_t);
void	 mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *),
	    void (*)(void *, pgno_t, void *), void *);
void	*mpool_new(MPOOL *, pgno_t *, unsigned int);
void	*mpool_get(MPOOL *, pgno_t, unsigned int);
int	 mpool_delete(MPOOL *, void *);
int	 mpool_put(MPOOL *, void *, unsigned int);
int	 mpool_sync(MPOOL *);
int	 mpool_close(MPOOL *);
#ifdef STATISTICS
void	 mpool_stat(MPOOL *);
#endif
__END_DECLS

#endif


code:
/*-
 * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/include/mqueue.h 165828 2007-01-06 11:30:04Z davidxu $
 */

#ifndef _MQUEUE_H_
#define _MQUEUE_H_

#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/mqueue.h>

struct sigevent;
struct timespec;

__BEGIN_DECLS
int	mq_close(mqd_t);
int	mq_getattr(mqd_t, struct mq_attr *);
int	mq_notify(mqd_t, const struct sigevent *);
mqd_t	mq_open(const char *, int, ...);
ssize_t	mq_receive(mqd_t, char *, size_t, unsigned *);
int	mq_send(mqd_t, const char *, size_t, unsigned);
int	mq_setattr(mqd_t, const struct mq_attr *__restrict,
		struct mq_attr *__restrict);
ssize_t	mq_timedreceive(mqd_t, char *__restrict, size_t,
		unsigned *__restrict, const struct timespec *__restrict);
int	mq_timedsend(mqd_t, const char *, size_t, unsigned,
		const struct timespec *);
int	mq_unlink(const char *);
int	__mq_oshandle(mqd_t mqd);

__END_DECLS
#endif