00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "db_config.h"
00011
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 #endif
00015
00016 #include "db_int.h"
00017 #include "dbinc/db_shash.h"
00018 #include "dbinc/log.h"
00019 #include "dbinc/mp.h"
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 int
00030 __memp_register_pp(dbenv, ftype, pgin, pgout)
00031 DB_ENV *dbenv;
00032 int ftype;
00033 int (*pgin) __P((DB_ENV *, db_pgno_t, void *, DBT *));
00034 int (*pgout) __P((DB_ENV *, db_pgno_t, void *, DBT *));
00035 {
00036 DB_THREAD_INFO *ip;
00037 int ret;
00038
00039 PANIC_CHECK(dbenv);
00040 ENV_REQUIRES_CONFIG(dbenv,
00041 dbenv->mp_handle, "DB_ENV->memp_register", DB_INIT_MPOOL);
00042
00043 ENV_ENTER(dbenv, ip);
00044 REPLICATION_WRAP(dbenv,
00045 (__memp_register(dbenv, ftype, pgin, pgout)), ret);
00046 ENV_LEAVE(dbenv, ip);
00047 return (ret);
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 int
00059 __memp_register(dbenv, ftype, pgin, pgout)
00060 DB_ENV *dbenv;
00061 int ftype;
00062 int (*pgin) __P((DB_ENV *, db_pgno_t, void *, DBT *));
00063 int (*pgout) __P((DB_ENV *, db_pgno_t, void *, DBT *));
00064 {
00065 DB_MPOOL *dbmp;
00066 DB_MPREG *mpreg;
00067 int ret;
00068
00069 dbmp = dbenv->mp_handle;
00070
00071
00072
00073
00074
00075
00076
00077
00078 if (ftype == DB_FTYPE_SET) {
00079 if (dbmp->pg_inout != NULL)
00080 return (0);
00081 if ((ret =
00082 __os_malloc(dbenv, sizeof(DB_MPREG), &dbmp->pg_inout)) != 0)
00083 return (ret);
00084 dbmp->pg_inout->ftype = ftype;
00085 dbmp->pg_inout->pgin = pgin;
00086 dbmp->pg_inout->pgout = pgout;
00087 return (0);
00088 }
00089
00090
00091
00092
00093
00094 MUTEX_LOCK(dbenv, dbmp->mutex);
00095 for (mpreg = LIST_FIRST(&dbmp->dbregq);
00096 mpreg != NULL; mpreg = LIST_NEXT(mpreg, q))
00097 if (mpreg->ftype == ftype) {
00098 mpreg->pgin = pgin;
00099 mpreg->pgout = pgout;
00100 break;
00101 }
00102
00103 if (mpreg == NULL) {
00104 if ((ret = __os_malloc(dbenv, sizeof(DB_MPREG), &mpreg)) != 0)
00105 return (ret);
00106 mpreg->ftype = ftype;
00107 mpreg->pgin = pgin;
00108 mpreg->pgout = pgout;
00109
00110 LIST_INSERT_HEAD(&dbmp->dbregq, mpreg, q);
00111 }
00112 MUTEX_UNLOCK(dbenv, dbmp->mutex);
00113
00114 return (0);
00115 }