Stefan Reinauer has uploaded this change for review. ( https://review.coreboot.org/c/em100/+/47780 )
Change subject: Handle exit requests in all long-running functions ......................................................................
Handle exit requests in all long-running functions
Signed-off-by: Stefan Reinauer stefan.reinauer@coreboot.org Change-Id: I5fb37bba1b7398cb6db96d23b226c8b87abee9cf --- M em100.c M em100.h M sdram.c M spi.c 4 files changed, 9 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/em100 refs/changes/80/47780/1
diff --git a/em100.c b/em100.c index 6cbae64..14e9805 100644 --- a/em100.c +++ b/em100.c @@ -15,7 +15,6 @@ #include <stdlib.h> #include <string.h> #include <strings.h> -#include <signal.h> #include <getopt.h> #include <unistd.h> #include <dirent.h> @@ -29,12 +28,12 @@ char *database_version; int debug = 0;
-static volatile int do_exit_flag = 0; +volatile sig_atomic_t exit_requested = 0; static struct em100 em100_state;
static void exit_handler(int sig __unused) { - do_exit_flag = 1; + exit_requested = 1; }
struct em100_hold_pin_states { @@ -1212,7 +1211,7 @@
printf(". Press CTL-C to exit.\n\n");
- while (!do_exit_flag) { + while (!exit_requested) { if (trace) read_spi_trace(em100, terminal, address_offset); diff --git a/em100.h b/em100.h index b003bd6..d49339b 100644 --- a/em100.h +++ b/em100.h @@ -15,6 +15,7 @@ #define __EM100_H__
#include <libusb.h> +#include <signal.h>
#define __unused __attribute__((unused)) #define __packed __attribute__((packed)) @@ -196,6 +197,7 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) char *get_em100_file(const char *name); extern int debug; +extern volatile sig_atomic_t exit_requested;
/* Chips */ int parse_dcfg(chipdesc *chip, TFILE *dcfg); diff --git a/sdram.c b/sdram.c index 408afd8..6a9252a 100644 --- a/sdram.c +++ b/sdram.c @@ -42,7 +42,7 @@ return 0; }
- while (bytes_read < length) { + while (!exit_requested && bytes_read < length) { actual = 0;
bytes_left = length - bytes_read; @@ -92,7 +92,7 @@ return 0; }
- while ( bytes_sent < length) { + while (!exit_requested && bytes_sent < length) { actual = 0;
bytes_left = length - bytes_sent; diff --git a/spi.c b/spi.c index c088a11..b06c72a 100644 --- a/spi.c +++ b/spi.c @@ -114,7 +114,7 @@ return 0; }
- while ( bytes_sent < length) { + while (!exit_requested && bytes_sent < length) { actual = 0;
bytes_left = length - bytes_sent; @@ -268,7 +268,7 @@ return 0; }
- while ( bytes_sent < length) { + while (!exit_requested && bytes_sent < length) { actual = 0;
bytes_left = length - bytes_sent;