]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-process: Add posix_thread state
authorMichalis Pappas <michalis@unikraft.io>
Fri, 3 Nov 2023 09:45:59 +0000 (10:45 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Fri, 17 Jan 2025 14:59:21 +0000 (14:59 +0000)
The state provides information on whether a posix_thread is
running, blocked, or exited.

Notice that posix_thread_state is only updated by operations
at the posix_process / posix_thread level and may not
always be in sync with the state of the underlying uk_thread.
This specifically applies to the POSIX_THREAD_RUNNING state,
which may not be accurate e.g. if the underlying uk_thread
blocks at the scheduler due to a lock.

On the other hand, the variants of POSIX_STATE_BLOCKED always
reflect the state of a posix_thread, as it is certain that the
underlying uk_thread will also be blocked from the scheduler.

Given the above, a check against POSIX_STATE_RUNNING should only be
used to check if the state of a posix-thread is not terminated or
blocked.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1386

lib/posix-process/process.h

index 28560470cca1c5d255fcf0ee2d44a691bed19b70..0e60fe3715f4abb5f5c7a56288bed4f830d47150 100644 (file)
 
 #define TIDMAP_SIZE (CONFIG_LIBPOSIX_PROCESS_MAX_PID + 1)
 
+/* Notice: The RUNNING state is not necessarily in sync with the state
+ * of the underlying uk_thread (may be blocked by the scheduler).
+ * On the other hand, the BLOCKED state implies that the underlying
+ * uk_thread is also blocked. Use RUNNING only as a means to check
+ * whether a posix-thread is neither terminated or blocked.
+ */
+enum posix_thread_state {
+       POSIX_THREAD_RUNNING,
+       POSIX_THREAD_BLOCKED_VFORK,  /* waiting for child to call execve */
+       POSIX_THREAD_BLOCKED_WAIT,   /* waiting for process state change */
+       POSIX_THREAD_BLOCKED_SIGNAL, /* waiting for signal */
+       POSIX_THREAD_EXITED,         /* terminated normally */
+       POSIX_THREAD_KILLED,         /* terminated by signal */
+};
+
 struct posix_process {
        pid_t pid;
        struct posix_process *parent;
@@ -58,6 +73,7 @@ struct posix_thread {
        struct uk_list_head thread_list_entry;
        struct uk_thread *thread;
        struct uk_alloc *_a;
+       enum posix_thread_state state;
 
        /* TODO: Mutex */
 };