Wrap SMTP Client concurrency check in a mutex
authorArt Cancro <ajc@citadel.org>
Tue, 7 Feb 2023 21:35:58 +0000 (16:35 -0500)
committerArt Cancro <ajc@citadel.org>
Tue, 7 Feb 2023 21:35:58 +0000 (16:35 -0500)
citadel/server/modules/smtp/serv_smtpclient.c
citadel/server/server.h

index bab18cee22161942321fc6f8be54166ec32dfb53..de61baee36dbeb0e6e77ed25b0d5cddeedece63b 100644 (file)
@@ -38,8 +38,6 @@ struct smtpmsgsrc {           // Data passed in and out of libcurl for message upload
        int bytes_sent;
 };
 
-static int doing_smtpclient = 0;
-
 // Initialize the SMTP outbound queue
 void smtp_init_spoolout(void) {
        struct ctdlroom qrbuf;
@@ -499,16 +497,17 @@ void smtp_add_msg(long msgnum, void *userdata) {
 
 // Run through the queue sending out messages.
 void smtp_do_queue(void) {
+       static int doing_smtpclient = 0;
        int i = 0;
 
-       // This is a simple concurrency check to make sure only one smtpclient
-       // run is done at a time.  We could do this with a mutex, but since we
-       // don't really require extremely fine granularity here, we'll do it
-       // with a static variable instead.
+       // This is a concurrency check to make sure only one smtpclient run is done at a time.
+       begin_critical_section(S_SMTPQUEUE);
        if (doing_smtpclient) {
+               end_critical_section(S_SMTPQUEUE);
                return;
        }
        doing_smtpclient = 1;
+       end_critical_section(S_SMTPQUEUE);
 
        syslog(LOG_DEBUG, "smtpclient: start queue run");
 
index 5fb7e1276d6390d91d0c542c8380503eadc77dad..7941945cdc5734704c272eaec52a34645a7f22b0 100644 (file)
@@ -149,6 +149,7 @@ enum {
        S_SINGLE_USER,
        S_IM_LOGS,
        S_OPENSSL,
+       S_SMTPQUEUE,
        MAX_SEMAPHORES
 };