Rework thread locks (since we don't need different kinds anymore)

This commit is contained in:
DL6ER
2017-06-03 19:08:24 +02:00
parent cb02d8c42d
commit 2f0f68e4d5
5 changed files with 17 additions and 37 deletions
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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
View File
@@ -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);
+2 -2
View File
@@ -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)
{
+9 -28
View File
@@ -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);
}