mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Rework thread locks (since we don't need different kinds anymore)
This commit is contained in:
@@ -17,7 +17,7 @@ void *GC_thread(void *val)
|
||||
|
||||
// Lock FTL's data structure, since it is likely that it will be changed here
|
||||
// Requests should not be processed/answered when data is about to change
|
||||
enable_read_write_lock("GC_thread");
|
||||
enable_thread_lock("GC_thread");
|
||||
|
||||
// Get minimum time stamp to keep
|
||||
int differencetofullhour = time(NULL) % GCinterval;
|
||||
@@ -141,7 +141,7 @@ void *GC_thread(void *val)
|
||||
}
|
||||
|
||||
// Release thread lock
|
||||
disable_thread_locks("GC_thread");
|
||||
disable_thread_lock("GC_thread");
|
||||
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -97,7 +97,7 @@ void *pihole_log_thread(void *val)
|
||||
{
|
||||
// Lock FTL's data structure, since it is likely that it will be changed here
|
||||
// Requests should not be processed/answered when data is about to change
|
||||
enable_read_write_lock("pihole_log_thread");
|
||||
enable_thread_lock("pihole_log_thread");
|
||||
|
||||
if(newdata > 0 && !flush)
|
||||
{
|
||||
@@ -123,7 +123,7 @@ void *pihole_log_thread(void *val)
|
||||
}
|
||||
|
||||
// Release thread lock
|
||||
disable_thread_locks("pihole_log_thread");
|
||||
disable_thread_lock("pihole_log_thread");
|
||||
}
|
||||
|
||||
// Wait some time before looking again at the log files
|
||||
|
||||
+2
-3
@@ -65,9 +65,8 @@ void parse_args(int argc, char* argv[]);
|
||||
|
||||
char* find_equals(const char* s);
|
||||
|
||||
void enable_read_lock(const char *message);
|
||||
void enable_read_write_lock(const char *message);
|
||||
void disable_thread_locks(const char *message);
|
||||
void enable_thread_lock(const char *message);
|
||||
void disable_thread_lock(const char *message);
|
||||
|
||||
void read_FTLconf(void);
|
||||
|
||||
|
||||
@@ -208,13 +208,13 @@ void *connection_handler_thread(void *socket_desc)
|
||||
|
||||
// Lock FTL data structure, since it is likely that it will be changed here
|
||||
// Requests should not be processed/answered when data is about to change
|
||||
enable_read_lock(threadname);
|
||||
enable_thread_lock(threadname);
|
||||
|
||||
process_request(message, &sock);
|
||||
free(message);
|
||||
|
||||
// Release thread lock
|
||||
disable_thread_locks("connection_handler_thread");
|
||||
disable_thread_lock(threadname);
|
||||
|
||||
if(sock == 0)
|
||||
{
|
||||
|
||||
@@ -13,43 +13,24 @@
|
||||
// Logic of the locks:
|
||||
// Any of the various threads (logparser, GC, client threads) is accessing FTL's data structure. Hence, they should
|
||||
// never run at the same time since the data can change half-way through, leading to unspecified behavior.
|
||||
// threadwritelock: The threadwritelock ensures that only one thread with write-access to FTL's data structure can
|
||||
// be active at any given time
|
||||
// threadreadlock: An expection to the rule of non-concurrency are the client threads, as they do need read-access
|
||||
// Therefore, it is no problem to have several of them running concurrently. Accordingly, client
|
||||
// threads do *not* have to wait at the lock if threadreadlocks is true (i.e. a client listener
|
||||
// thread has activated this thread lock earlier)
|
||||
bool threadwritelock = false;
|
||||
bool threadreadlock = false;
|
||||
// threadlock: The threadlock ensures that only one thread can be active at any given time
|
||||
bool threadlock = false;
|
||||
|
||||
void enable_read_lock(const char *message)
|
||||
void enable_thread_lock(const char *message)
|
||||
{
|
||||
while(threadwritelock) sleepms(5);
|
||||
while(threadlock) sleepms(5);
|
||||
|
||||
if(debugthreads)
|
||||
logg("Thread lock enabled (R ): %s", message);
|
||||
logg("Thread lock enabled: %s", message);
|
||||
|
||||
// Set threadwritelock
|
||||
threadwritelock = false;
|
||||
// Set threadreadlock (see above)
|
||||
threadreadlock = true;
|
||||
// Set threadlock
|
||||
threadlock = true;
|
||||
}
|
||||
|
||||
void enable_read_write_lock(const char *message)
|
||||
void disable_thread_lock(const char *message)
|
||||
{
|
||||
while(threadwritelock || threadreadlock) sleepms(5);
|
||||
threadlock = false;
|
||||
|
||||
if(debugthreads)
|
||||
logg("Thread lock enabled (RW): %s", message);
|
||||
|
||||
// Set threadwritelock
|
||||
threadwritelock = true;
|
||||
}
|
||||
|
||||
void disable_thread_locks(const char *message)
|
||||
{
|
||||
threadwritelock = false;
|
||||
threadreadlock = false;
|
||||
if(debugthreads)
|
||||
logg("Thread lock disabled: %s", message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user