Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. extern crate libc;
  2. extern crate num_cpus;
  3.  
  4. use libc::{c_char, size_t};
  5. use std::thread;
  6. use std::fs::copy;
  7.  
  8. fn python_str_array_2_str_vec<T, U, V>(_: T, _: U) -> V {
  9. unimplemented!()
  10. }
  11.  
  12. #[no_mangle]
  13. pub extern "C" fn copyFiles(
  14. sources: *const *const c_char,
  15. destinies: *const *const c_char,
  16. array_len: size_t,
  17. ) {
  18. let src: Vec<&str> = python_str_array_2_str_vec(sources, array_len);
  19. let dst: Vec<&str> = python_str_array_2_str_vec(destinies, array_len);
  20. let mut iter = src.iter().zip(dst);
  21. let num_threads = num_cpus::get();
  22. let threads = (0..num_threads).map(|_| {
  23. thread::spawn(|| while let Some((s, d)) = iter.next() {
  24. copy(s, d);
  25. })
  26. });
  27. for t in threads {
  28. t.join();
  29. }
  30. }
  31.  
  32. fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement