Advertisement
Guest User

enqueue() - Rust

a guest
Apr 8th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.26 KB | None | 0 0
  1. mod bindings;
  2. use bindings::*;
  3.  
  4. pub fn enqueue(rp: *mut proc) {
  5.     let q: i32 = rp.p_priority;
  6.     let rdy_head: *mut proc;
  7.     let rdy_tail: *mut proc;
  8.  
  9.     // assert!(proc_is_runnable(rp));
  10.  
  11.     // assert!(q > 0);
  12.  
  13.     rdy_head = get_cpu_var(rp.p_cpu, run_q_head);
  14.     rdy_tail = get_cpu_var(rp.p_cpu, run_q_tail);
  15.  
  16.     // Now add the process to the queue
  17.     if !rdy_head[&q] {
  18.         rdy_head[&q] = rdy_tail[q] = rp;
  19.         //rp.p_nextready = std::ptr::null();
  20.     }
  21.     else {
  22.         rdy_tail[&q].p_nextready = rp;
  23.         rdy_tail[&q] = rp;
  24.         //rp.p_nextready = std::ptr::null();
  25.     }
  26.  
  27.      /*
  28.      * enqueueing a process with a higher priority than the current one,
  29.      * it gets preempted. The current process must be preemptible. Testing
  30.      * the priority also makes sure that a process does not preempt itself
  31.      */
  32.  
  33.     if cpuid == rp.p_cpu {
  34.         let p: *mut proc;
  35.         p = get_cpulocal_var(proc_ptr);
  36.         assert!(p);
  37.  
  38.         if (p.p_priority > rp.p_priority) && p.s_flags & PREEMPTIBLE {
  39.             RTS_SET(p, RTS_PREEMPTED);
  40.         }
  41.  
  42.     }
  43.     else if get_cpu_var(rp.p_cpu, cpu_is_idle) {
  44.         smp_schedule(rp.p_cpu);
  45.     }
  46.  
  47.     read_tsc_64(&(get_cpulocal_var(proc_ptr).p_accounting.enter_queue));
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement