Index: kernel/generic/src/sysinfo/stats.c
===================================================================
--- kernel/generic/src/sysinfo/stats.c	(revision 6e121b8c6823b53d2588dac16ca12e517fea0c94)
+++ kernel/generic/src/sysinfo/stats.c	(revision 313b6172c4a7557560500d83509400c7cf95dc2f)
@@ -110,10 +110,7 @@
 	}
 	
-	/* Each CPU structure is locked separatelly */
-	ipl_t ipl = interrupts_disable();
-	
 	size_t i;
 	for (i = 0; i < config.cpu_count; i++) {
-		spinlock_lock(&cpus[i].lock);
+		irq_spinlock_lock(&cpus[i].lock, true);
 		
 		stats_cpus[i].id = cpus[i].id;
@@ -123,8 +120,6 @@
 		stats_cpus[i].idle_ticks = cpus[i].idle_ticks;
 		
-		spinlock_unlock(&cpus[i].lock);
-	}
-	
-	interrupts_restore(ipl);
+		irq_spinlock_unlock(&cpus[i].lock, true);
+	}
 	
 	return ((void *) stats_cpus);
@@ -235,5 +230,5 @@
 	
 	/* Interrupts are already disabled */
-	spinlock_lock(&(task->lock));
+	irq_spinlock_lock(&(task->lock), false);
 	
 	/* Record the statistics and increment the iterator */
@@ -241,5 +236,5 @@
 	(*iterator)++;
 	
-	spinlock_unlock(&(task->lock));
+	irq_spinlock_unlock(&(task->lock), false);
 	
 	return true;
