100
101
DbTable* tb, /* [in out] */
103
int (*db_put)(Process* p,
104
DbTable* tb, /* [in out] */
104
int (*db_put)(DbTable* tb, /* [in out] */
106
int key_clash_fail); /* DB_ERROR_BADKEY if key exists */
107
107
int (*db_get)(Process* p,
108
108
DbTable* tb, /* [in out] */
116
int (*db_member)(Process* p,
117
DbTable* tb, /* [in out] */
116
int (*db_member)(DbTable* tb, /* [in out] */
120
int (*db_erase)(Process* p,
121
DbTable* tb, /* [in out] */
119
int (*db_erase)(DbTable* tb, /* [in out] */
124
int (*db_erase_object)(Process* p,
125
DbTable* tb, /* [in out] */
122
int (*db_erase_object)(DbTable* tb, /* [in out] */
128
125
int (*db_slot)(Process* p,
133
130
DbTable* tb, /* [in out] */
138
135
int (*db_select)(Process* p,
139
136
DbTable* tb, /* [in out] */
143
140
int (*db_select_delete)(Process* p,
144
141
DbTable* tb, /* [in out] */
165
162
DbTable* db /* [in out] */ );
167
164
int (*db_free_table)(DbTable* db /* [in out] */ );
168
int (*db_free_table_continue)(DbTable* db, /* [in out] */
165
int (*db_free_table_continue)(DbTable* db); /* [in out] */
171
167
void (*db_print)(int to,
179
175
void (*db_check_table)(DbTable* tb);
181
/* Allocate and replace a dbterm with a new size.
182
* The new DbTerm must be initialized by caller (from the old).
184
DbTerm* (*db_alloc_newsize)(DbTable* tb,
185
void** bp, /* XxxDbTerm** */
188
/* Free a dbterm not in table.
190
void (*db_free_dbterm)(DbTable* tb, DbTerm* bp);
192
/* Lookup a dbterm by key. Return false if not found.
177
/* Lookup a dbterm for updating. Return false if not found.
194
179
int (*db_lookup_dbterm)(DbTable*, Eterm key,
195
180
DbUpdateHandle* handle); /* [out] */
182
/* Must be called for each db_lookup_dbterm that returned true,
183
** even if dbterm was not updated.
185
void (*db_finalize_dbterm)(DbUpdateHandle* handle);
214
204
typedef struct db_table_common {
215
erts_refc_t ref; /* ref count ro prevent table deletion */
206
erts_refc_t fixref; /* fixation counter */
217
208
erts_smp_rwmtx_t rwlock; /* rw lock on table */
218
Uint32 type; /* hash or tree; *read only* after creation */
209
erts_smp_mtx_t fixlock; /* Protects fixations,megasec,sec,microsec */
210
int is_thread_safe; /* No fine locking inside table needed */
211
Uint32 type; /* hash or tree, private or not; *read only* after creation */
220
213
Eterm owner; /* Pid of the creator */
221
Eterm the_name; /* an atom */
214
Eterm heir; /* Pid of the heir */
215
Eterm heir_data; /* To send in ETS-TRANSFER (is_immed or (DbTerm*) */
216
SysTimeval heir_started; /* To further identify the heir */
217
Eterm the_name; /* an atom */
222
218
Eterm id; /* atom | integer */
223
219
DbTableMethod* meth; /* table methods */
224
Uint nitems; /* Total number of items */
220
erts_smp_atomic_t nitems; /* Total number of items in table */
225
221
erts_smp_atomic_t memory_size;/* Total memory size. NOTE: in bytes! */
226
222
Uint megasec,sec,microsec; /* Last fixation time */
227
DbFixation *fixations; /* List of processes who have fixed
223
DbFixation* fixations; /* List of processes who have done safe_fixtable,
224
"local" fixations not included. */
230
225
/* All 32-bit fields */
231
226
Uint32 status; /* bit masks defined below */
232
227
int slot; /* slot index in meta_main_tab */
233
228
int keypos; /* defaults to 1 */
234
int kept_items; /* Number of kept elements due to fixation */
237
231
/* These are status bit patterns */
241
235
#define DB_PUBLIC (1 << 3)
242
236
#define DB_BAG (1 << 4)
243
237
#define DB_SET (1 << 5)
244
#define DB_LHASH (1 << 6) /* not really used!!! */
245
#define DB_FIXED (1 << 7)
238
/*#define DB_LHASH (1 << 6)*/
239
#define DB_FINE_LOCKED (1 << 7) /* fine grained locking enabled */
246
240
#define DB_DUPLICATE_BAG (1 << 8)
247
241
#define DB_ORDERED_SET (1 << 9)
248
242
#define DB_DELETE (1 << 10) /* table is being deleted */
250
#define ERTS_ETS_TABLE_TYPES (DB_BAG|DB_SET|DB_DUPLICATE_BAG|DB_ORDERED_SET)
244
#define ERTS_ETS_TABLE_TYPES (DB_BAG|DB_SET|DB_DUPLICATE_BAG|DB_ORDERED_SET|DB_PRIVATE|DB_FINE_LOCKED)
252
246
#define IS_HASH_TABLE(Status) (!!((Status) & \
253
247
(DB_BAG | DB_SET | DB_DUPLICATE_BAG)))
254
248
#define IS_TREE_TABLE(Status) (!!((Status) & \
250
#define NFIXED(T) (erts_refc_read(&(T)->common.fixref,0))
251
#define IS_FIXED(T) (NFIXED(T) != 0)
258
253
Eterm erts_ets_copy_object(Eterm, Process*);
269
264
/* tb is an DbTableCommon and obj is an Eterm (tagged) */
270
265
#define TERM_GETKEY(tb, obj) db_getkey((tb)->common.keypos, (obj))
272
#define ONLY_WRITER(P,T) (((T)->common.status & DB_PRIVATE) || \
273
(((T)->common.status & DB_PROTECTED) && (T)->common.owner == (P)->id))
267
#define ONLY_WRITER(P,T) (((T)->common.status & (DB_PRIVATE|DB_PROTECTED)) \
268
&& (T)->common.owner == (P)->id)
275
270
#define ONLY_READER(P,T) (((T)->common.status & DB_PRIVATE) && \
276
271
(T)->common.owner == (P)->id)
278
#define SOLE_LOCKER(P,Fixations) ((Fixations) != NULL && \
279
(Fixations)->next == NULL && (Fixations)->pid == (P)->id && \
280
(Fixations)->counter == 1)
282
273
/* Function prototypes */
283
274
Eterm db_get_trace_control_word_0(Process *p);
284
275
Eterm db_set_trace_control_word_1(Process *p, Eterm val);