kernel: select work queue implementation

Attempts to reimplement the existing work API using a new work
implementation failed, primarily due to heavy use of whitebox testing
in validating the original API.  Add a temporary Kconfig that will
select between the two implementations so we can use the same
identifiers but select which implementation they reference.

This commit just adds the selection infrastructure and uses it to
conditionalize the existing implementation in anticipation of the new
one in the next commit.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
diff --git a/doc/zephyr.doxyfile.in b/doc/zephyr.doxyfile.in
index 3ee6cee..0297832 100644
--- a/doc/zephyr.doxyfile.in
+++ b/doc/zephyr.doxyfile.in
@@ -1973,6 +1973,7 @@
                          "CONFIG_FPU" \
                          "CONFIG_FPU_SHARING" \
                          "CONFIG_HEAP_MEM_POOL_SIZE" \
+                         "CONFIG_KERNEL_WORK1" \
                          "CONFIG_MMU" \
                          "CONFIG_NET_L2_ETHERNET_MGMT" \
                          "CONFIG_NET_MGMT_EVENT" \
diff --git a/include/kernel.h b/include/kernel.h
index bb88570..83a262b 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -2482,6 +2482,8 @@
 
 /** @} */
 
+#ifdef CONFIG_KERNEL_WORK1
+
 struct k_work;
 
 /**
@@ -2954,6 +2956,9 @@
 }
 
 /** @} */
+
+#endif /* CONFIG_KERNEL_WORK1 */
+
 /**
  * @defgroup mutex_apis Mutex APIs
  * @ingroup kernel_apis
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
index 912a6a9..e12f66f 100644
--- a/kernel/CMakeLists.txt
+++ b/kernel/CMakeLists.txt
@@ -22,7 +22,6 @@
   system_work_q.c
   thread.c
   version.c
-  work_q.c
   condvar.c
   smp.c
   banner.c
@@ -37,6 +36,7 @@
 
 # Kernel files has the macro __ZEPHYR_SUPERVISOR__ set so that it
 # optimizes the code when userspace is enabled.
+
 set_target_properties(
   kernel
   PROPERTIES
@@ -44,6 +44,8 @@
   __ZEPHYR_SUPERVISOR__
   )
 
+target_sources_ifdef(CONFIG_KERNEL_WORK1          kernel PRIVATE work_q.c)
+
 target_sources_ifdef(CONFIG_STACK_CANARIES        kernel PRIVATE compiler_stack_protect.c)
 target_sources_ifdef(CONFIG_SYS_CLOCK_EXISTS      kernel PRIVATE timeout.c timer.c)
 target_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_C   kernel PRIVATE atomic_c.c)
diff --git a/kernel/Kconfig b/kernel/Kconfig
index dc0bae2..230e1d2 100644
--- a/kernel/Kconfig
+++ b/kernel/Kconfig
@@ -875,4 +875,22 @@
 	help
 	  This option enables thread local storage (TLS) support in kernel.
 
+choice KERNEL_WORK
+	prompt "Which work queue implementation to use"
+	default KERNEL_WORK1
+
+config KERNEL_WORK1
+	bool "Select the original racy work API"
+	help
+	  This selects the original k_work_* implementation, and excludes the
+	  new simplementation.
+
+config KERNEL_WORK2
+	bool "Select alternative work API"
+	help
+	  This disables the original k_work_* implementation and replaces it
+	  with a new one.
+
+endchoice # KERNEL_WORK
+
 endmenu
diff --git a/lib/os/CMakeLists.txt b/lib/os/CMakeLists.txt
index d754e33..923e83f 100644
--- a/lib/os/CMakeLists.txt
+++ b/lib/os/CMakeLists.txt
@@ -19,11 +19,12 @@
   sem.c
   thread_entry.c
   timeutil.c
-  work_q.c
   heap.c
   heap-validate.c
   )
 
+zephyr_sources_ifdef(CONFIG_KERNEL_WORK1 work_q.c)
+
 zephyr_sources_ifdef(CONFIG_CBPRINTF_COMPLETE cbprintf_complete.c)
 zephyr_sources_ifdef(CONFIG_CBPRINTF_NANO cbprintf_nano.c)