Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Jan 2008 05:13:29 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 132459 for review
Message-ID:  <200801040513.m045DT9m024795@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=132459

Change 132459 by jb@jb_freebsd1 on 2008/01/04 05:13:01

	Drop the mutex lock before freeing memory and obtain it again
	directly after. The window the the CPU is unlocked could be
	enough for another thread to get in a do the expansion and possibly
	to fill the expanded arrays, so put the expand call in a loop
	(while the mutex is locked) and only come out when there is space
	for the cyclic being added.

Affected files ...

.. //depot/projects/dtrace/src/sys/cddl/kern/cyclic.c#7 edit

Differences ...

==== //depot/projects/dtrace/src/sys/cddl/kern/cyclic.c#7 (text+ko) ====

@@ -690,10 +690,14 @@
 	mtx_lock_spin(&cpu->cyp_mtx);
 
 	/* Check if another thread beat us while the mutex was unlocked. */
-	if (old_size < cpu->cyp_size) {
+	if (old_size != cpu->cyp_size) {
 		/* Oh well, he won. */
+		mtx_unlock_spin(&cpu->cyp_mtx);
+
 		free(new_heap, M_CYCLIC);
 		free(new_cyclics, M_CYCLIC);
+
+		mtx_lock_spin(&cpu->cyp_mtx);
 		return;
 	}
 
@@ -722,8 +726,12 @@
 	if (old_cyclics != NULL) {
 		ASSERT(old_heap != NULL);
 		ASSERT(old_size != 0);
+		mtx_unlock_spin(&cpu->cyp_mtx);
+
 		free(old_cyclics, M_CYCLIC);
 		free(old_heap, M_CYCLIC);
+
+		mtx_lock_spin(&cpu->cyp_mtx);
 	}
 }
 
@@ -741,10 +749,10 @@
 	ASSERT(!(cpu->cyp_cpu->cpu_flags & CPU_OFFLINE));
 	ASSERT(when->cyt_when >= 0 && when->cyt_interval > 0);
 
-	if (cpu->cyp_nelems == cpu->cyp_size) {
+	while (cpu->cyp_nelems == cpu->cyp_size)
 		cyclic_expand(cpu);
-		ASSERT(cpu->cyp_nelems < cpu->cyp_size);
-	}
+
+	ASSERT(cpu->cyp_nelems < cpu->cyp_size);
 
 	nelems = cpu->cyp_nelems++;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801040513.m045DT9m024795>