diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py index de8a496a..622cc9a7 100644 --- a/klippy/chelper/__init__.py +++ b/klippy/chelper/__init__.py @@ -182,7 +182,7 @@ defs_serialqueue = """ }; struct serialqueue *serialqueue_alloc(int serial_fd, char serial_fd_type - , int client_id); + , int client_id, char name[16]); void serialqueue_exit(struct serialqueue *sq); void serialqueue_free(struct serialqueue *sq); struct command_queue *serialqueue_alloc_commandqueue(void); diff --git a/klippy/chelper/serialqueue.c b/klippy/chelper/serialqueue.c index c207495c..1af00b06 100644 --- a/klippy/chelper/serialqueue.c +++ b/klippy/chelper/serialqueue.c @@ -47,6 +47,7 @@ struct serialqueue { pthread_mutex_t lock; // protects variables below pthread_cond_t cond; int receive_waiting; + char name[16]; // Baud / clock tracking int receive_window; double bittime_adjust, idle_time; @@ -612,6 +613,7 @@ static void * background_thread(void *data) { struct serialqueue *sq = data; + set_thread_name(sq->name); pollreactor_run(sq->pr); pthread_mutex_lock(&sq->lock); @@ -623,13 +625,15 @@ background_thread(void *data) // Create a new 'struct serialqueue' object struct serialqueue * __visible -serialqueue_alloc(int serial_fd, char serial_fd_type, int client_id) +serialqueue_alloc(int serial_fd, char serial_fd_type, int client_id + , char name[16]) { struct serialqueue *sq = malloc(sizeof(*sq)); memset(sq, 0, sizeof(*sq)); sq->serial_fd = serial_fd; sq->serial_fd_type = serial_fd_type; sq->client_id = client_id; + strncpy(sq->name, name, sizeof(sq->name)); int ret = pipe(sq->pipe_fds); if (ret) diff --git a/klippy/chelper/serialqueue.h b/klippy/chelper/serialqueue.h index 4d447f2f..9da0ad08 100644 --- a/klippy/chelper/serialqueue.h +++ b/klippy/chelper/serialqueue.h @@ -27,7 +27,7 @@ struct pull_queue_message { struct serialqueue; struct serialqueue *serialqueue_alloc(int serial_fd, char serial_fd_type - , int client_id); + , int client_id, char name[16]); void serialqueue_exit(struct serialqueue *sq); void serialqueue_free(struct serialqueue *sq); struct command_queue *serialqueue_alloc_commandqueue(void); diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index ab26514c..2a401f89 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -18,6 +18,8 @@ class SerialReader: self.mcu_name = mcu_name if self.mcu_name: self.warn_prefix = "mcu '%s': " % (self.mcu_name) + sq_name = ("serialq %s" % (self.mcu_name))[:15] + self.sq_name = sq_name.encode("utf-8") # Serial port self.serial_dev = None self.msgparser = msgproto.MessageParser(warn_prefix=self.warn_prefix) @@ -85,7 +87,8 @@ class SerialReader: self.serial_dev = serial_dev self.serialqueue = self.ffi_main.gc( self.ffi_lib.serialqueue_alloc(serial_dev.fileno(), - serial_fd_type, client_id), + serial_fd_type, client_id, + self.sq_name), self.ffi_lib.serialqueue_free) self.background_thread = threading.Thread(target=self._bg_thread) self.background_thread.start() @@ -205,7 +208,8 @@ class SerialReader: self.serial_dev = debugoutput self.msgparser.process_identify(dictionary, decompress=False) self.serialqueue = self.ffi_main.gc( - self.ffi_lib.serialqueue_alloc(self.serial_dev.fileno(), b'f', 0), + self.ffi_lib.serialqueue_alloc(self.serial_dev.fileno(), b'f', 0, + self.sq_name), self.ffi_lib.serialqueue_free) def set_clock_est(self, freq, conv_time, conv_clock, last_clock): self.ffi_lib.serialqueue_set_clock_est(