]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Use CAS for atomic maps lock
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 13 Mar 2016 22:21:19 +0000 (22:21 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 13 Mar 2016 22:21:19 +0000 (22:21 +0000)
src/libutil/map.c

index cd4992eabfe80d6693d02f8441ec2b2010386eb4..377154b8f8d9ec72ea15a4eb3dcfe283f9634bac 100644 (file)
@@ -539,15 +539,13 @@ file_callback (gint fd, short what, void *ud)
 
        pool = map->pool;
 
-       if (g_atomic_int_get (map->locked)) {
+       if (!g_atomic_int_compare_and_exchange (map->locked, 0, 1)) {
                msg_info_pool (
                        "don't try to reread map as it is locked by other process, will reread it later");
                jitter_timeout_event (map, TRUE, FALSE, FALSE);
                return;
        }
 
-       g_atomic_int_inc (map->locked);
-
        if (stat (data->filename, &st) != -1 &&
                (st.st_mtime > data->st.st_mtime || data->st.st_mtime == -1)) {
                /* File was modified since last check */