mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 21:36:30 +03:00
remove thread-suspend
This commit is contained in:
@@ -498,8 +498,6 @@ pub struct BobStatus {
|
|||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct SmtpState {
|
pub struct SmtpState {
|
||||||
pub idle: bool,
|
pub idle: bool,
|
||||||
pub suspended: bool,
|
|
||||||
pub doing_jobs: bool,
|
|
||||||
pub perform_jobs_needed: i32,
|
pub perform_jobs_needed: i32,
|
||||||
pub probe_network: bool,
|
pub probe_network: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/job.rs
52
src/job.rs
@@ -479,24 +479,12 @@ pub fn perform_smtp_jobs(context: &Context) {
|
|||||||
state.probe_network = false;
|
state.probe_network = false;
|
||||||
state.perform_jobs_needed = 0;
|
state.perform_jobs_needed = 0;
|
||||||
|
|
||||||
if state.suspended {
|
|
||||||
info!(context, "SMTP-jobs suspended.",);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
state.doing_jobs = true;
|
|
||||||
probe_smtp_network
|
probe_smtp_network
|
||||||
};
|
};
|
||||||
|
|
||||||
info!(context, "SMTP-jobs started...",);
|
info!(context, "SMTP-jobs started...",);
|
||||||
job_perform(context, Thread::Smtp, probe_smtp_network);
|
job_perform(context, Thread::Smtp, probe_smtp_network);
|
||||||
info!(context, "SMTP-jobs ended.");
|
info!(context, "SMTP-jobs ended.");
|
||||||
|
|
||||||
{
|
|
||||||
let &(ref lock, _) = &*context.smtp_state.clone();
|
|
||||||
let mut state = lock.lock().unwrap();
|
|
||||||
|
|
||||||
state.doing_jobs = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn perform_smtp_idle(context: &Context) {
|
pub fn perform_smtp_idle(context: &Context) {
|
||||||
@@ -775,24 +763,9 @@ fn job_perform(context: &Context, thread: Thread, probe_network: bool) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// some configuration jobs are "exclusive":
|
// some configuration jobs are "exclusive":
|
||||||
// - they are always executed in the imap-thread and the smtp-thread is suspended during execution
|
|
||||||
// - they may change the database handle change the database handle; we do not keep old pointers therefore
|
|
||||||
// - they can be re-executed one time AT_ONCE, but they are not save in the database for later execution
|
// - they can be re-executed one time AT_ONCE, but they are not save in the database for later execution
|
||||||
if Action::ConfigureImap == job.action || Action::ImexImap == job.action {
|
if Action::ConfigureImap == job.action || Action::ImexImap == job.action {
|
||||||
job_kill_action(context, job.action);
|
job_kill_action(context, job.action);
|
||||||
context
|
|
||||||
.sentbox_thread
|
|
||||||
.clone()
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.suspend(context);
|
|
||||||
context
|
|
||||||
.mvbox_thread
|
|
||||||
.clone()
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.suspend(context);
|
|
||||||
suspend_smtp_thread(context, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut tries = 0;
|
let mut tries = 0;
|
||||||
@@ -834,19 +807,6 @@ fn job_perform(context: &Context, thread: Thread, probe_network: bool) {
|
|||||||
tries += 1
|
tries += 1
|
||||||
}
|
}
|
||||||
if Action::ConfigureImap == job.action || Action::ImexImap == job.action {
|
if Action::ConfigureImap == job.action || Action::ImexImap == job.action {
|
||||||
context
|
|
||||||
.sentbox_thread
|
|
||||||
.clone()
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.unsuspend(context);
|
|
||||||
context
|
|
||||||
.mvbox_thread
|
|
||||||
.clone()
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.unsuspend(context);
|
|
||||||
suspend_smtp_thread(context, false);
|
|
||||||
break;
|
break;
|
||||||
} else if job.try_again == TryAgain::AtOnce || job.try_again == TryAgain::StandardDelay {
|
} else if job.try_again == TryAgain::AtOnce || job.try_again == TryAgain::StandardDelay {
|
||||||
let tries = job.tries + 1;
|
let tries = job.tries + 1;
|
||||||
@@ -914,18 +874,6 @@ fn get_backoff_time_offset(c_tries: libc::c_int) -> i64 {
|
|||||||
seconds as i64
|
seconds as i64
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suspend_smtp_thread(context: &Context, suspend: bool) {
|
|
||||||
context.smtp_state.0.lock().unwrap().suspended = suspend;
|
|
||||||
if suspend {
|
|
||||||
loop {
|
|
||||||
if !context.smtp_state.0.lock().unwrap().doing_jobs {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::thread::sleep(std::time::Duration::from_micros(300 * 1000));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_mdn(context: &Context, msg_id: MsgId) -> Result<(), Error> {
|
fn send_mdn(context: &Context, msg_id: MsgId) -> Result<(), Error> {
|
||||||
let mut mimefactory = MimeFactory::load_mdn(context, msg_id)?;
|
let mut mimefactory = MimeFactory::load_mdn(context, msg_id)?;
|
||||||
unsafe { mimefactory.render()? };
|
unsafe { mimefactory.render()? };
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ pub struct JobThread {
|
|||||||
pub struct JobState {
|
pub struct JobState {
|
||||||
idle: bool,
|
idle: bool,
|
||||||
jobs_needed: bool,
|
jobs_needed: bool,
|
||||||
suspended: bool,
|
|
||||||
using_handle: bool,
|
using_handle: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,32 +29,6 @@ impl JobThread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suspend(&self, context: &Context) {
|
|
||||||
info!(context, "Suspending {}-thread.", self.name,);
|
|
||||||
{
|
|
||||||
self.state.0.lock().unwrap().suspended = true;
|
|
||||||
}
|
|
||||||
self.interrupt_idle(context);
|
|
||||||
loop {
|
|
||||||
let using_handle = self.state.0.lock().unwrap().using_handle;
|
|
||||||
if !using_handle {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::thread::sleep(std::time::Duration::from_micros(300 * 1000));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unsuspend(&self, context: &Context) {
|
|
||||||
info!(context, "Unsuspending {}-thread.", self.name);
|
|
||||||
|
|
||||||
let &(ref lock, ref cvar) = &*self.state.clone();
|
|
||||||
let mut state = lock.lock().unwrap();
|
|
||||||
|
|
||||||
state.suspended = false;
|
|
||||||
state.idle = true;
|
|
||||||
cvar.notify_one();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn interrupt_idle(&self, context: &Context) {
|
pub fn interrupt_idle(&self, context: &Context) {
|
||||||
{
|
{
|
||||||
self.state.0.lock().unwrap().jobs_needed = true;
|
self.state.0.lock().unwrap().jobs_needed = true;
|
||||||
@@ -77,10 +50,6 @@ impl JobThread {
|
|||||||
let &(ref lock, _) = &*self.state.clone();
|
let &(ref lock, _) = &*self.state.clone();
|
||||||
let mut state = lock.lock().unwrap();
|
let mut state = lock.lock().unwrap();
|
||||||
|
|
||||||
if state.suspended {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
state.using_handle = true;
|
state.using_handle = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,14 +114,6 @@ impl JobThread {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.suspended {
|
|
||||||
while !state.idle {
|
|
||||||
state = cvar.wait(state).unwrap();
|
|
||||||
}
|
|
||||||
state.idle = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
state.using_handle = true;
|
state.using_handle = true;
|
||||||
|
|
||||||
if !use_network {
|
if !use_network {
|
||||||
|
|||||||
Reference in New Issue
Block a user