- Remove ROSRTL. The era is over. Thanks to Filip for his help during the last month.
Modified: trunk/reactos/drivers/net/tcpip/include/precomp.h
Added: trunk/reactos/drivers/net/tcpip/recmutex/
Added: trunk/reactos/drivers/net/tcpip/recmutex/recmutex.c
Added: trunk/reactos/drivers/net/tcpip/recmutex/recmutex.h
Modified: trunk/reactos/drivers/net/tcpip/tcpip.xml
Deleted: trunk/reactos/include/rosrtl/
Modified: trunk/reactos/lib/directory.xml
Modified: trunk/reactos/lib/dnsapi/dnsapi.xml
Modified: trunk/reactos/lib/gdi32/gdi32.xml
Modified: trunk/reactos/lib/kernel32/kernel32.xml
Modified: trunk/reactos/lib/kernel32/tests/kernel32.xml
Modified: trunk/reactos/lib/ntdll/ntdll.xml
Deleted: trunk/reactos/lib/rosrtl/
Added: trunk/reactos/lib/rtl/qsort.c
Modified: trunk/reactos/lib/rtl/rtl.xml
Modified: trunk/reactos/lib/user32/user32.xml
Modified: trunk/reactos/ntoskrnl/ntoskrnl.xml
Modified: trunk/reactos/subsys/win32k/tests/win32k.xml
Modified: trunk/reactos/subsys/win32k/win32k.xml

Modified: trunk/reactos/drivers/net/tcpip/include/precomp.h
--- trunk/reactos/drivers/net/tcpip/include/precomp.h	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/drivers/net/tcpip/include/precomp.h	2005-07-26 04:52:11 UTC (rev 16731)
@@ -1,7 +1,7 @@
 #include <roscfg.h>
 #include <limits.h>
 #include <ddk/ntddk.h>
-#include <rosrtl/recmutex.h>
+#include <../recmutex/recmutex.h>
 #include <roscfg.h>
 #include <tcpip.h>
 #include <loopback.h>

Copied: trunk/reactos/drivers/net/tcpip/recmutex/recmutex.c (from rev 16725, trunk/reactos/lib/rosrtl/recmutex/recmutex.c)
--- trunk/reactos/lib/rosrtl/recmutex/recmutex.c	2005-07-25 20:28:29 UTC (rev 16725)
+++ trunk/reactos/drivers/net/tcpip/recmutex/recmutex.c	2005-07-26 04:52:11 UTC (rev 16731)
@@ -0,0 +1,83 @@
+#include <ddk/ntddk.h>
+#include "recmutex.h"
+
+VOID RecursiveMutexInit( PRECURSIVE_MUTEX RecMutex ) {
+    RtlZeroMemory( RecMutex, sizeof(*RecMutex) );
+    KeInitializeSpinLock( &RecMutex->SpinLock );
+    ExInitializeFastMutex( &RecMutex->Mutex );
+    KeInitializeEvent( &RecMutex->StateLockedEvent, 
+		       NotificationEvent, FALSE );    
+}
+
+/* NOTE: When we leave, the FAST_MUTEX must have been released.  The result
+ * is that we always exit in the same irql as entering */
+UINT RecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex, BOOL ToWrite ) {
+    NTSTATUS Status = STATUS_SUCCESS;
+    PVOID CurrentThread = KeGetCurrentThread();
+
+    /* Wait for the previous user to unlock the RecMutex state.  There might be
+     * multiple waiters waiting to change the state.  We need to check each
+     * time we get the event whether somebody still has the state locked */
+
+    if( !RecMutex ) return FALSE;
+
+    if( CurrentThread == RecMutex->CurrentThread || 
+	(!ToWrite && !RecMutex->Writer) ) {
+	RecMutex->LockCount++;
+	return TRUE;
+    }
+
+    if( KeGetCurrentIrql() == PASSIVE_LEVEL ) {
+	ExAcquireFastMutex( &RecMutex->Mutex );
+	RecMutex->OldIrql = PASSIVE_LEVEL;
+	while( RecMutex->Locked ) {
+	    ExReleaseFastMutex( &RecMutex->Mutex );
+	    Status = KeWaitForSingleObject( &RecMutex->StateLockedEvent,
+					    UserRequest,
+					    KernelMode,
+					    FALSE,
+					    NULL );
+	    ExAcquireFastMutex( &RecMutex->Mutex );
+	    if( Status == STATUS_SUCCESS ) break;
+	}
+	RecMutex->Locked = TRUE;
+	RecMutex->Writer = ToWrite;
+	RecMutex->CurrentThread = CurrentThread;
+	RecMutex->LockCount++;
+	ExReleaseFastMutex( &RecMutex->Mutex );
+    } else {
+	KeAcquireSpinLock( &RecMutex->SpinLock, &RecMutex->OldIrql );
+	RecMutex->Locked = TRUE;
+	RecMutex->Writer = ToWrite;
+	RecMutex->CurrentThread = CurrentThread;
+	RecMutex->LockCount++;
+    }
+
+    return TRUE;
+}
+
+VOID RecursiveMutexLeave( PRECURSIVE_MUTEX RecMutex ) {
+    if( RecMutex->LockCount == 0 ) {
+	return;
+    } else
+	RecMutex->LockCount--;
+
+    if( !RecMutex->LockCount ) {
+	RecMutex->CurrentThread = NULL;
+	if( RecMutex->OldIrql == PASSIVE_LEVEL ) {
+	    ExAcquireFastMutex( &RecMutex->Mutex );
+	    RecMutex->Locked = FALSE;
+	    RecMutex->Writer = FALSE;
+	    ExReleaseFastMutex( &RecMutex->Mutex );
+	} else {
+	    RecMutex->Locked = FALSE;
+	    RecMutex->Writer = FALSE;
+	    KeReleaseSpinLock( &RecMutex->SpinLock, RecMutex->OldIrql );
+	}
+
+	RecMutex->OldIrql = PASSIVE_LEVEL;
+	KePulseEvent( &RecMutex->StateLockedEvent, IO_NETWORK_INCREMENT, 
+		      FALSE );
+    }
+}
+

