forked from pi-hole/FTL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
threads.c
46 lines (39 loc) · 1.23 KB
/
threads.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Thread routines
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
#include "FTL.h"
// 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.
// threadlock: The threadlock ensures that only one thread can be active at any given time
pthread_mutex_t threadlock;
void enable_thread_lock(void)
{
// logg("At thread lock: waiting");
int ret = pthread_mutex_lock(&threadlock);
// logg("At thread lock: passed");
if(ret != 0)
logg("Thread lock error: %i",ret);
}
void disable_thread_lock(void)
{
int ret = pthread_mutex_unlock(&threadlock);
// logg("At thread lock: unlocked");
if(ret != 0)
logg("Thread unlock error: %i",ret);
}
void init_thread_lock(void)
{
if (pthread_mutex_init(&threadlock, NULL) != 0)
{
logg("FATAL: Thread mutex init failed\n");
// Return failure
exit(EXIT_FAILURE);
}
}