[Kos-cvs] kos/modules/kitc _kmutex.c,1.4,1.5

thomas at kos.enix.org thomas at kos.enix.org
Wed Dec 29 20:28:52 CET 2004


Update of /home/kos/cvs/kos/modules/kitc
In directory the-doors:/tmp/cvs-serv1745/modules/kitc

Modified Files:
	_kmutex.c 
Log Message:
2004-12-29  Thomas Petazzoni  <thomas at crazy.kos.nx>

	* modules/x86/task/_thread_cpu_context.c
	(init_user_thread_context): VMM functions now work with address
	spaces.

	* modules/x86/mm/_vmap.c (arch_do_unmap_virtual_page): Unmapping a
	page that hasn't any corresponding PT is not an error. So, the
	ASSERT_FATAL() was removed, and replaced by a test that returns
	SUCCESS if there's not PT associated to the page.

	* modules/vmm/vmm.h: VMM functions now operate on address space
	not on teams.

	* modules/vmm/vmm.c: Try to limit the exports only to the modules
	that really need them.

	* modules/vmm/_vmm_map.c: VMM functions now operate on address space,
	not on teams.

	* modules/vmm/_vmm_as.c: VMM functions now operate on address space,
	not on teams. Check the return of kmutex_lock and kmutex_unlock
	for safety.

	* modules/vmm/_vmm.h: VMM functions now operate on address space,
	not on teams.

	* modules/test/vmm_test.c: A couple of updates, whitespaces
	cleanup. In the hope of the stress test to pass, one day, maybe
	;-)

	* modules/test/test.c: Add the new mutex test.

	* modules/test/sem_test.c: Semaphore test update. Less kernel
	threads are created, less time is spent in usleep() and
	create_kernel_thread() return is checked to make sure all kernel
	threads are correctly created.

	* modules/test/mutex_test.c: New mutex test.

	* modules/test/_test.h: New mutex_test() function.

	* modules/test/Makefile (OBJS): New mutex_test.c file.

	* modules/task/_task_kstack.c (unallocate_cpl0_stack): Update
	calls to unmap_virtual_range() according to new prototype.

	* modules/pci/_pci.c (_pci_scan_bus): Not initializing pca
	(pci_config_address) to 0 is not good ! Now, PCI devices are
	correctly detected under Bochs and Qemu. Even a network adapter,
	along with its I/O space and IRQ configuration can be detected !

	* modules/lib/std/stdlib.h (printk): printk is re-defined as
	ktty_printk, and not bochs_printk. By the way, I find this #define
	quite ugly.

	* modules/kos/wolfgang.c (primary_thread): Testing, testing,
	debugging, debugging, testing...

	* modules/kitc/_kmutex.c: Changed k_ui32_t to
	spinlock_flags_t. Added some debugging messages and assertions.

	* MkVars (KOSSYSPATH): The path to the kos-sys CVS module, in
	which the hard disk image is stored. The default value is
	../kos-sys/, but it can be overriden using the .mkvars file.

	* Makefile (qemu): Instead of an hard-coded path to the hard disk
	image, we use a KOSSYSPATH variable that can be overriden in the
	.mkvars file.



Index: _kmutex.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/kitc/_kmutex.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- _kmutex.c	28 Dec 2004 18:44:36 -0000	1.4
+++ _kmutex.c	29 Dec 2004 19:28:50 -0000	1.5
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2000, 
+ * Copyright (C) 2000, David Decotigny, Julien Munier, Thomas Petazzoni
  * http://kos.enix.org
  *
  * Mutex.
@@ -27,11 +27,11 @@
 
 result_t kmutex_destroy(struct kmutex *mutex)
 {
-  k_ui32_t flags;
+  spinlock_flags_t flags;
   result_t result;
 
   ASSERT_RETURN_VAL(mutex != NULL, -EINVAL);
-  
+
   synchq_lock(& mutex->synchq, flags);
 
   /* Make sure nobody's waiting */
@@ -50,15 +50,15 @@
 
 result_t kmutex_lock(struct kmutex *mutex)
 {
-  k_ui32_t flags;
+  spinlock_flags_t flags;
 
   ASSERT_RETURN_VAL(mutex != NULL, -EINVAL);
 
-  DEBUG_PRINT3("[kmutex_lock] Mutex lock 0x%x, %d++\n",
-	       (unsigned) mutex, mutex->nested_level);
-
   synchq_lock(& mutex->synchq, flags);
 
+  DEBUG_PRINT3("[kmutex_lock] Mutex lock 0x%x, %d++ ...",
+	       (unsigned) mutex, mutex->nested_level);
+
   if(mutex->free)
     {
       ASSERT_FATAL(mutex->nested_level == 0);
@@ -73,12 +73,22 @@
 	    ASSERT_FATAL(mutex->nested_level > 0);
 	  else
 	    {
+	      DEBUG_PRINT3("[kmutex_lock] DEADLOCK Mutex already held by thread 0x%x:%s, and we are 0x%x:%s\n",
+			   (unsigned) mutex->owner, mutex->owner->name,
+			   (unsigned) get_current_thread(),
+			   get_current_thread()->name);
+
 	      synchq_unlock(& mutex->synchq, flags);
 	      return -EDEADLK;
 	    }
 	}
-      else
+      else {
+	DEBUG_PRINT3("Waiting ...");
 	synchq_wait_unsafe(& mutex->synchq, NULL, NULL);
+      }
+
+      if(! mutex->is_recursive)
+	ASSERT_FATAL(mutex->nested_level == 0);
 
       mutex->free  = FALSE;
       mutex->owner = get_current_thread();
@@ -86,6 +96,8 @@
 
   mutex->nested_level++;
 
+  DEBUG_PRINT3("Granted ! : %d\n", mutex->nested_level);
+
   synchq_unlock(& mutex->synchq, flags);
 
   return ESUCCESS;
@@ -94,14 +106,14 @@
 result_t kmutex_trylock(struct kmutex *mutex)
 {
   result_t result = ESUCCESS;
-  k_ui32_t flags;
+  spinlock_flags_t flags;
 
   ASSERT_RETURN_VAL(mutex != NULL, -EINVAL);
 
+  synchq_lock(& mutex->synchq, flags);
+
   DEBUG_PRINT3("[kmutex_trylock] Mutex trylock 0x%x, %d++\n",
 	       (unsigned) mutex, mutex->nested_level);
- 
-  synchq_lock(& mutex->synchq, flags);
 
   if(mutex->free)
     {
@@ -131,26 +143,28 @@
 }
 
 
-result_t kmutex_unlock(struct kmutex *mutex) 
+result_t kmutex_unlock(struct kmutex *mutex)
 {
-  k_ui32_t flags;
+  spinlock_flags_t flags;
 
   ASSERT_RETURN_VAL(mutex != NULL, -EINVAL);
 
+  synchq_lock(& mutex->synchq, flags);
+
   DEBUG_PRINT3("[kmutex_unlock] Mutex unlock 0x%x, %d--\n",
 	       (unsigned) mutex, mutex->nested_level);
 
-  synchq_lock(& mutex->synchq, flags);
-
   if (mutex->free)
     {
       synchq_unlock(& mutex->synchq, flags);
+      DEBUG_PRINT3("[kmutex_unlock] -EINVAL\n");
       return -EINVAL;
     }
 
   if (mutex->owner != get_current_thread())
     {
       synchq_unlock(& mutex->synchq, flags);
+      DEBUG_PRINT3("[kmutex_unlock] -EPERM\n");
       return -EPERM;
     }
 



More information about the Kos-cvs mailing list