mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-28 01:52:57 +01:00
Merge pull request #368 from Diggsey/master
Remove reimplementation of `LazyCell`
This commit is contained in:
commit
00c97504b6
@ -75,6 +75,7 @@ time = "0.1"
|
|||||||
encoding = "0.2"
|
encoding = "0.2"
|
||||||
language-tags = "0.2"
|
language-tags = "0.2"
|
||||||
lazy_static = "1.0"
|
lazy_static = "1.0"
|
||||||
|
lazycell = "1.0.0"
|
||||||
parking_lot = "0.6"
|
parking_lot = "0.6"
|
||||||
url = { version="1.7", features=["query_encoding"] }
|
url = { version="1.7", features=["query_encoding"] }
|
||||||
cookie = { version="0.10", features=["percent-encode"] }
|
cookie = { version="0.10", features=["percent-encode"] }
|
||||||
|
@ -107,6 +107,7 @@ extern crate htmlescape;
|
|||||||
extern crate http as modhttp;
|
extern crate http as modhttp;
|
||||||
extern crate httparse;
|
extern crate httparse;
|
||||||
extern crate language_tags;
|
extern crate language_tags;
|
||||||
|
extern crate lazycell;
|
||||||
extern crate mime;
|
extern crate mime;
|
||||||
extern crate mime_guess;
|
extern crate mime_guess;
|
||||||
extern crate mio;
|
extern crate mio;
|
||||||
|
@ -2,13 +2,14 @@ use std::cell::{Cell, RefCell, RefMut, UnsafeCell};
|
|||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::{env, fmt, mem, net};
|
use std::{env, fmt, net};
|
||||||
|
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use futures_cpupool::CpuPool;
|
use futures_cpupool::CpuPool;
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use time;
|
use time;
|
||||||
|
use lazycell::LazyCell;
|
||||||
|
|
||||||
use super::channel::Node;
|
use super::channel::Node;
|
||||||
use super::message::{Request, RequestPool};
|
use super::message::{Request, RequestPool};
|
||||||
@ -41,7 +42,7 @@ pub struct ServerSettings {
|
|||||||
addr: Option<net::SocketAddr>,
|
addr: Option<net::SocketAddr>,
|
||||||
secure: bool,
|
secure: bool,
|
||||||
host: String,
|
host: String,
|
||||||
cpu_pool: UnsafeCell<Option<CpuPool>>,
|
cpu_pool: LazyCell<CpuPool>,
|
||||||
responses: &'static HttpResponsePool,
|
responses: &'static HttpResponsePool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ impl Clone for ServerSettings {
|
|||||||
addr: self.addr,
|
addr: self.addr,
|
||||||
secure: self.secure,
|
secure: self.secure,
|
||||||
host: self.host.clone(),
|
host: self.host.clone(),
|
||||||
cpu_pool: UnsafeCell::new(None),
|
cpu_pool: LazyCell::new(),
|
||||||
responses: HttpResponsePool::get_pool(),
|
responses: HttpResponsePool::get_pool(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +65,7 @@ impl Default for ServerSettings {
|
|||||||
secure: false,
|
secure: false,
|
||||||
host: "localhost:8080".to_owned(),
|
host: "localhost:8080".to_owned(),
|
||||||
responses: HttpResponsePool::get_pool(),
|
responses: HttpResponsePool::get_pool(),
|
||||||
cpu_pool: UnsafeCell::new(None),
|
cpu_pool: LazyCell::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,7 +82,7 @@ impl ServerSettings {
|
|||||||
} else {
|
} else {
|
||||||
"localhost".to_owned()
|
"localhost".to_owned()
|
||||||
};
|
};
|
||||||
let cpu_pool = UnsafeCell::new(None);
|
let cpu_pool = LazyCell::new();
|
||||||
let responses = HttpResponsePool::get_pool();
|
let responses = HttpResponsePool::get_pool();
|
||||||
ServerSettings {
|
ServerSettings {
|
||||||
addr,
|
addr,
|
||||||
@ -102,7 +103,7 @@ impl ServerSettings {
|
|||||||
addr,
|
addr,
|
||||||
host,
|
host,
|
||||||
secure,
|
secure,
|
||||||
cpu_pool: UnsafeCell::new(None),
|
cpu_pool: LazyCell::new(),
|
||||||
responses: HttpResponsePool::get_pool(),
|
responses: HttpResponsePool::get_pool(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,15 +125,7 @@ impl ServerSettings {
|
|||||||
|
|
||||||
/// Returns default `CpuPool` for server
|
/// Returns default `CpuPool` for server
|
||||||
pub fn cpu_pool(&self) -> &CpuPool {
|
pub fn cpu_pool(&self) -> &CpuPool {
|
||||||
// Unsafe: ServerSetting is !Sync, DEFAULT_CPUPOOL is protected by Mutex
|
self.cpu_pool.borrow_with(|| DEFAULT_CPUPOOL.lock().clone())
|
||||||
unsafe {
|
|
||||||
let val = &mut *self.cpu_pool.get();
|
|
||||||
if val.is_none() {
|
|
||||||
let pool = DEFAULT_CPUPOOL.lock().clone();
|
|
||||||
*val = Some(pool);
|
|
||||||
}
|
|
||||||
val.as_ref().unwrap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -236,16 +229,15 @@ impl<H> WorkerSettings<H> {
|
|||||||
|
|
||||||
pub fn set_date(&self, dst: &mut BytesMut, full: bool) {
|
pub fn set_date(&self, dst: &mut BytesMut, full: bool) {
|
||||||
// Unsafe: WorkerSetting is !Sync and !Send
|
// Unsafe: WorkerSetting is !Sync and !Send
|
||||||
unsafe {
|
let date_bytes = unsafe { &(*self.date.get()).bytes };
|
||||||
if full {
|
if full {
|
||||||
let mut buf: [u8; 39] = mem::uninitialized();
|
let mut buf: [u8; 39] = [0; 39];
|
||||||
buf[..6].copy_from_slice(b"date: ");
|
buf[..6].copy_from_slice(b"date: ");
|
||||||
buf[6..35].copy_from_slice(&(*self.date.get()).bytes);
|
buf[6..35].copy_from_slice(date_bytes);
|
||||||
buf[35..].copy_from_slice(b"\r\n\r\n");
|
buf[35..].copy_from_slice(b"\r\n\r\n");
|
||||||
dst.extend_from_slice(&buf);
|
dst.extend_from_slice(&buf);
|
||||||
} else {
|
} else {
|
||||||
dst.extend_from_slice(&(*self.date.get()).bytes);
|
dst.extend_from_slice(date_bytes);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user