1*4582Scth /* 2*4582Scth * CDDL HEADER START 3*4582Scth * 4*4582Scth * The contents of this file are subject to the terms of the 5*4582Scth * Common Development and Distribution License (the "License"). 6*4582Scth * You may not use this file except in compliance with the License. 7*4582Scth * 8*4582Scth * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*4582Scth * or http://www.opensolaris.org/os/licensing. 10*4582Scth * See the License for the specific language governing permissions 11*4582Scth * and limitations under the License. 12*4582Scth * 13*4582Scth * When distributing Covered Code, include this CDDL HEADER in each 14*4582Scth * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*4582Scth * If applicable, add the following below this CDDL HEADER, with the 16*4582Scth * fields enclosed by brackets "[]" replaced with your own identifying 17*4582Scth * information: Portions Copyright [yyyy] [name of copyright owner] 18*4582Scth * 19*4582Scth * CDDL HEADER END 20*4582Scth */ 21*4582Scth 22*4582Scth /* 23*4582Scth * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24*4582Scth * Use is subject to license terms. 25*4582Scth */ 26*4582Scth 27*4582Scth #ifndef _UTIL_H 28*4582Scth #define _UTIL_H 29*4582Scth 30*4582Scth #pragma ident "%Z%%M% %I% %E% SMI" 31*4582Scth 32*4582Scth /* 33*4582Scth * Utility functions and macros 34*4582Scth */ 35*4582Scth 36*4582Scth #ifdef __cplusplus 37*4582Scth extern "C" { 38*4582Scth #endif 39*4582Scth 40*4582Scth #include <stdio.h> 41*4582Scth #include <stdarg.h> 42*4582Scth #include <time.h> 43*4582Scth 44*4582Scth extern int _dm_assert(const char *assertion, const char *file, int line, 45*4582Scth const char *func); 46*4582Scth 47*4582Scth #if defined(__STDC__) 48*4582Scth #if __STDC_VERSION__ - 0 >= 199901L 49*4582Scth #define dm_assert(EX) (void)((EX) ? 0 : \ 50*4582Scth _dm_assert(#EX, __FILE__, __LINE__, __func__)) 51*4582Scth #else 52*4582Scth #define dm_assert(EX) (void)((EX) ? 0 : \ 53*4582Scth _dm_assert(#EX, __FILE__, __LINE__, NULL)) 54*4582Scth #endif /* __STDC_VERSION__ - 0 >= 199901L */ 55*4582Scth #else 56*4582Scth #define dm_assert(EX) (void)((EX) ? 0 : \ 57*4582Scth _dm_assert("EX", __FILE__, __LINE__, NULL)) 58*4582Scth #endif /* __STDC__ */ 59*4582Scth 60*4582Scth /* 61*4582Scth * The following structures comprise the implementation of the 62*4582Scth * queue structure that's used to construct the list of state 63*4582Scth * changes. Removals from the queue are blocking operations that 64*4582Scth * cause the thread to wait until new entries are added. 65*4582Scth */ 66*4582Scth struct q_node { 67*4582Scth void *data; 68*4582Scth struct q_node *next; 69*4582Scth }; 70*4582Scth 71*4582Scth typedef struct q_head { 72*4582Scth /* 73*4582Scth * Block On Empty (when queue is empty, the calling thread will be 74*4582Scth * blocked until something is added) 75*4582Scth */ 76*4582Scth boolean_t boe; 77*4582Scth pthread_mutex_t mutex; 78*4582Scth pthread_cond_t cvar; 79*4582Scth void *(*nalloc)(size_t); 80*4582Scth void (*nfree)(void *, size_t); 81*4582Scth void (*data_dealloc)(void *); 82*4582Scth struct q_node *nodep; 83*4582Scth } qu_t; 84*4582Scth 85*4582Scth typedef enum log_class { 86*4582Scth MM_CONF = 0x0001, 87*4582Scth MM_HPMGR = 0x0004, 88*4582Scth MM_SCHGMGR = 0x0008, 89*4582Scth MM_MAIN = 0x0040, 90*4582Scth MM_TOPO = 0x0100, 91*4582Scth MM_ERR = 0x0200, 92*4582Scth MM_WARN = 0x0400, 93*4582Scth MM_NOTE = 0x0800, 94*4582Scth MM_OTHER = 0x1000 95*4582Scth } log_class_t; 96*4582Scth 97*4582Scth extern void queue_add(qu_t *qp, void *data); 98*4582Scth extern void *queue_remove(qu_t *qp); 99*4582Scth extern qu_t *new_queue(boolean_t block_on_empty, void *(*nodealloc)(size_t), 100*4582Scth void (*nodefree)(void *, size_t), void (*deallocator)(void *)); 101*4582Scth extern void queue_free(qu_t **qp); 102*4582Scth 103*4582Scth extern void *dmalloc(size_t sz); 104*4582Scth extern void *dzmalloc(size_t sz); 105*4582Scth extern char *dstrdup(const char *s); 106*4582Scth extern void dfree(void *p, size_t sz); 107*4582Scth extern void dstrfree(char *s); 108*4582Scth 109*4582Scth extern void log_msg(log_class_t cl, const char *fmt, ...); 110*4582Scth extern void log_err(const char *fmt, ...); 111*4582Scth extern void log_warn(const char *fmt, ...); 112*4582Scth extern void log_warn_e(const char *fmt, ...); 113*4582Scth extern void vcont(log_class_t cl, const char *fmt, va_list val); 114*4582Scth 115*4582Scth #ifdef __cplusplus 116*4582Scth } 117*4582Scth #endif 118*4582Scth 119*4582Scth #endif /* _UTIL_H */ 120