00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef DB_LOCK_DEFAULT_N
00011 #define DB_LOCK_DEFAULT_N 1000
00012 #endif
00013
00014
00015
00016
00017
00018 #define LOCK_INVALID INVALID_ROFF
00019
00020
00021
00022
00023
00024
00025 #define DB_LOCK_MAXID 0x7fffffff
00026
00027
00028
00029
00030
00031 typedef struct __db_lockregion {
00032 u_int32_t id;
00033 u_int32_t need_dd;
00034 u_int32_t detect;
00035
00036 SH_TAILQ_HEAD(__flock) free_locks;
00037
00038 SH_TAILQ_HEAD(__fobj) free_objs;
00039
00040 SH_TAILQ_HEAD(__flocker) free_lockers;
00041 SH_TAILQ_HEAD(__dobj) dd_objs;
00042 u_int32_t maxlocks;
00043 u_int32_t table_size;
00044 u_int32_t nmodes;
00045 u_int32_t nlockers;
00046 u_int32_t maxnlockers;
00047 roff_t conf_off;
00048 roff_t obj_off;
00049 roff_t osynch_off;
00050 roff_t locker_off;
00051 roff_t lsynch_off;
00052 u_int32_t nconflicts;
00053 u_int32_t nrequests;
00054 u_int32_t nreleases;
00055 u_int32_t nnowaits;
00056
00057 u_int32_t ndeadlocks;
00058 } DB_LOCKREGION;
00059
00060
00061
00062
00063
00064 typedef struct __sh_dbt {
00065 u_int32_t size;
00066 ssize_t off;
00067 } SH_DBT;
00068
00069 #define SH_DBT_PTR(p) ((void *)(((u_int8_t *)(p)) + (p)->off))
00070
00071
00072
00073
00074 typedef struct __db_lockobj {
00075 SH_DBT lockobj;
00076 SH_TAILQ_ENTRY links;
00077 SH_TAILQ_ENTRY dd_links;
00078 SH_TAILQ_HEAD(__wait) waiters;
00079 SH_TAILQ_HEAD(__hold) holders;
00080
00081
00082
00083
00084 u_int8_t objdata[sizeof(struct __db_ilock)];
00085 } DB_LOCKOBJ;
00086
00087
00088
00089
00090 typedef struct __db_locker {
00091 u_int32_t id;
00092 u_int32_t dd_id;
00093 size_t master_locker;
00094 size_t parent_locker;
00095 SH_LIST_HEAD(_child) child_locker;
00096
00097
00098 SH_LIST_ENTRY child_link;
00099
00100
00101 SH_TAILQ_ENTRY links;
00102 SH_LIST_HEAD(_held) heldby;
00103
00104 #define DB_LOCKER_DELETED 0x0001
00105 u_int32_t flags;
00106 } DB_LOCKER;
00107
00108
00109
00110
00111
00112
00113 #define LOCKER_FREEABLE(lp) \
00114 ((lp)->master_locker == TXN_INVALID_ID && \
00115 SH_LIST_FIRST(&(lp)->child_locker, __db_locker) == NULL)
00116
00117
00118
00119
00120
00121
00122 typedef struct __db_locktab {
00123 DB_ENV *dbenv;
00124 REGINFO reginfo;
00125 u_int8_t *conflicts;
00126 DB_HASHTAB *obj_tab;
00127 DB_HASHTAB *locker_tab;
00128 } DB_LOCKTAB;
00129
00130
00131 #define CONFLICTS(T, R, HELD, WANTED) \
00132 (T)->conflicts[(HELD) * (R)->nmodes + (WANTED)]
00133
00134 #define OBJ_LINKS_VALID(L) ((L)->links.stqe_prev != -1)
00135
00136 struct __db_lock {
00137
00138
00139
00140
00141 MUTEX mutex;
00142
00143 u_int32_t holder;
00144 u_int32_t gen;
00145 SH_TAILQ_ENTRY links;
00146 SH_LIST_ENTRY locker_links;
00147 u_int32_t refcount;
00148 db_lockmode_t mode;
00149 ssize_t obj;
00150 db_status_t status;
00151 };
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 #define DB_LOCK_DOALL 0x001
00164 #define DB_LOCK_FREE 0x002
00165 #define DB_LOCK_IGNOREDEL 0x004
00166 #define DB_LOCK_NOPROMOTE 0x008
00167 #define DB_LOCK_UNLINK 0x010
00168
00169
00170
00171
00172 #define OBJECT_LOOKUP(lt, ndx, dbt, sh_obj) \
00173 HASHLOOKUP((lt)->objtab, \
00174 ndx, __db_lockobj, links, dbt, sh_obj, CDB___lock_cmp);
00175
00176 #define OBJECT_LOCK(lt, reg, obj, ndx) \
00177 ndx = CDB___lock_ohash(obj) % (reg)->table_size
00178 #define SHOBJECT_LOCK(lt, reg, shobj, ndx) \
00179 ndx = CDB___lock_lhash(shobj) % (reg)->table_size
00180 #define OBJECT_UNLOCK(lt, ndx)
00181
00182 #define LOCKER_LOOKUP(lt, ndx, locker, sh_locker) \
00183 HASHLOOKUP((lt)->lockertab, \
00184 ndx, __db_locker, links, locker, sh_locker, CDB___lock_locker_cmp);
00185
00186 #define LOCKREGION(dbenv, lt) R_LOCK((dbenv), &(lt)->reginfo)
00187 #define UNLOCKREGION(dbenv, lt) R_UNLOCK((dbenv), &(lt)->reginfo)
00188 #include "lock_ext.h"