1 /* 2 * BEGIN illumos section 3 * This is an unstable interface; changes may be made 4 * without notice. 5 * END illumos section 6 */ 7 /*********************************************************************** 8 * * 9 * This software is part of the ast package * 10 * Copyright (c) 1985-2011 AT&T Intellectual Property * 11 * and is licensed under the * 12 * Eclipse Public License, Version 1.0 * 13 * by AT&T Intellectual Property * 14 * * 15 * A copy of the License is available at * 16 * http://www.eclipse.org/org/documents/epl-v10.html * 17 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 18 * * 19 * Information and Software Systems Research * 20 * AT&T Research * 21 * Florham Park NJ * 22 * * 23 * Glenn Fowler <gsf@research.att.com> * 24 * David Korn <dgk@research.att.com> * 25 * Phong Vo <kpv@research.att.com> * 26 * * 27 ***********************************************************************/ 28 #ifndef _CDTLIB_H 29 #define _CDTLIB_H 1 30 31 /* cdt library/method implementation header 32 ** this header is exported to the method libraries 33 ** Written by Kiem-Phong Vo (5/25/96) 34 */ 35 36 #if _PACKAGE_ast 37 #include <ast.h> 38 #if !_BLD_cdt 39 #include <dlldefs.h> 40 #endif 41 #endif 42 43 #include <cdt.h> 44 #include <unistd.h> 45 #include <aso.h> 46 47 #include "debug.h" 48 49 /* short-hand notations */ 50 #define NIL(t) ((t)0) 51 #define reg register 52 53 /* min #bits for a hash table. (1<<this) is table size */ 54 #define DT_HTABLE 10 55 56 /* convenient types */ 57 #if !defined(uint) 58 #define uint unsigned int 59 #endif 60 #if !defined(uchar) 61 #define uchar unsigned char 62 #endif 63 64 /* This struct holds private method data created on DT_OPEN */ 65 struct _dtdata_s 66 { unsigned int lock; /* general dictionary lock */ 67 Dtuser_t user; /* application's data */ 68 unsigned int type; /* method type, control flags */ 69 ssize_t size; /* number of objects */ 70 Dt_t dict; /* when DT_INDATA is requested */ 71 }; 72 73 /* this structure holds the plugin information */ 74 typedef struct _dtlib_s 75 { 76 char* name; /* short name */ 77 char* description; /* short description */ 78 char* release; /* release info */ 79 char* prefix; /* name prefix */ 80 Dtmethod_t** methods; /* method list */ 81 } Dtlib_t; 82 83 #if _BLD_cdt 84 85 #if defined(__STDC__) 86 #define CDTLIB(m) __DEFINE__(Dtmethod_t*,m,&_##m); 87 #else 88 #define CDTLIB(m) __DEFINE__(Dtmethod_t*,m,&_/**/m); 89 #endif 90 91 #else 92 93 #if defined(__STDC__) 94 #define CDTLIB(m) \ 95 void* cdt_lib(const char* name, Dtdisc_t* disc, const char* type) \ 96 { \ 97 int i; \ 98 int n; \ 99 if (!type) \ 100 return &cdt_lib_##m; \ 101 n = strlen(cdt_lib_##m.prefix); \ 102 if (!strncmp(type, cdt_lib_##m.prefix, n)) \ 103 type += n; \ 104 for (i = 0; cdt_lib_##m.methods[i]; i++) \ 105 if (!strcmp(type, cdt_lib_##m.methods[i]->name + n)) \ 106 return cdt_lib_##m.methods[i]; \ 107 return 0; \ 108 } \ 109 unsigned long plugin_version(void) { return CDT_PLUGIN_VERSION; } 110 #else 111 #define CDTLIB(m) \ 112 void* cdt_lib(name, disc, type) const char* name; Dtdisc_t* disc; const char* type; \ 113 { \ 114 int i; \ 115 int n; \ 116 if (!type) \ 117 return &cdt_lib_/**/m; \ 118 n = strlen(cdt_lib_/**/m.prefix); \ 119 if (!strncmp(type, cdt_lib_/**/m.prefix, n)) \ 120 type += n; \ 121 for (i = 0; cdt_lib_/**/m.methods[i]; i++) \ 122 if (!strcmp(type, cdt_lib_/**/m.methods[i]->name + n)) \ 123 return cdt_lib_/**/m.methods[i]; \ 124 return 0; \ 125 } \ 126 unsigned long plugin_version() { return CDT_PLUGIN_VERSION; } 127 #endif 128 129 #endif /* _BLD_cdt */ 130 131 /* these macros lock/unlock dictionaries. DTRETURN substitutes for "return" */ 132 #define DTSETLOCK(dt) (((dt)->data->type&DT_SHARE) ? asolock(&(dt)->data->lock,1,ASO_SPINLOCK) : 0 ) 133 #define DTCLRLOCK(dt) (((dt)->data->type&DT_SHARE) ? asolock(&(dt)->data->lock,1,ASO_UNLOCK) : 0 ) 134 #define DTRETURN(ob,rv) do { (ob) = (rv); goto dt_return; } while(0) 135 #define DTERROR(dt, mesg) (!((dt)->disc && (dt)->disc->eventf) ? 0 : \ 136 (*(dt)->disc->eventf)((dt),DT_ERROR,(Void_t*)(mesg),(dt)->disc) ) 137 138 /* announce completion of an operation of type (ty) on some object (ob) in dictionary (dt) */ 139 #define DTANNOUNCE(dt,ob,ty) ( ((ob) && ((ty)&DT_TOANNOUNCE) && ((dt)->data->type&DT_ANNOUNCE) && \ 140 (dt)->disc && (dt)->disc->eventf ) ? \ 141 (*(dt)->disc->eventf)((dt), DT_ANNOUNCE|(ty), (ob), (dt)->disc) : 0 ) 142 143 /* map bits for upward compabitibility */ 144 #define DTTYPE(dt,ty) ((dt)->typef ? (*(dt)->typef)((dt), (ty)) : (ty) ) 145 146 /* short-hands for fields in Dtlink_t. 147 ** note that __hash is used as a hash value 148 ** or as the position in the parent table. 149 */ 150 #define _left lh.__left 151 #define _hash lh.__hash 152 #define _ppos lh.__hash 153 154 #define _rght rh.__rght 155 #define _ptbl rh.__ptbl 156 157 /* tree rotation/linking functions */ 158 #define rrotate(x,y) ((x)->_left = (y)->_rght, (y)->_rght = (x)) 159 #define lrotate(x,y) ((x)->_rght = (y)->_left, (y)->_left = (x)) 160 #define rlink(r,x) ((r) = (r)->_left = (x) ) 161 #define llink(l,x) ((l) = (l)->_rght = (x) ) 162 163 #define RROTATE(x,y) (rrotate(x,y), (x) = (y)) 164 #define LROTATE(x,y) (lrotate(x,y), (x) = (y)) 165 #define RRSHIFT(x,t) ((t) = (x)->_left->_left, (x)->_left->_left = (t)->_rght, \ 166 (t)->_rght = (x), (x) = (t) ) 167 #define LLSHIFT(x,t) ((t) = (x)->_rght->_rght, (x)->_rght->_rght = (t)->_left, \ 168 (t)->_left = (x), (x) = (t) ) 169 170 _BEGIN_EXTERNS_ 171 172 #if _BLD_cdt && defined(__EXPORT__) 173 #define extern __EXPORT__ 174 #endif 175 176 extern Dtlink_t* _dtmake _ARG_((Dt_t*, Void_t*, int)); 177 extern void _dtfree _ARG_((Dt_t*, Dtlink_t*, int)); 178 extern int _dtlock _ARG_((Dt_t*, int)); 179 180 #undef extern 181 182 #if !_PACKAGE_ast 183 extern Void_t* malloc _ARG_((size_t)); 184 extern Void_t* realloc _ARG_((Void_t*, size_t)); 185 extern void free _ARG_((Void_t*)); 186 #endif 187 _END_EXTERNS_ 188 189 #endif /* _CDTLIB_H */ 190