cxx_mpool.cpp 4.06 KB
Newer Older
1 2 3
/*-
 * See the file LICENSE for redistribution information.
 *
jimw@mysql.com's avatar
jimw@mysql.com committed
4
 * Copyright (c) 1997-2005
5
 *	Sleepycat Software.  All rights reserved.
jimw@mysql.com's avatar
jimw@mysql.com committed
6
 *
jimw@mysql.com's avatar
jimw@mysql.com committed
7
 * $Id: cxx_mpool.cpp,v 12.1 2005/06/16 20:21:02 bostic Exp $
8 9 10 11 12 13 14
 */

#include "db_config.h"

#include <errno.h>

#include "db_cxx.h"
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#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))						\
jimw@mysql.com's avatar
jimw@mysql.com committed
36 37
		DB_ERROR(DbEnv::get_DbEnv(mpf->dbenv), \
			"DbMpoolFile::"#_name, ret, ON_ERROR_UNKNOWN);	\
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
38 39 40 41 42 43 44 45 46 47
	return (ret);							\
}

#define	DB_MPOOLFILE_METHOD_VOID(_name, _argspec, _arglist)		\
void DbMpoolFile::_name _argspec					\
{									\
	DB_MPOOLFILE *mpf = unwrap(this);				\
									\
	mpf->_name _arglist;						\
}
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

////////////////////////////////////////////////////////////////////////
//                                                                    //
//                            DbMpoolFile                             //
//                                                                    //
////////////////////////////////////////////////////////////////////////

DbMpoolFile::DbMpoolFile()
:	imp_(0)
{
}

DbMpoolFile::~DbMpoolFile()
{
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
64
int DbMpoolFile::close(u_int32_t flags)
65 66
{
	DB_MPOOLFILE *mpf = unwrap(this);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
67
	int ret;
jimw@mysql.com's avatar
jimw@mysql.com committed
68
	DbEnv *dbenv = DbEnv::get_DbEnv(mpf->dbenv);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
69 70 71 72 73 74

	if (mpf == NULL)
		ret = EINVAL;
	else
		ret = mpf->close(mpf, flags);

75 76 77 78 79 80
	imp_ = 0;                   // extra safety

	// This may seem weird, but is legal as long as we don't access
	// any data before returning.
	delete this;

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
81
	if (!DB_RETOK_STD(ret))
jimw@mysql.com's avatar
jimw@mysql.com committed
82
		DB_ERROR(dbenv, "DbMpoolFile::close", ret, ON_ERROR_UNKNOWN);
83

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
84
	return (ret);
85 86
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
87 88 89 90 91 92 93 94 95
DB_MPOOLFILE_METHOD(get, (db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep),
    (mpf, pgnoaddr, flags, pagep), DB_RETOK_MPGET)
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(set, (void *pgaddr, u_int32_t flags),
    (mpf, pgaddr, flags), DB_RETOK_STD)
jimw@mysql.com's avatar
jimw@mysql.com committed
96 97
DB_MPOOLFILE_METHOD(get_clear_len, (u_int32_t *lenp),
    (mpf, lenp), DB_RETOK_STD)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
98 99
DB_MPOOLFILE_METHOD(set_clear_len, (u_int32_t len),
    (mpf, len), DB_RETOK_STD)
jimw@mysql.com's avatar
jimw@mysql.com committed
100 101
DB_MPOOLFILE_METHOD(get_fileid, (u_int8_t *fileid),
    (mpf, fileid), DB_RETOK_STD)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
102 103
DB_MPOOLFILE_METHOD(set_fileid, (u_int8_t *fileid),
    (mpf, fileid), DB_RETOK_STD)
jimw@mysql.com's avatar
jimw@mysql.com committed
104 105 106 107 108 109
DB_MPOOLFILE_METHOD(get_flags, (u_int32_t *flagsp),
    (mpf, flagsp), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(set_flags, (u_int32_t flags, int onoff),
    (mpf, flags, onoff), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(get_ftype, (int *ftypep),
    (mpf, ftypep), DB_RETOK_STD)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
110 111
DB_MPOOLFILE_METHOD(set_ftype, (int ftype),
    (mpf, ftype), DB_RETOK_STD)
jimw@mysql.com's avatar
jimw@mysql.com committed
112 113
DB_MPOOLFILE_METHOD(get_lsn_offset, (int32_t *offsetp),
    (mpf, offsetp), DB_RETOK_STD)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
114 115
DB_MPOOLFILE_METHOD(set_lsn_offset, (int32_t offset),
    (mpf, offset), DB_RETOK_STD)
jimw@mysql.com's avatar
jimw@mysql.com committed
116 117 118 119 120 121
DB_MPOOLFILE_METHOD(get_maxsize, (u_int32_t *gbytesp, u_int32_t *bytesp),
    (mpf, gbytesp, bytesp), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(set_maxsize, (u_int32_t gbytes, u_int32_t bytes),
    (mpf, gbytes, bytes), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(get_pgcookie, (DBT *dbt),
    (mpf, dbt), DB_RETOK_STD)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
122 123
DB_MPOOLFILE_METHOD(set_pgcookie, (DBT *dbt),
    (mpf, dbt), DB_RETOK_STD)
jimw@mysql.com's avatar
jimw@mysql.com committed
124 125 126 127
DB_MPOOLFILE_METHOD(get_priority, (DB_CACHE_PRIORITY *priorityp),
    (mpf, priorityp), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(set_priority, (DB_CACHE_PRIORITY priority),
    (mpf, priority), DB_RETOK_STD)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
128 129
DB_MPOOLFILE_METHOD(sync, (),
    (mpf), DB_RETOK_STD)