1 /*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1996, 1997, 1998, 1999, 2000
5 * Sleepycat Software. All rights reserved.
6 */
7 #include "config.h"
8
9 #ifndef lint
10 static const char revid[] = "$Id: mp_register.c,v 1.3 2000/06/28 16:47:02 loic Exp $";
11 #endif /* not lint */
12
13 #ifndef NO_SYSTEM_INCLUDES
14 #include <sys/types.h>
15 #endif
16
17 #ifdef HAVE_RPC
18 #include "db_server.h"
19 #endif
20
21 #include "db_int.h"
22 #include "db_shash.h"
23 #include "mp.h"
24
25 #ifdef HAVE_RPC
26 #include "gen_client_ext.h"
27 #include "rpc_client_ext.h"
28 #endif
29
30 /*
31 * CDB_memp_register --
32 * Register a file type's pgin, pgout routines.
33 */
34 int
CDB_memp_register(dbenv,ftype,pgin,pgout)35 CDB_memp_register(dbenv, ftype, pgin, pgout)
36 DB_ENV *dbenv;
37 int ftype;
38 int (*pgin) __P((DB_ENV *, db_pgno_t, void *, DBT *));
39 int (*pgout) __P((DB_ENV *, db_pgno_t, void *, DBT *));
40 {
41 DB_MPOOL *dbmp;
42 DB_MPREG *mpreg;
43 int ret;
44
45 #ifdef HAVE_RPC
46 if (F_ISSET(dbenv, DB_ENV_RPCCLIENT))
47 return (__dbcl_memp_register(dbenv, ftype, pgin, pgout));
48 #endif
49
50 PANIC_CHECK(dbenv);
51 ENV_REQUIRES_CONFIG(dbenv, dbenv->mp_handle, DB_INIT_MPOOL);
52
53 dbmp = dbenv->mp_handle;
54
55 /*
56 * Chances are good that the item has already been registered, as the
57 * DB access methods are the folks that call this routine. If already
58 * registered, just update the entry, although it's probably unchanged.
59 */
60 MUTEX_THREAD_LOCK(dbmp->mutexp);
61 for (mpreg = LIST_FIRST(&dbmp->dbregq);
62 mpreg != NULL; mpreg = LIST_NEXT(mpreg, q))
63 if (mpreg->ftype == ftype) {
64 mpreg->pgin = pgin;
65 mpreg->pgout = pgout;
66 break;
67 }
68 MUTEX_THREAD_UNLOCK(dbmp->mutexp);
69 if (mpreg != NULL)
70 return (0);
71
72 /* New entry. */
73 if ((ret = CDB___os_malloc(dbenv, sizeof(DB_MPREG), NULL, &mpreg)) != 0)
74 return (ret);
75
76 mpreg->ftype = ftype;
77 mpreg->pgin = pgin;
78 mpreg->pgout = pgout;
79
80 MUTEX_THREAD_LOCK(dbmp->mutexp);
81 LIST_INSERT_HEAD(&dbmp->dbregq, mpreg, q);
82 MUTEX_THREAD_UNLOCK(dbmp->mutexp);
83
84 return (0);
85 }
86