2
Copyright (C) 2010 Zimin
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include "filesystemlock.h"
24
FilesystemLock::FilesystemLock()
28
pthread_cond_init(&condition, NULL);
29
pthread_mutex_init(&mutex, NULL);
32
FilesystemLock::~FilesystemLock()
34
pthread_cond_destroy(&condition);
35
pthread_mutex_destroy(&mutex);
38
void FilesystemLock::scan_begin()
40
pthread_mutex_lock(&mutex);
43
if (updater_count == 0)
46
pthread_mutex_unlock(&mutex);
49
pthread_cond_wait(&condition, &mutex);
51
pthread_mutex_unlock(&mutex);
54
void FilesystemLock::scan_end() {
55
pthread_mutex_lock(&mutex);
57
assert(scanner_count >= 0);
58
if (scanner_count == 0)
59
pthread_cond_broadcast(&condition);
60
pthread_mutex_unlock(&mutex);
63
void FilesystemLock::scan_update_begin()
65
pthread_mutex_lock(&mutex);
68
if (scanner_count == 0 && updater_count == 0)
72
pthread_mutex_unlock(&mutex);
75
pthread_cond_wait(&condition, &mutex);
77
pthread_mutex_unlock(&mutex);
80
void FilesystemLock::scan_update_end()
82
pthread_mutex_lock(&mutex);
85
assert(scanner_count >= 0 && updater_count >= 0);
87
pthread_cond_broadcast(&condition);
88
pthread_mutex_unlock(&mutex);