mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
BDB 4.1.24
This commit is contained in:
@ -1,20 +1,51 @@
|
||||
/*-
|
||||
* See the file LICENSE for redistribution information.
|
||||
*
|
||||
* Copyright (c) 1997, 1998, 1999, 2000
|
||||
* Copyright (c) 1997-2002
|
||||
* Sleepycat Software. All rights reserved.
|
||||
*/
|
||||
|
||||
#include "db_config.h"
|
||||
|
||||
#ifndef lint
|
||||
static const char revid[] = "$Id: cxx_mpool.cpp,v 11.11 2000/09/21 15:05:45 dda Exp $";
|
||||
static const char revid[] = "$Id: cxx_mpool.cpp,v 11.20 2002/07/03 21:03:53 bostic Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "db_cxx.h"
|
||||
#include "cxx_int.h"
|
||||
#include "dbinc/cxx_int.h"
|
||||
|
||||
#include "db_int.h"
|
||||
|
||||
// Helper macros for simple methods that pass through to the
|
||||
// underlying C method. It may return an error or raise an exception.
|
||||
// Note this macro expects that input _argspec is an argument
|
||||
// list element (e.g., "char *arg") and that _arglist is the arguments
|
||||
// that should be passed through to the C method (e.g., "(mpf, arg)")
|
||||
//
|
||||
#define DB_MPOOLFILE_METHOD(_name, _argspec, _arglist, _retok) \
|
||||
int DbMpoolFile::_name _argspec \
|
||||
{ \
|
||||
int ret; \
|
||||
DB_MPOOLFILE *mpf = unwrap(this); \
|
||||
\
|
||||
if (mpf == NULL) \
|
||||
ret = EINVAL; \
|
||||
else \
|
||||
ret = mpf->_name _arglist; \
|
||||
if (!_retok(ret)) \
|
||||
DB_ERROR("DbMpoolFile::"#_name, ret, ON_ERROR_UNKNOWN); \
|
||||
return (ret); \
|
||||
}
|
||||
|
||||
#define DB_MPOOLFILE_METHOD_VOID(_name, _argspec, _arglist) \
|
||||
void DbMpoolFile::_name _argspec \
|
||||
{ \
|
||||
DB_MPOOLFILE *mpf = unwrap(this); \
|
||||
\
|
||||
mpf->_name _arglist; \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
@ -31,150 +62,49 @@ DbMpoolFile::~DbMpoolFile()
|
||||
{
|
||||
}
|
||||
|
||||
int DbMpoolFile::open(DbEnv *envp, const char *file,
|
||||
u_int32_t flags, int mode, size_t pagesize,
|
||||
DB_MPOOL_FINFO *finfop, DbMpoolFile **result)
|
||||
{
|
||||
int err;
|
||||
|
||||
DB_MPOOLFILE *mpf;
|
||||
DB_ENV *env = unwrap(envp);
|
||||
|
||||
if ((err = ::memp_fopen(env, file, flags, mode, pagesize,
|
||||
finfop, &mpf)) != 0) {
|
||||
DB_ERROR("DbMpoolFile::open", err, envp->error_policy());
|
||||
return (err);
|
||||
}
|
||||
*result = new DbMpoolFile();
|
||||
(*result)->imp_ = wrap(mpf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int DbMpoolFile::close()
|
||||
int DbMpoolFile::close(u_int32_t flags)
|
||||
{
|
||||
DB_MPOOLFILE *mpf = unwrap(this);
|
||||
int err = 0;
|
||||
if (!mpf) {
|
||||
err = EINVAL;
|
||||
}
|
||||
else if ((err = ::memp_fclose(mpf)) != 0) {
|
||||
DB_ERROR("DbMpoolFile::close", err, ON_ERROR_UNKNOWN);
|
||||
return (err);
|
||||
}
|
||||
int ret;
|
||||
|
||||
if (mpf == NULL)
|
||||
ret = EINVAL;
|
||||
else
|
||||
ret = mpf->close(mpf, flags);
|
||||
|
||||
imp_ = 0; // extra safety
|
||||
|
||||
// This may seem weird, but is legal as long as we don't access
|
||||
// any data before returning.
|
||||
//
|
||||
delete this;
|
||||
return (0);
|
||||
|
||||
if (!DB_RETOK_STD(ret))
|
||||
DB_ERROR("DbMpoolFile::close", ret, ON_ERROR_UNKNOWN);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int DbMpoolFile::get(db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep)
|
||||
{
|
||||
DB_MPOOLFILE *mpf = unwrap(this);
|
||||
int err = 0;
|
||||
if (!mpf) {
|
||||
err = EINVAL;
|
||||
}
|
||||
else if ((err = ::memp_fget(mpf, pgnoaddr, flags, pagep)) != 0) {
|
||||
DB_ERROR("DbMpoolFile::get", err, ON_ERROR_UNKNOWN);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
int DbMpoolFile::put(void *pgaddr, u_int32_t flags)
|
||||
{
|
||||
DB_MPOOLFILE *mpf = unwrap(this);
|
||||
int err = 0;
|
||||
if (!mpf) {
|
||||
err = EINVAL;
|
||||
}
|
||||
else if ((err = ::memp_fput(mpf, pgaddr, flags)) != 0) {
|
||||
DB_ERROR("DbMpoolFile::put", err, ON_ERROR_UNKNOWN);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
int DbMpoolFile::set(void *pgaddr, u_int32_t flags)
|
||||
{
|
||||
DB_MPOOLFILE *mpf = unwrap(this);
|
||||
int err = 0;
|
||||
if (!mpf) {
|
||||
err = EINVAL;
|
||||
}
|
||||
else if ((err = ::memp_fset(mpf, pgaddr, flags)) != 0) {
|
||||
DB_ERROR("DbMpoolFile::set", err, ON_ERROR_UNKNOWN);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
int DbMpoolFile::sync()
|
||||
{
|
||||
DB_MPOOLFILE *mpf = unwrap(this);
|
||||
int err = 0;
|
||||
if (!mpf) {
|
||||
err = EINVAL;
|
||||
}
|
||||
else if ((err = ::memp_fsync(mpf)) != 0 && err != DB_INCOMPLETE) {
|
||||
DB_ERROR("DbMpoolFile::sync", err, ON_ERROR_UNKNOWN);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// DbMpool //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int DbEnv::memp_register(int ftype,
|
||||
pgin_fcn_type pgin_fcn,
|
||||
pgout_fcn_type pgout_fcn)
|
||||
{
|
||||
DB_ENV *env = unwrap(this);
|
||||
int err = 0;
|
||||
|
||||
if ((err = ::memp_register(env, ftype, pgin_fcn, pgout_fcn)) != 0) {
|
||||
DB_ERROR("DbEnv::memp_register", err, error_policy());
|
||||
return (err);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
int DbEnv::memp_stat(DB_MPOOL_STAT **gsp, DB_MPOOL_FSTAT ***fsp,
|
||||
db_malloc_fcn_type db_malloc_fcn)
|
||||
{
|
||||
DB_ENV *env = unwrap(this);
|
||||
int err = 0;
|
||||
|
||||
if ((err = ::memp_stat(env, gsp, fsp, db_malloc_fcn)) != 0) {
|
||||
DB_ERROR("DbEnv::memp_stat", err, error_policy());
|
||||
return (err);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
int DbEnv::memp_sync(DbLsn *sn)
|
||||
{
|
||||
DB_ENV *env = unwrap(this);
|
||||
int err = 0;
|
||||
|
||||
if ((err = ::memp_sync(env, sn)) != 0 && err != DB_INCOMPLETE) {
|
||||
DB_ERROR("DbEnv::memp_sync", err, error_policy());
|
||||
return (err);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
int DbEnv::memp_trickle(int pct, int *nwrotep)
|
||||
{
|
||||
DB_ENV *env = unwrap(this);
|
||||
int err = 0;
|
||||
|
||||
if ((err = ::memp_trickle(env, pct, nwrotep)) != 0) {
|
||||
DB_ERROR("DbEnv::memp_trickle", err, error_policy());
|
||||
return (err);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
DB_MPOOLFILE_METHOD(get, (db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep),
|
||||
(mpf, pgnoaddr, flags, pagep), DB_RETOK_MPGET)
|
||||
DB_MPOOLFILE_METHOD_VOID(last_pgno, (db_pgno_t *pgnoaddr), (mpf, pgnoaddr))
|
||||
DB_MPOOLFILE_METHOD(open,
|
||||
(const char *file, u_int32_t flags, int mode, size_t pagesize),
|
||||
(mpf, file, flags, mode, pagesize), DB_RETOK_STD)
|
||||
DB_MPOOLFILE_METHOD(put, (void *pgaddr, u_int32_t flags),
|
||||
(mpf, pgaddr, flags), DB_RETOK_STD)
|
||||
DB_MPOOLFILE_METHOD_VOID(refcnt, (db_pgno_t *pgnoaddr), (mpf, pgnoaddr))
|
||||
DB_MPOOLFILE_METHOD(set, (void *pgaddr, u_int32_t flags),
|
||||
(mpf, pgaddr, flags), DB_RETOK_STD)
|
||||
DB_MPOOLFILE_METHOD(set_clear_len, (u_int32_t len),
|
||||
(mpf, len), DB_RETOK_STD)
|
||||
DB_MPOOLFILE_METHOD(set_fileid, (u_int8_t *fileid),
|
||||
(mpf, fileid), DB_RETOK_STD)
|
||||
DB_MPOOLFILE_METHOD(set_ftype, (int ftype),
|
||||
(mpf, ftype), DB_RETOK_STD)
|
||||
DB_MPOOLFILE_METHOD(set_lsn_offset, (int32_t offset),
|
||||
(mpf, offset), DB_RETOK_STD)
|
||||
DB_MPOOLFILE_METHOD(set_pgcookie, (DBT *dbt),
|
||||
(mpf, dbt), DB_RETOK_STD)
|
||||
DB_MPOOLFILE_METHOD_VOID(set_unlink, (int ul), (mpf, ul))
|
||||
DB_MPOOLFILE_METHOD(sync, (),
|
||||
(mpf), DB_RETOK_STD)
|
||||
|
Reference in New Issue
Block a user