Add remove thread

This commit is contained in:
PolynomialDivision 2017-07-16 20:59:32 +02:00
parent c696b8c16e
commit e444dd57db
3 changed files with 31 additions and 3 deletions

View file

@ -54,6 +54,7 @@ typedef struct client_s {
#define ARRAY_CLIENT_LEN 1000
#define TIME_THRESHOLD_CLIENT 60
struct client_s client_array[ARRAY_CLIENT_LEN];
pthread_mutex_t client_array_mutex;
@ -64,6 +65,7 @@ void client_array_insert(client entry);
client* client_array_delete(client entry);
void print_client_array();
void print_client_entry(client entry);
void *remove_client_array_thread(void *arg);
#define ARRAY_LEN 1000

View file

@ -60,10 +60,12 @@ int main(int argc, char **argv) {
init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 0);
pthread_t tid;
pthread_create(&tid, NULL, &remove_array_thread, NULL);
pthread_t tid_probe;
pthread_create(&tid_probe, NULL, &remove_array_thread, NULL);
pthread_t tid_client;
pthread_create(&tid_client, NULL, &remove_client_array_thread, NULL);
//pthread_create(&tid, NULL, &remove_thread, NULL);
dawn_init_ubus(ubus_socket, opt_hostapd_dir);

View file

@ -15,6 +15,7 @@ int client_array_go_next(char sort_order[], int i, client entry,
client next_entry);
int client_array_go_next_help(char sort_order[], int i, client entry,
client next_entry);
void remove_old_client_entries(time_t current_time, long long int threshold);
int probe_entry_last = -1;
int client_entry_last = -1;
@ -232,6 +233,17 @@ void insert_to_array(probe_entry entry, int inc_counter)
pthread_mutex_unlock(&probe_array_mutex);
}
void remove_old_client_entries(time_t current_time, long long int threshold)
{
for(int i = 0; i < probe_entry_last; i++)
{
if (client_array[i].time < current_time - threshold)
{
client_array_delete(client_array[i]);
}
}
}
void remove_old_probe_entries(time_t current_time, long long int threshold)
{
for(int i = 0; i < probe_entry_last; i++)
@ -254,6 +266,18 @@ void *remove_array_thread(void *arg) {
return 0;
}
void *remove_client_array_thread(void *arg) {
while (1) {
sleep(TIME_THRESHOLD_CLIENT);
pthread_mutex_lock(&client_array_mutex);
printf("[Thread] : Removing old client entries!\n");
remove_old_client_entries(time(0), TIME_THRESHOLD_CLIENT);
pthread_mutex_unlock(&client_array_mutex);
}
return 0;
}
void insert_client_to_array(client entry)
{
pthread_mutex_lock(&client_array_mutex);