@@ -260,6 +255,5 @@
 {
 	/* Messing with task structures, avoid deadlock */
-	ipl_t ipl = interrupts_disable();
-	spinlock_lock(&tasks_lock);
+	irq_spinlock_lock(&tasks_lock, true);
 	
 	/* First walk the task tree to count the tasks */
@@ -269,7 +263,5 @@
 	if (count == 0) {
 		/* No tasks found (strange) */
-		spinlock_unlock(&tasks_lock);
-		interrupts_restore(ipl);
-		
+		irq_spinlock_unlock(&tasks_lock, true);
 		*size = 0;
 		return NULL;
@@ -278,6 +270,5 @@
 	*size = sizeof(stats_task_t) * count;
 	if (dry_run) {
-		spinlock_unlock(&tasks_lock);
-		interrupts_restore(ipl);
+		irq_spinlock_unlock(&tasks_lock, true);
 		return NULL;
 	}
@@ -286,7 +277,5 @@
 	if (stats_tasks == NULL) {
 		/* No free space for allocation */
-		spinlock_unlock(&tasks_lock);
-		interrupts_restore(ipl);
-		
+		irq_spinlock_unlock(&tasks_lock, true);
 		*size = 0;
 		return NULL;
@@ -297,6 +286,5 @@
 	avltree_walk(&tasks_tree, task_serialize_walker, (void *) &iterator);
 	
-	spinlock_unlock(&tasks_lock);
-	interrupts_restore(ipl);
+	irq_spinlock_unlock(&tasks_lock, true);
 	
 	return ((void *) stats_tasks);
@@ -346,5 +334,5 @@
 	
 	/* Interrupts are already disabled */
-	spinlock_lock(&thread->lock);
+	irq_spinlock_lock(&thread->lock, false);
 	
 	/* Record the statistics and increment the iterator */
@@ -352,5 +340,5 @@
 	(*iterator)++;
 	
-	spinlock_unlock(&thread->lock);
+	irq_spinlock_unlock(&thread->lock, false);
 	
 	return true;
@@ -371,6 +359,5 @@
 {
 	/* Messing with threads structures, avoid deadlock */
-	ipl_t ipl = interrupts_disable();
-	spinlock_lock(&threads_lock);
+	irq_spinlock_lock(&threads_lock, true);
 	
 	/* First walk the thread tree to count the threads */
@@ -380,7 +367,5 @@
 	if (count == 0) {
 		/* No threads found (strange) */
-		spinlock_unlock(&threads_lock);
-		interrupts_restore(ipl);
-		
+		irq_spinlock_unlock(&threads_lock, true);
 		*size = 0;
 		return NULL;
@@ -389,6 +374,5 @@
 	*size = sizeof(stats_thread_t) * count;
 	if (dry_run) {
-		spinlock_unlock(&threads_lock);
-		interrupts_restore(ipl);
+		irq_spinlock_unlock(&threads_lock, true);
 		return NULL;
 	}
@@ -397,7 +381,5 @@
 	if (stats_threads == NULL) {
 		/* No free space for allocation */
-		spinlock_unlock(&threads_lock);
-		interrupts_restore(ipl);
-		
+		irq_spinlock_unlock(&threads_lock, true);
 		*size = 0;
 		return NULL;
@@ -408,6 +390,5 @@
 	avltree_walk(&threads_tree, thread_serialize_walker, (void *) &iterator);
 	
-	spinlock_unlock(&threads_lock);
-	interrupts_restore(ipl);
+	irq_spinlock_unlock(&threads_lock, true);
 	
 	return ((void *) stats_threads);
@@ -443,12 +424,10 @@
 	
 	/* Messing with task structures, avoid deadlock */
-	ipl_t ipl = interrupts_disable();
-	spinlock_lock(&tasks_lock);
+	irq_spinlock_lock(&tasks_lock, true);
 	
 	task_t *task = task_find_by_id(task_id);
 	if (task == NULL) {
 		/* No task with this ID */
-		spinlock_unlock(&tasks_lock);
-		interrupts_restore(ipl);
+		irq_spinlock_unlock(&tasks_lock, true);
 		return ret;
 	}
@@ -459,5 +438,5 @@
 		ret.data.size = sizeof(stats_task_t);
 		
-		spinlock_unlock(&tasks_lock);
+		irq_spinlock_unlock(&tasks_lock, true);
 	} else {
 		/* Allocate stats_task_t structure */
@@ -465,6 +444,5 @@
 		    (stats_task_t *) malloc(sizeof(stats_task_t), FRAME_ATOMIC);
 		if (stats_task == NULL) {
-			spinlock_unlock(&tasks_lock);
-			interrupts_restore(ipl);
+			irq_spinlock_unlock(&tasks_lock, true);
 			return ret;
 		}
@@ -474,15 +452,12 @@
 		ret.data.data = (void *) stats_task;
 		ret.data.size = sizeof(stats_task_t);
-	
+		
 		/* Hand-over-hand locking */
-		spinlock_lock(&task->lock);
-		spinlock_unlock(&tasks_lock);
+		irq_spinlock_exchange(&tasks_lock, &task->lock);
 		
 		produce_stats_task(task, stats_task);
 		
-		spinlock_unlock(&task->lock);
-	}
-	
-	interrupts_restore(ipl);
+		irq_spinlock_unlock(&task->lock, true);
+	}
 	
 	return ret;
@@ -518,12 +493,10 @@
 	
 	/* Messing with threads structures, avoid deadlock */
-	ipl_t ipl = interrupts_disable();
-	spinlock_lock(&threads_lock);
+	irq_spinlock_lock(&threads_lock, true);
 	
 	thread_t *thread = thread_find_by_id(thread_id);
 	if (thread == NULL) {
 		/* No thread with this ID */
-		spinlock_unlock(&threads_lock);
-		interrupts_restore(ipl);
+		irq_spinlock_unlock(&threads_lock, true);
 		return ret;
 	}
@@ -534,5 +507,5 @@
 		ret.data.size = sizeof(stats_thread_t);
 		
-		spinlock_unlock(&threads_lock);
+		irq_spinlock_unlock(&threads_lock, true);
 	} else {
 		/* Allocate stats_thread_t structure */
@@ -540,6 +513,5 @@
 		    (stats_thread_t *) malloc(sizeof(stats_thread_t), FRAME_ATOMIC);
 		if (stats_thread == NULL) {
-			spinlock_unlock(&threads_lock);
-			interrupts_restore(ipl);
+			irq_spinlock_unlock(&threads_lock, true);
 			return ret;
 		}
@@ -551,13 +523,10 @@
 		
 		/* Hand-over-hand locking */
-		spinlock_lock(&thread->lock);
-		spinlock_unlock(&threads_lock);
+		irq_spinlock_exchange(&threads_lock, &thread->lock);
 		
 		produce_stats_thread(thread, stats_thread);
 		
-		spinlock_unlock(&thread->lock);
-	}
-	
-	interrupts_restore(ipl);
+		irq_spinlock_unlock(&thread->lock, true);
+	}
 	
 	return ret;
@@ -673,5 +642,5 @@
 {
 	mutex_initialize(&load_lock, MUTEX_PASSIVE);
-
+	
 	sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
 	sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
