mp_register.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996, 1997, 1998, 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 #include "config.h"
00008 
00009 #ifndef lint
00010 static const char revid[] = "$Id: mp__register_8c-source.html,v 1.1 2008/06/08 10:20:50 sebdiaz Exp $";
00011 #endif /* not lint */
00012 
00013 #ifndef NO_SYSTEM_INCLUDES
00014 #include <sys/types.h>
00015 #endif
00016 
00017 #ifdef  HAVE_RPC
00018 #include "db_server.h"
00019 #endif
00020 
00021 #include "db_int.h"
00022 #include "db_shash.h"
00023 #include "mp.h"
00024 
00025 #ifdef HAVE_RPC
00026 #include "gen_client_ext.h"
00027 #include "rpc_client_ext.h"
00028 #endif
00029 
00030 /*
00031  * CDB_memp_register --
00032  *      Register a file type's pgin, pgout routines.
00033  */
00034 int
00035 CDB_memp_register(dbenv, ftype, pgin, pgout)
00036         DB_ENV *dbenv;
00037         int ftype;
00038         int (*pgin) __P((DB_ENV *, db_pgno_t, void *, DBT *));
00039         int (*pgout) __P((DB_ENV *, db_pgno_t, void *, DBT *));
00040 {
00041         DB_MPOOL *dbmp;
00042         DB_MPREG *mpreg;
00043         int ret;
00044 
00045 #ifdef HAVE_RPC
00046         if (F_ISSET(dbenv, DB_ENV_RPCCLIENT))
00047                 return (__dbcl_memp_register(dbenv, ftype, pgin, pgout));
00048 #endif
00049 
00050         PANIC_CHECK(dbenv);
00051         ENV_REQUIRES_CONFIG(dbenv, dbenv->mp_handle, DB_INIT_MPOOL);
00052 
00053         dbmp = dbenv->mp_handle;
00054 
00055         /*
00056          * Chances are good that the item has already been registered, as the
00057          * DB access methods are the folks that call this routine.  If already
00058          * registered, just update the entry, although it's probably unchanged.
00059          */
00060         MUTEX_THREAD_LOCK(dbmp->mutexp);
00061         for (mpreg = LIST_FIRST(&dbmp->dbregq);
00062             mpreg != NULL; mpreg = LIST_NEXT(mpreg, q))
00063                 if (mpreg->ftype == ftype) {
00064                         mpreg->pgin = pgin;
00065                         mpreg->pgout = pgout;
00066                         break;
00067                 }
00068         MUTEX_THREAD_UNLOCK(dbmp->mutexp);
00069         if (mpreg != NULL)
00070                 return (0);
00071 
00072         /* New entry. */
00073         if ((ret = CDB___os_malloc(dbenv, sizeof(DB_MPREG), NULL, &mpreg)) != 0)
00074                 return (ret);
00075 
00076         mpreg->ftype = ftype;
00077         mpreg->pgin = pgin;
00078         mpreg->pgout = pgout;
00079 
00080         MUTEX_THREAD_LOCK(dbmp->mutexp);
00081         LIST_INSERT_HEAD(&dbmp->dbregq, mpreg, q);
00082         MUTEX_THREAD_UNLOCK(dbmp->mutexp);
00083 
00084         return (0);
00085 }

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by  doxygen 1.5.5