avoid inbox jobs_needed flag

This commit is contained in:
holger krekel
2019-12-06 01:36:07 +01:00
parent b3495695d0
commit 7c3fc251ff
3 changed files with 13 additions and 28 deletions

View File

@@ -44,7 +44,6 @@ pub struct Context {
/// Blob directory path
blobdir: PathBuf,
pub sql: Sql,
pub perform_inbox_jobs_needed: Arc<RwLock<bool>>,
pub probe_imap_network: Arc<RwLock<bool>>,
pub inbox_thread: Arc<RwLock<JobThread>>,
pub sentbox_thread: Arc<RwLock<JobThread>>,
@@ -147,7 +146,6 @@ impl Context {
Imap::new(),
))),
probe_imap_network: Arc::new(RwLock::new(false)),
perform_inbox_jobs_needed: Arc::new(RwLock::new(false)),
generating_key_mutex: Mutex::new(()),
translated_stockstrings: RwLock::new(HashMap::new()),
};

View File

@@ -35,7 +35,7 @@ const JOB_RETRIES: u32 = 17;
/// Thread IDs
#[derive(Debug, Display, Copy, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql)]
#[repr(i32)]
enum Thread {
pub enum Thread {
Unknown = 0,
Imap = 100,
Smtp = 5000,
@@ -436,13 +436,6 @@ pub fn perform_sentbox_fetch(context: &Context) {
}
pub fn perform_inbox_idle(context: &Context) {
if *context.perform_inbox_jobs_needed.clone().read().unwrap() {
info!(
context,
"INBOX-IDLE will not be started because of waiting jobs."
);
return;
}
let use_network = context.get_config_bool(Config::InboxWatch);
context
@@ -552,7 +545,7 @@ pub fn perform_smtp_idle(context: &Context) {
info!(context, "SMTP-idle ended.",);
}
fn get_next_wakeup_time(context: &Context, thread: Thread) -> Duration {
pub(crate) fn get_next_wakeup_time(context: &Context, thread: Thread) -> Duration {
let t: i64 = context
.sql
.query_get_value(
@@ -704,7 +697,6 @@ pub fn perform_inbox_jobs(context: &Context) {
let probe_imap_network = *context.probe_imap_network.clone().read().unwrap();
*context.probe_imap_network.write().unwrap() = false;
*context.perform_inbox_jobs_needed.write().unwrap() = false;
job_perform(context, Thread::Imap, probe_imap_network);
info!(context, "dc_perform_inbox_jobs ended.",);
@@ -951,10 +943,6 @@ pub fn add_job_no_interrupt(
(timestamp + delay_seconds as i64)
]
).ok();
if thread == Thread::Imap {
*context.perform_inbox_jobs_needed.write().unwrap() = true;
}
}
pub fn add_job_with_interrupt(

View File

@@ -3,6 +3,8 @@ use std::sync::{Arc, Condvar, Mutex};
use crate::context::Context;
use crate::error::{Error, Result};
use crate::imap::Imap;
use crate::job::{get_next_wakeup_time, Thread};
use std::time::Duration;
#[derive(Debug)]
pub struct JobThread {
@@ -57,10 +59,6 @@ impl JobThread {
}
pub fn interrupt_idle(&self, context: &Context) {
{
self.state.0.lock().unwrap().jobs_needed = true;
}
info!(context, "Interrupting {}-IDLE...", self.name);
self.imap.interrupt_idle(context);
@@ -140,14 +138,15 @@ impl JobThread {
let &(ref lock, ref cvar) = &*self.state.clone();
let mut state = lock.lock().unwrap();
if state.jobs_needed {
info!(
context,
"{}-IDLE will not be started as it was interrupted while not ideling.",
self.name,
);
state.jobs_needed = false;
return;
if self.folder_config_name == "INBOX" {
let duration = get_next_wakeup_time(context, Thread::Imap);
if duration <= Duration::from_millis(1) {
info!(
context,
"INBOX-IDLE will not be started because of waiting jobs."
);
return;
}
}
if state.suspended {