Copied: trunk/reactos/drivers/net/tcpip/recmutex/recmutex.h (from rev 16725, trunk/reactos/include/rosrtl/recmutex.h)

Modified: trunk/reactos/drivers/net/tcpip/tcpip.xml
--- trunk/reactos/drivers/net/tcpip/tcpip.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/drivers/net/tcpip/tcpip.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -8,7 +8,6 @@
 	<library>ip</library>
 	<library>oskittcp</library>
 	<library>ndis</library>
-	<library>rosrtl</library>
 	<library>pseh</library>
 	<library>ntoskrnl</library>
 	<library>hal</library>
@@ -18,6 +17,9 @@
 	<directory name="datalink">
 		<file>lan.c</file>
 	</directory>
+	<directory name="recmutex">
+		<file>recmutex.c</file>
+	</directory>
 	<directory name="tcpip">
 		<file>buffer.c</file>
 		<file>bug.c</file>

Modified: trunk/reactos/lib/directory.xml
--- trunk/reactos/lib/directory.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/lib/directory.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -214,9 +214,6 @@
 <directory name="riched20">
 	<xi:include href="riched20/riched20.xml" />
 </directory>
-<directory name="rosrtl">
-	<xi:include href="rosrtl/rosrtl.xml" />
-</directory>
 <directory name="rossym">
 	<xi:include href="rossym/rossym.xml" />
 </directory>

Modified: trunk/reactos/lib/dnsapi/dnsapi.xml
--- trunk/reactos/lib/dnsapi/dnsapi.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/lib/dnsapi/dnsapi.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -7,7 +7,6 @@
 	<define name="ADNS_JGAA_WIN32" />
 	<define name="__USE_W32API" />
 	<library>adns</library>
-	<library>rosrtl</library>
 	<library>ntdll</library>
 	<library>kernel32</library>
 	<library>user32</library>

Modified: trunk/reactos/lib/gdi32/gdi32.xml
--- trunk/reactos/lib/gdi32/gdi32.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/lib/gdi32/gdi32.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -7,7 +7,6 @@
 	<define name="WINVER">0x0600</define>
 	<define name="_WIN32_WINNT">0x0501</define>
 	<library>ntdll</library>
-	<library>rosrtl</library>
 	<library>kernel32</library>
 	<library>advapi32</library>
 	<directory name="include">

Modified: trunk/reactos/lib/kernel32/kernel32.xml
--- trunk/reactos/lib/kernel32/kernel32.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/lib/kernel32/kernel32.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -118,7 +118,6 @@
 	<define name="WINVER">0x0500</define>
 	<library>kernel32_base</library>
 	<library>pseh</library>
-	<library>rosrtl</library>
 	<library>intrlck</library>
 	<library>ntdll</library>
 	<linkerflag>-lgcc</linkerflag>

Modified: trunk/reactos/lib/kernel32/tests/kernel32.xml
--- trunk/reactos/lib/kernel32/tests/kernel32.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/lib/kernel32/tests/kernel32.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -10,7 +10,6 @@
 	<library>regtests</library>
 	<library>kernel32_base</library>
 	<library>pseh</library>
-	<library>rosrtl</library>
 	<library>ntdll</library>
 	<library>msvcrt</library>
 	<linkerflag>-lgcc</linkerflag>

