1 // Copyright 2018 The Fuchsia Authors
2 //
3 // Use of this source code is governed by a MIT-style
4 // license that can be found in the LICENSE file or at
5 // https://opensource.org/licenses/MIT
6 
7 #include <fbl/auto_lock.h>
8 #include <trace.h>
9 #include <vm/page_source.h>
10 
11 #define LOCAL_TRACE 0
12 
PageSource(PageSourceCallback * callback,uint64_t page_source_id)13 PageSource::PageSource(PageSourceCallback* callback, uint64_t page_source_id)
14         : callback_(callback), page_source_id_(page_source_id) {
15     LTRACEF("%p callback %p\n", this, callback_);
16 }
17 
~PageSource()18 PageSource::~PageSource() {
19     LTRACEF("%p\n", this);
20     DEBUG_ASSERT(closed_);
21 }
22 
Close()23 void PageSource::Close() {
24     fbl::AutoLock info_lock(&mtx_);
25     LTRACEF("%p\n", this);
26 
27     if (!closed_) {
28         closed_ = true;
29         callback_->OnClose();
30     }
31 }
32