Index: trunk/kernel/mm/page.c
===================================================================
--- trunk/kernel/mm/page.c	(revision 486)
+++ trunk/kernel/mm/page.c	(revision 567)
@@ -27,15 +27,11 @@
 #include <hal_atomic.h>
 #include <list.h>
-#include <xlist.h>
+#include <queuelock.h>
 #include <memcpy.h>
-#include <thread.h>
-#include <scheduler.h>
-#include <cluster.h>
-#include <ppm.h>
-#include <mapper.h>
 #include <printk.h>
 #include <vfs.h>
 #include <process.h>
 #include <page.h>
+
 
 ////////////////////////////////////////
@@ -49,7 +45,7 @@
 	page->forks    = 0;
 
-	spinlock_init( &page->lock );
+	remote_busylock_init( XPTR( local_cxy , &page->lock ), LOCK_PAGE_STATE );
+
 	list_entry_init( &page->list );
-    xlist_root_init( XPTR( local_cxy , &page->wait_root ) );
 }
 
@@ -73,149 +69,4 @@
 {
     return ( (page->flags & value) ? 1 : 0 );
-}
-
-//////////////////////////////////////
-bool_t page_do_dirty( page_t * page )
-{
-	bool_t done = false;
-
-	ppm_t * ppm = &LOCAL_CLUSTER->ppm;
-
-	// lock the PPM dirty_list
-	spinlock_lock( &ppm->dirty_lock );
-
-	if( !page_is_flag( page , PG_DIRTY ) )
-	{
-		// set dirty flag in page descriptor
-		page_set_flag( page , PG_DIRTY );
-
-		// register page in PPM dirty list
-		list_add_first( &ppm->dirty_root , &page->list );
-		done = true;
-	}
-
-	// unlock the PPM dirty_list
-	spinlock_unlock( &ppm->dirty_lock );
-
-	return done;
-}
-
-////////////////////////////////////////
-bool_t page_undo_dirty( page_t * page )
-{
-	bool_t done = false;
-
-	ppm_t * ppm = &LOCAL_CLUSTER->ppm;
-
-	// lock the dirty_list
-	spinlock_lock( &ppm->dirty_lock );
-
-	if( page_is_flag( page , PG_DIRTY) )
-	{
-		// clear dirty flag in page descriptor
-		page_clear_flag( page , PG_DIRTY );
-
-		// remove page from PPM dirty list
-		list_unlink( &page->list );
-		done = true;
-	}
-
-	// unlock the dirty_list
-	spinlock_unlock( &ppm->dirty_lock );
-
-	return done;
-}
-
-/////////////////////
-void sync_all_pages( void )
-{
-	page_t   * page;
-	ppm_t    * ppm = &LOCAL_CLUSTER->ppm;
-
-	// lock the dirty_list
-	spinlock_lock( &ppm->dirty_lock );
-
-	while( !list_is_empty( &ppm->dirty_root ) )
-	{
-		page = LIST_FIRST( &ppm->dirty_root ,  page_t , list );
-
-		// unlock the dirty_list
-		spinlock_unlock( &ppm->dirty_lock );
-
-		// lock the page
-		page_lock( page );
-
-		// sync the page
-		vfs_mapper_move_page( page , false );  // from mapper
-
-		// unlock the page
-		page_unlock( page );
-
-		// lock the dirty_list
-		spinlock_lock( &ppm->dirty_lock );
-	}
-
-	// unlock the dirty_list
-	spinlock_unlock( &ppm->dirty_lock );
-
-}
-
-///////////////////////////////
-void page_lock( page_t * page )
-{
-	// take the spinlock protecting the PG_LOCKED flag
-	spinlock_lock( &page->lock );
-
-	if( page_is_flag( page , PG_LOCKED ) )  // page is already locked
-	{
-		// get pointer on calling thread
-		thread_t * thread = CURRENT_THREAD;
-
-		// register thread in the page waiting queue
-		xlist_add_last( XPTR( local_cxy , &page->wait_root ),
-		                XPTR( local_cxy , &thread->wait_list ) );
-
-		// release the spinlock
-		spinlock_unlock( &page->lock );
-
-		// deschedule the calling thread
-		thread_block( XPTR( local_cxy , thread ) , THREAD_BLOCKED_PAGE );
-		sched_yield("cannot lock a page");
-	}
-	else                                    // page is not locked
-	{
-		// set the PG_LOCKED flag
-		page_set_flag( page , PG_LOCKED );
-
-		// release the spinlock
-		spinlock_unlock( &page->lock );
-	}
-}
-
-/////////////////////////////////
-void page_unlock( page_t * page )
-{
-	// take the spinlock protecting the PG_LOCKED flag
-	spinlock_lock( &page->lock );
-
-	// check the page waiting list
-	bool_t is_empty = xlist_is_empty( XPTR( local_cxy , &page->wait_root ) );
-
-	if( is_empty == false )    // at least one waiting thread => resume it
-	{
-		// get an extended pointer on the first waiting thread
-		xptr_t root_xp   = XPTR( local_cxy , &page->wait_root );
-		xptr_t thread_xp = XLIST_FIRST_ELEMENT( root_xp , thread_t , wait_list );
-
-		// reactivate the first waiting thread
-		thread_unblock( thread_xp , THREAD_BLOCKED_PAGE );
-	}
-	else                      // no waiting thread => clear the PG_LOCKED flag
-	{
-		page_clear_flag( page , PG_LOCKED );
-	}
-
-	// release the spinlock
-	spinlock_unlock( &page->lock );
 }
 