Modified: trunk/reactos/lib/ntdll/ntdll.xml
--- trunk/reactos/lib/ntdll/ntdll.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/lib/ntdll/ntdll.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -8,7 +8,6 @@
 	<define name="_WIN32_WINNT">0x0502</define>
 	<define name="_NTOSKRNL_" />
 	<library>rtl</library>
-	<library>rosrtl</library>
 	<library>intrlck</library>
 	<library>string</library>
 	<linkerflag>-lgcc</linkerflag>

Added: trunk/reactos/lib/rtl/qsort.c
--- trunk/reactos/lib/rtl/qsort.c	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/lib/rtl/qsort.c	2005-07-26 04:52:11 UTC (rev 16731)
@@ -0,0 +1,266 @@
+/* $Id: qsort.c 12852 2005-01-06 13:58:04Z mf $
+ * 
+ * FILE: ntoskrnl/rtl/qsort.c
+ * NOTE: Adapted from CygWin newlib 2000-03-12.
+ */
+/*
+FUNCTION
+<<qsort>>---sort an array
+
+INDEX
+	qsort
+
+ANSI_SYNOPSIS
+	#include <stdlib.h>
+	void qsort(void *<[base]>, size_t <[nmemb]>, size_t <[size]>,
+		   int (*<[compar]>)(const void *, const void *) );
+
+TRAD_SYNOPSIS
+	#include <stdlib.h>
+	qsort(<[base]>, <[nmemb]>, <[size]>, <[compar]> )
+	char *<[base]>;
+	size_t <[nmemb]>;
+	size_t <[size]>;
+	int (*<[compar]>)();
+
+DESCRIPTION
+<<qsort>> sorts an array (beginning at <[base]>) of <[nmemb]> objects.
+<[size]> describes the size of each element of the array.
+
+You must supply a pointer to a comparison function, using the argument
+shown as <[compar]>.  (This permits sorting objects of unknown
+properties.)  Define the comparison function to accept two arguments,
+each a pointer to an element of the array starting at <[base]>.  The
+result of <<(*<[compar]>)>> must be negative if the first argument is
+less than the second, zero if the two arguments match, and positive if
+the first argument is greater than the second (where ``less than'' and
+``greater than'' refer to whatever arbitrary ordering is appropriate).
+
+The array is sorted in place; that is, when <<qsort>> returns, the
+array elements beginning at <[base]> have been reordered.
+
+RETURNS
+<<qsort>> does not return a result.
+
+PORTABILITY
+<<qsort>> is required by ANSI (without specifying the sorting algorithm).
+*/
+
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __GNUC__
+#define inline
+#endif
+
+/* FIXME: these types should be from the default includes */
+
+typedef int (* 	_pfunccmp_t) (char *, char *);
+typedef int size_t;
+
+#define min(a,b) ((a)<(b)?(a):(b))
+
+/*
+ * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
+ */
+#define swapcode(TYPE, parmi, parmj, n) { 		\
+	long i = (n) / sizeof (TYPE); 			\
+	register TYPE *pi = (TYPE *) (parmi); 		\
+	register TYPE *pj = (TYPE *) (parmj); 		\
+	do { 						\
+		register TYPE	t = *pi;		\
+		*pi++ = *pj;				\
+		*pj++ = t;				\
+        } while (--i > 0);				\
+}
+
+#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
+	es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
+
+static inline void
+swapfunc (
+	char	* a,
+	char	* b,
+	int	n,
+	int	swaptype
+	)
+{
+	if(swaptype <= 1) 
+		swapcode(long, a, b, n)
+	else
+		swapcode(char, a, b, n)
+}
+
+#define swap(a, b)					\
+	if (swaptype == 0) {				\
+		long t = *(long *)(a);			\
+		*(long *)(a) = *(long *)(b);		\
+		*(long *)(b) = t;			\
+	} else						\
+		swapfunc(a, b, es, swaptype)
+
+#define vecswap(a, b, n) 	if ((n) > 0) swapfunc(a, b, n, swaptype)
+
+static inline char *
+med3 (
+	char		* a,
+	char		* b,
+	char		* c,
+	_pfunccmp_t	cmp
+	)
+{
+	return cmp(a, b) < 0 ?
+	       (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
+              :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
+}
+
+
+/* EXPORTED */
+void
+qsort (
+	void		* a,
+	size_t		n,
+	size_t		es,
+	_pfunccmp_t	cmp
+	)
+{
+	char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
+	int d, r, swaptype, swap_cnt;
+
+loop:	SWAPINIT(a, es);
+	swap_cnt = 0;
+	if (n < 7)
+	{
+		for (	pm = (char *) a + es;
+			pm < (char *) a + n * es;
+			pm += es
+			)
+		{
+			for (	pl = pm;
+				pl > (char *) a && cmp(pl - es, pl) > 0;
+				pl -= es
+				)
+			{
+				swap(pl, pl - es);
+			}
+		}
+		return;
+	}
+	pm = (char *) a + (n / 2) * es;
+	if (n > 7)
+	{
+		pl = (char *) a;
+		pn = (char *) a + (n - 1) * es;
+		if (n > 40)
+		{
+			d = (n / 8) * es;
+			pl = med3(pl, pl + d, pl + 2 * d, cmp);
+			pm = med3(pm - d, pm, pm + d, cmp);
+			pn = med3(pn - 2 * d, pn - d, pn, cmp);
+		}
+		pm = med3(pl, pm, pn, cmp);
+	}
+	swap(a, pm);
+	pa = pb = (char *) a + es;
+
+	pc = pd = (char *) a + (n - 1) * es;
+	for (;;)
+	{
+		while (pb <= pc && (r = cmp(pb, a)) <= 0)
+		{
+			if (r == 0)
+			{
+				swap_cnt = 1;
+				swap(pa, pb);
+				pa += es;
+			}
+			pb += es;
+		}
+		while (pb <= pc && (r = cmp(pc, a)) >= 0)
+		{
+			if (r == 0)
+			{
+				swap_cnt = 1;
+				swap(pc, pd);
+				pd -= es;
+			}
+			pc -= es;
+		}
+		if (pb > pc)
+		{
+			break;
+		}
+		swap(pb, pc);
+		swap_cnt = 1;
+		pb += es;
+		pc -= es;
+	}
+	if (swap_cnt == 0)  /* Switch to insertion sort */
+	{
+		for (	pm = (char *) a + es;
+			pm < (char *) a + n * es;
+			pm += es
+			)
+		{
+			for (	pl = pm;
+				pl > (char *) a && cmp(pl - es, pl) > 0; 
+				pl -= es
+				)
+			{
+				swap(pl, pl - es);
+			}
+		}
+		return;
+	}
+
+	pn = (char *) a + n * es;
+	r = min(pa - (char *)a, pb - pa);
+	vecswap(a, pb - r, r);
+	r = min(pd - pc, pn - pd - es);
+	vecswap(pb, pn - r, r);
+	if ((r = pb - pa) > es)
+	{
+		qsort(a, r / es, es, cmp);
+	}
+	if ((r = pd - pc) > es)
+	{ 
+		/* Iterate rather than recurse to save stack space */
+		a = pn - r;
+		n = r / es;
+		goto loop;
+	}
+/*		qsort(pn - r, r / es, es, cmp);*/
+}
+
+
+/* EOF */

Modified: trunk/reactos/lib/rtl/rtl.xml
--- trunk/reactos/lib/rtl/rtl.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/lib/rtl/rtl.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -37,6 +37,7 @@
 	<file>nls.c</file>
 	<file>ppb.c</file>
 	<file>process.c</file>
+	<file>qsort.c</file>
 	<file>random.c</file>
 	<file>registry.c</file>
 	<file>sd.c</file>

Modified: trunk/reactos/lib/user32/user32.xml
--- trunk/reactos/lib/user32/user32.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/lib/user32/user32.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -11,7 +11,6 @@
 	<library>wine</library>
 	<library>ntdll</library>
 	<library>gdi32</library>
-	<library>rosrtl</library>
 	<library>kernel32</library>
 	<library>advapi32</library>
 	<directory name="include">

Modified: trunk/reactos/ntoskrnl/ntoskrnl.xml
--- trunk/reactos/ntoskrnl/ntoskrnl.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/ntoskrnl/ntoskrnl.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -14,7 +14,6 @@
 	<library>kjs</library>
 	<library>pseh</library>
 	<library>rtl</library>
-	<library>rosrtl</library>
 	<library>rossym</library>
 	<library>string</library>
 	<library>wdmguid</library>

Modified: trunk/reactos/subsys/win32k/tests/win32k.xml
--- trunk/reactos/subsys/win32k/tests/win32k.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/subsys/win32k/tests/win32k.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -14,7 +14,6 @@
 	<library>regtests</library>
 	<library>win32k_base</library>
 	<library>pseh</library>
-	<library>rosrtl</library>
 	<directory name="tests">
 		<file>DIB_24BPP_ColorFill-performance.c</file>
 	</directory>

Modified: trunk/reactos/subsys/win32k/win32k.xml
--- trunk/reactos/subsys/win32k/win32k.xml	2005-07-26 04:14:10 UTC (rev 16730)
+++ trunk/reactos/subsys/win32k/win32k.xml	2005-07-26 04:52:11 UTC (rev 16731)
@@ -132,7 +132,6 @@
 	<importlibrary definition="win32k.def" />
 	<library>win32k_base</library>
 	<library>pseh</library>
-	<library>rosrtl</library>
 	<library>ntoskrnl</library>
 	<library>hal</library>
 	<library>freetype</library>