]> source.dussan.org Git - rspamd.git/commitdiff
Add basic locking.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 31 Oct 2011 15:45:29 +0000 (18:45 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 31 Oct 2011 15:45:29 +0000 (18:45 +0300)
src/kvstorage_server.c

index 81d04d4c2464962c7a969771f9e252d93bfa1081..d124e9f4a6f5c2ed76b2d54ecdfe45ce77a4a27e 100644 (file)
@@ -387,7 +387,9 @@ kvstorage_read_socket (f_str_t * in, void *arg)
                                rspamd_set_dispatcher_policy (session->dispather, BUFFER_CHARACTER, session->length);
                        }
                        else if (session->command == KVSTORAGE_CMD_GET) {
+                               g_static_rw_lock_reader_lock (&session->cf->storage->rwlock);
                                elt = rspamd_kv_storage_lookup (session->cf->storage, session->key, session->now);
+                               g_static_rw_lock_reader_unlock (&session->cf->storage->rwlock);
                                if (elt == NULL) {
                                        return rspamd_dispatcher_write (session->dispather, ERROR_NOT_FOUND,
                                                                                                                                sizeof (ERROR_NOT_FOUND) - 1, FALSE, TRUE);
@@ -407,11 +409,14 @@ kvstorage_read_socket (f_str_t * in, void *arg)
                                }
                        }
                        else if (session->command == KVSTORAGE_CMD_DELETE) {
+                               g_static_rw_lock_writer_lock (&session->cf->storage->rwlock);
                                if (rspamd_kv_storage_delete (session->cf->storage, session->key)) {
+                                       g_static_rw_lock_writer_unlock (&session->cf->storage->rwlock);
                                        return rspamd_dispatcher_write (session->dispather, "DELETED" CRLF,
                                                                                                                                sizeof ("DELETED" CRLF) - 1, FALSE, TRUE);
                                }
                                else {
+                                       g_static_rw_lock_writer_unlock (&session->cf->storage->rwlock);
                                        return rspamd_dispatcher_write (session->dispather, ERROR_NOT_FOUND,
                                                                                                                sizeof (ERROR_NOT_FOUND) - 1, FALSE, TRUE);
                                }
@@ -426,12 +431,15 @@ kvstorage_read_socket (f_str_t * in, void *arg)
        case KVSTORAGE_STATE_READ_DATA:
                session->state = KVSTORAGE_STATE_READ_CMD;
                rspamd_set_dispatcher_policy (session->dispather, BUFFER_LINE, -1);
+               g_static_rw_lock_writer_lock (&session->cf->storage->rwlock);
                if (rspamd_kv_storage_insert (session->cf->storage, session->key, in->begin, in->len,
                                session->flags, session->expire)) {
+                       g_static_rw_lock_writer_unlock (&session->cf->storage->rwlock);
                        return rspamd_dispatcher_write (session->dispather, "STORED" CRLF,
                                                                                        sizeof ("STORED" CRLF) - 1, FALSE, TRUE);
                }
                else {
+                       g_static_rw_lock_writer_unlock (&session->cf->storage->rwlock);
                        return rspamd_dispatcher_write (session->dispather, ERROR_NOT_STORED,
                                                                        sizeof (ERROR_NOT_STORED) - 1, FALSE, TRUE);
                }