Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Commit 8328612

Browse files
committed
async rwlock
1 parent 4003031 commit 8328612

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/cameras.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
//! Camera management
22
3-
use std::sync::RwLock;
4-
53
use tokio::fs;
4+
use tokio::sync::RwLock;
65

76
use actix_web::HttpResponse;
87
use actix_web::http::{StatusCode};
98
use actix_web::web::{self, Data, Json, ServiceConfig};
109

1110
use awc::Client;
1211
use diesel::prelude::*;
13-
use log::{debug, info, trace, warn};
12+
use log::{debug, info, trace};
1413
use serde::{Deserialize, Serialize};
1514
use tera::{Context, Tera};
1615

17-
use crate::do_write;
1816
use crate::db::{ConnectionPool, PooledConnection};
1917
use crate::db::schema::cameras;
2018
use crate::error::{Error, Result};
@@ -296,7 +294,9 @@ async fn patch_camera(
296294
assert!(cfg!(feature = "stream"));
297295
debug!("updating local stream settings");
298296
#[cfg(feature = "stream")]
299-
do_write!(stream).update(&new_stream, &conn, &templates)
297+
stream.write()
298+
.await
299+
.update(&new_stream, &conn, &templates)
300300
.await?;
301301
} else {
302302
debug!("sending new stream settings to {}", camera.address);

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ mod users;
2020

2121
use std::env;
2222
use std::mem;
23-
use std::sync::RwLock;
2423

2524
use actix_files::Files;
2625
use actix_web::{App, HttpServer};
2726
use actix_web::web::{self, Data};
2827
use env_logger::Env;
2928
use log::{debug, trace};
3029
use tera::Tera;
30+
use tokio::sync::RwLock;
3131

3232
use crate::error::Result;
3333

src/stream.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::env;
99
use std::fs;
1010
use std::io::Write;
1111
use std::process::{Command, Stdio};
12-
use std::sync::RwLock;
1312

1413
use actix_web::web::{self, Data, Json, ServiceConfig};
1514
use diesel::backend::Backend;
@@ -20,8 +19,8 @@ use log::{debug, trace};
2019
use rand::Rng;
2120
use serde::{Deserialize, Serialize};
2221
use tera::{Context, Tera};
22+
use tokio::sync::RwLock;
2323

24-
use crate::{do_read, do_write};
2524
use crate::error::Result;
2625
use crate::db::{ConnectionPool, PooledConnection};
2726
use crate::prochost::ProcHost;
@@ -310,9 +309,11 @@ async fn get_stream(
310309
stream: Data<RwLock<Stream>>,
311310
) -> Result<Json<StreamState>> {
312311

313-
let stream = do_read!(stream);
312+
let state = stream.read()
313+
.await
314+
.state();
314315

315-
Ok(Json(stream.state()))
316+
Ok(Json(state))
316317
}
317318

318319

@@ -324,9 +325,10 @@ async fn patch_stream(
324325
body: Json<StreamUpdate>,
325326
) -> Result<Json<StreamState>> {
326327

327-
let mut stream = do_write!(stream);
328328
let conn = pool.get()?;
329329

330+
let mut stream = stream.write()
331+
.await;
330332
stream.update(&body, &conn, &templates)
331333
.await?;
332334

0 commit comments

Comments
 (0)