Removed unecessary locks

This commit is contained in:
Antoine Gersant 2016-10-23 15:34:12 -07:00
parent 7b3e0cfaef
commit 88a4142aa5
2 changed files with 6 additions and 12 deletions

View file

@ -4,7 +4,6 @@ use std::io;
use std::path::*;
use std::ops::Deref;
use std::sync::Arc;
use std::sync::Mutex;
use iron::prelude::*;
use iron::headers::CookiePair;
@ -46,14 +45,13 @@ impl From<PError> for IronError {
}
}
pub fn get_api_handler(collection: Arc<Mutex<Collection>>) -> Mount {
pub fn get_api_handler(collection: Arc<Collection>) -> Mount {
let mut api_handler = Mount::new();
{
let collection = collection.clone();
api_handler.mount("/auth/", move |request: &mut Request| {
let acquired_collection = collection.deref().lock().unwrap();
self::auth(request, acquired_collection.deref())
self::auth(request, collection.deref())
});
}
@ -62,22 +60,19 @@ pub fn get_api_handler(collection: Arc<Mutex<Collection>>) -> Mount {
{
let collection = collection.clone();
auth_api_mount.mount("/browse/", move |request: &mut Request| {
let acquired_collection = collection.deref().lock().unwrap();
self::browse(request, acquired_collection.deref())
self::browse(request, collection.deref())
});
}
{
let collection = collection.clone();
auth_api_mount.mount("/flatten/", move |request: &mut Request| {
let acquired_collection = collection.deref().lock().unwrap();
self::flatten(request, acquired_collection.deref())
self::flatten(request, collection.deref())
});
}
{
let collection = collection.clone();
auth_api_mount.mount("/serve/", move |request: &mut Request| {
let acquired_collection = collection.deref().lock().unwrap();
self::serve(request, acquired_collection.deref())
self::serve(request, collection.deref())
});
}

View file

@ -30,7 +30,6 @@ use mount::Mount;
use staticfile::Static;
use std::path;
use std::sync::Arc;
use std::sync::Mutex;
mod api;
mod collection;
@ -69,7 +68,7 @@ fn main() {
{
let mut collection = collection::Collection::new();
collection.load_config(&config).unwrap();
let collection = Arc::new(Mutex::new(collection));
let collection = Arc::new(collection);
api_handler = api::get_api_handler(collection);
}
api_chain = Chain::new(api_handler);