Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

mp_register.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: mp_register.c,v 12.6 2005/10/07 20:21:33 ubell Exp $
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  * memp_register_pp --
00023  *      DB_ENV->memp_register pre/post processing.
00024  *
00025  * PUBLIC: int __memp_register_pp __P((DB_ENV *, int,
00026  * PUBLIC:     int (*)(DB_ENV *, db_pgno_t, void *, DBT *),
00027  * PUBLIC:     int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
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  * memp_register --
00052  *      DB_ENV->memp_register.
00053  *
00054  * PUBLIC: int __memp_register __P((DB_ENV *, int,
00055  * PUBLIC:     int (*)(DB_ENV *, db_pgno_t, void *, DBT *),
00056  * PUBLIC:     int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
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          * We keep the DB pgin/pgout functions outside of the linked list
00073          * to avoid locking/unlocking the linked list on every page I/O.
00074          *
00075          * The Berkeley DB I/O conversion functions are registered when the
00076          * environment is first created, so there's no need for locking here.
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          * The item may already have been registered.  If already registered,
00092          * just update the entry, although it's probably unchanged.
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) {                    /* New entry. */
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 }

Generated on Sun Dec 25 12:14:41 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2