forked from xinyu391/zircon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suspend_token_dispatcher.cpp
41 lines (32 loc) · 1.25 KB
/
suspend_token_dispatcher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2018 The Fuchsia Authors
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#include <object/suspend_token_dispatcher.h>
#include <err.h>
#include <kernel/auto_lock.h>
#include <object/thread_dispatcher.h>
#include <zircon/rights.h>
#include <fbl/alloc_checker.h>
zx_status_t SuspendTokenDispatcher::Create(fbl::RefPtr<ThreadDispatcher> thread,
fbl::RefPtr<Dispatcher>* dispatcher,
zx_rights_t* rights) {
fbl::AllocChecker ac;
fbl::unique_ptr<SuspendTokenDispatcher> disp(
new (&ac) SuspendTokenDispatcher(fbl::move(thread)));
if (!ac.check())
return ZX_ERR_NO_MEMORY;
zx_status_t status = disp->thread_->Suspend();
if (status != ZX_OK)
return ZX_ERR_BAD_STATE;
*rights = default_rights();
*dispatcher = fbl::AdoptRef<Dispatcher>(disp.release());
return ZX_OK;
}
SuspendTokenDispatcher::SuspendTokenDispatcher(fbl::RefPtr<ThreadDispatcher> thread)
: thread_(fbl::move(thread)) {}
SuspendTokenDispatcher::~SuspendTokenDispatcher() {}
void SuspendTokenDispatcher::on_zero_handles() {
thread_->Resume();
}