Mercurial > hg > openjdk > jigsaw > bdb
view src/mp/mp_fset.c @ 0:a1985f14b030
Initial load
author | chegar |
---|---|
date | Fri, 11 May 2012 10:42:02 +0100 |
parents | |
children |
line wrap: on
line source
/*- * See the file LICENSE for redistribution information. * * Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved. * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * * $Id$ */ #include "db_config.h" #include "db_int.h" #include "dbinc/log.h" #include "dbinc/mp.h" #include "dbinc/txn.h" /* * __memp_dirty -- * Upgrade a page from a read-only to a writable pointer. * * PUBLIC: int __memp_dirty __P((DB_MPOOLFILE *, void *, * PUBLIC: DB_THREAD_INFO *, DB_TXN *, DB_CACHE_PRIORITY, u_int32_t)); */ int __memp_dirty(dbmfp, addrp, ip, txn, priority, flags) DB_MPOOLFILE *dbmfp; void *addrp; DB_THREAD_INFO *ip; DB_TXN *txn; DB_CACHE_PRIORITY priority; u_int32_t flags; { BH *bhp; DB_MPOOL *dbmp; DB_MPOOL_HASH *hp; ENV *env; MPOOL *c_mp; REGINFO *infop; db_pgno_t pgno; void *pgaddr; env = dbmfp->env; dbmp = env->mp_handle; /* Convert the page address to a buffer header. */ pgaddr = *(void **)addrp; bhp = (BH *)((u_int8_t *)pgaddr - SSZA(BH, buf)); pgno = bhp->pgno; /* If we have it exclusively then its already dirty. */ if (F_ISSET(bhp, BH_EXCLUSIVE)) { DB_ASSERT(env, F_ISSET(bhp, BH_DIRTY)); return (0); } if (flags == 0) flags = DB_MPOOL_DIRTY; DB_ASSERT(env, flags == DB_MPOOL_DIRTY || flags == DB_MPOOL_EDIT); if (F_ISSET(dbmfp, MP_READONLY)) { __db_errx(env, DB_STR_A("3008", "%s: dirty flag set for readonly file page", "%s"), __memp_fn(dbmfp)); return (EACCES); } infop = &dbmp->reginfo[bhp->region]; c_mp = infop->primary; hp = R_ADDR(infop, c_mp->htab); hp = &hp[bhp->bucket]; /* Drop the shared latch and get an exclusive. We have the buf ref'ed.*/ MUTEX_UNLOCK(env, bhp->mtx_buf); MUTEX_LOCK(env, bhp->mtx_buf); DB_ASSERT(env, !F_ISSET(bhp, BH_EXCLUSIVE)); F_SET(bhp, BH_EXCLUSIVE); /* Set/clear the page bits. */ if (!F_ISSET(bhp, BH_DIRTY)) { #ifdef DIAGNOSTIC MUTEX_LOCK(env, hp->mtx_hash); #endif atomic_inc(env, &hp->hash_page_dirty); F_SET(bhp, BH_DIRTY); #ifdef DIAGNOSTIC MUTEX_UNLOCK(env, hp->mtx_hash); #endif } DB_ASSERT(env, !F_ISSET(bhp, BH_DIRTY) || atomic_read(&hp->hash_page_dirty) != 0); COMPQUIET(ip, NULL); COMPQUIET(txn, NULL); COMPQUIET(priority, 0); return (0); } /* * __memp_shared -- * Downgrade a page from exlusively held to shared. * * PUBLIC: int __memp_shared __P((DB_MPOOLFILE *, void *)); */ int __memp_shared(dbmfp, pgaddr) DB_MPOOLFILE *dbmfp; void *pgaddr; { BH *bhp; ENV *env; env = dbmfp->env; /* Convert the page address to a buffer header. */ bhp = (BH *)((u_int8_t *)pgaddr - SSZA(BH, buf)); if (F_ISSET(bhp, BH_DIRTY)) dbmfp->mfp->file_written = 1; DB_ASSERT(env, F_ISSET(bhp, BH_EXCLUSIVE)); F_CLR(bhp, BH_EXCLUSIVE); MUTEX_UNLOCK(env, bhp->mtx_buf); MUTEX_READLOCK(env, bhp->mtx_buf); return (0); }