• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 use libc::c_void;
15 
16 use super::Qos;
17 
18 #[must_use]
19 /// Qos Interval.
20 pub struct QosInterval(*mut c_void);
21 
22 impl QosInterval {
23     /// Creates a new QosInterval.
new(deadline_us: u64, qos: Qos) -> Self24     pub fn new(deadline_us: u64, qos: Qos) -> Self {
25         unsafe {
26             let p = ffrt_qos_interval_create(deadline_us, qos);
27             ffrt_qos_interval_begin(p);
28             QosInterval(p)
29         }
30     }
31 
32     /// Updates the interval with a new deadline.
update(&mut self, new_deadline_us: u64)33     pub fn update(&mut self, new_deadline_us: u64) {
34         unsafe {
35             ffrt_qos_interval_update(self.0, new_deadline_us);
36         }
37     }
38 }
39 
40 impl Drop for QosInterval {
drop(&mut self)41     fn drop(&mut self) {
42         unsafe {
43             ffrt_qos_interval_end(self.0);
44             ffrt_qos_interval_destroy(self.0);
45         }
46     }
47 }
48 
49 unsafe impl Send for QosInterval {}
50 
51 #[link(name = "ffrt")]
52 // deadline.h
53 extern "C" {
ffrt_qos_interval_create(deadline_us: u64, qos: Qos) -> *mut c_void54     fn ffrt_qos_interval_create(deadline_us: u64, qos: Qos) -> *mut c_void;
ffrt_qos_interval_update(it: *mut c_void, new_deadline_us: u64)55     fn ffrt_qos_interval_update(it: *mut c_void, new_deadline_us: u64);
ffrt_qos_interval_begin(it: *mut c_void)56     fn ffrt_qos_interval_begin(it: *mut c_void);
ffrt_qos_interval_end(it: *mut c_void)57     fn ffrt_qos_interval_end(it: *mut c_void);
ffrt_qos_interval_destroy(it: *mut c_void)58     fn ffrt_qos_interval_destroy(it: *mut c_void);
59 }
60