changeset 549:7002f6e48db9

* src/common/thread.cxx: Fix potential warning and overflow with CYGNUM_KERNEL_THREADS_DATA_MAX == 32.
author jlarmour
date Thu, 30 Jan 2003 07:02:53 +0000
parents fb853432c81a
children bedc0ec92536
files packages/kernel/current/ChangeLog packages/kernel/current/cdl/thread.cdl packages/kernel/current/src/common/thread.cxx
diffstat 3 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/packages/kernel/current/ChangeLog
+++ b/packages/kernel/current/ChangeLog
@@ -1,3 +1,8 @@
+2003-01-30  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* src/common/thread.cxx: Fix potential warning and overflow with
+	CYGNUM_KERNEL_THREADS_DATA_MAX == 32.
+
 2003-01-28  Jonathan Larmour  <jifl@eCosCentric.com>
 
 	* src/common/kapi.cxx (cyg_thread_get_next): Be quite zealous about
--- a/packages/kernel/current/cdl/thread.cdl
+++ b/packages/kernel/current/cdl/thread.cdl
@@ -165,7 +165,7 @@ cdl_component CYGVAR_KERNEL_THREADS_DATA
     cdl_option CYGNUM_KERNEL_THREADS_DATA_MAX {
 	display            "Number of words of per-thread data"
 	flavor             data
-	legal_values       4 to 31
+	legal_values       4 to 32
 	default_value      6
 	description "
         It is possible for the kernel to support per-thread data, in
@@ -176,7 +176,7 @@ cdl_component CYGVAR_KERNEL_THREADS_DATA
         number of words of per-thread data that the kernel will
         allow. In the current implementation a bitmask is used to identify
         used per-thread data slots and so the maximum legal value must
-        remain 31."
+        remain 32."
     }
 
     cdl_component CYGNUM_KERNEL_THREADS_DATA_ALL {
--- a/packages/kernel/current/src/common/thread.cxx
+++ b/packages/kernel/current/src/common/thread.cxx
@@ -1055,7 +1055,9 @@ Cyg_Thread::deliver_exception(
 
 // Set the data map bits for each free slot in the data array.
 cyg_ucount32 Cyg_Thread::thread_data_map = (~CYGNUM_KERNEL_THREADS_DATA_ALL) &
-                                           ((1<<CYGNUM_KERNEL_THREADS_DATA_MAX)-1);
+             (1+(((cyg_ucount32)(1<<(CYGNUM_KERNEL_THREADS_DATA_MAX-1))-1)<<1));
+// the second expression is equivalent to ((1<<CYGNUM_KERNEL_THREADS_DATA_MAX)-1);
+// but avoids overflow. The compiler will compile to a constant just fine.
 
 Cyg_Thread::cyg_data_index
 Cyg_Thread::new_data_index()