Skip to content

Commit

Permalink
Revert "Scan screen: further simplify mutex use (#78)"
Browse files Browse the repository at this point in the history
This reverts commit c74e52d.
The fix was not right, using deferred pthread_cancel (the
default). Also the use of locks needs to be revised.
  • Loading branch information
Gerrit Renker committed Oct 17, 2020
1 parent f247c6a commit 9c21760
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions iw_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ struct scan_result {
pthread_mutex_t mutex;
};

extern void init_scan_list(struct scan_result *sr);
extern void free_scan_list(struct scan_entry *head);
extern void scan_result_init(struct scan_result *sr);
extern void scan_result_fini(struct scan_result *sr);
extern void *do_scan(void *sr_ptr);

/*
Expand Down
23 changes: 20 additions & 3 deletions iw_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void sort_scan_list(struct scan_entry **headp)
}

/** De-allocate list. Use after all threads are terminated. */
void free_scan_list(struct scan_entry *head)
static void free_scan_list(struct scan_entry *head)
{
if (head) {
free_scan_list(head->next);
Expand All @@ -304,7 +304,7 @@ void free_scan_list(struct scan_entry *head)
}

/** Initialize scan results. Requires lock to be taken. */
void init_scan_list(struct scan_result *sr)
static void init_scan_list(struct scan_result *sr)
{
free_scan_list(sr->head);
free(sr->channel_stats);
Expand All @@ -313,7 +313,6 @@ void init_scan_list(struct scan_result *sr)
sr->msg[0] = '\0';
sr->max_essid_len = MAX_ESSID_LEN;
memset(&(sr->num), 0, sizeof(sr->num));
sr->mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
}

/*
Expand Down Expand Up @@ -368,6 +367,24 @@ static void compute_channel_stats(struct scan_result *sr)
sr->num.ch_stats = n < MAX_CH_STATS ? n : MAX_CH_STATS;
}

/*
* Scan results.
*/
void scan_result_init(struct scan_result *sr)
{
init_scan_list(sr);
pthread_mutex_init(&sr->mutex, NULL);
}

void scan_result_fini(struct scan_result *sr)
{
pthread_mutex_lock(&sr->mutex);
free_scan_list(sr->head);
free(sr->channel_stats);
pthread_mutex_unlock(&sr->mutex);
pthread_mutex_destroy(&sr->mutex);
}

/** The actual scan thread. */
void *do_scan(void *sr_ptr)
{
Expand Down
6 changes: 2 additions & 4 deletions scan_scr.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void scr_aplst_init(void)
mvwaddstr(w_aplst, START_LINE, 1, "Waiting for scan data ...");
wrefresh(w_aplst);

init_scan_list(&sr);
scan_result_init(&sr);
pthread_create(&scan_thread, NULL, do_scan, &sr);
}

Expand Down Expand Up @@ -251,8 +251,6 @@ int scr_aplst_loop(WINDOW *w_menu)
void scr_aplst_fini(void)
{
pthread_cancel(scan_thread);
free_scan_list(sr.head);
free(sr.channel_stats);

scan_result_fini(&sr);
delwin(w_aplst);
}

0 comments on commit 9c21760

Please sign in to comment.