btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / system / kernel / vm / PageCacheLocker.cpp
blob3352fc0b75f6d642464b0922d1307ff146843f75
1 /*
2 * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "PageCacheLocker.h"
9 #include <vm/VMCache.h>
12 bool
13 PageCacheLocker::_IgnorePage(vm_page* page)
15 if (page->busy || page->State() == PAGE_STATE_WIRED
16 || page->State() == PAGE_STATE_FREE || page->State() == PAGE_STATE_CLEAR
17 || page->State() == PAGE_STATE_UNUSED || page->WiredCount() > 0)
18 return true;
20 return false;
24 bool
25 PageCacheLocker::Lock(vm_page* page, bool dontWait)
27 if (_IgnorePage(page))
28 return false;
30 // Grab a reference to this cache.
31 VMCache* cache = vm_cache_acquire_locked_page_cache(page, dontWait);
32 if (cache == NULL)
33 return false;
35 if (_IgnorePage(page)) {
36 cache->ReleaseRefAndUnlock();
37 return false;
40 fPage = page;
41 return true;
45 void
46 PageCacheLocker::Unlock()
48 if (fPage == NULL)
49 return;
51 fPage->Cache()->ReleaseRefAndUnlock();
53 fPage = NULL;