Added mutex test application.

svn path=/trunk/; revision=2358
This commit is contained in:
Eric Kohl 2001-11-07 16:42:15 +00:00
parent 679c19d7f8
commit 1355fed119
4 changed files with 145 additions and 1 deletions

View file

@ -68,7 +68,7 @@ SYS_APPS = services shell winlogon
APPS = args hello test cat bench apc shm lpc thread event file gditest \
pteb consume dump_shared_data vmtest regtest alive mstest nptest \
objdir atomtest winhello partinfo
objdir atomtest winhello partinfo mutex
#NET_APPS = ping roshttpd telnet
NET_APPS = ping roshttpd

View file

@ -0,0 +1,22 @@
#
# $Id: makefile,v 1.1 2001/11/07 16:40:58 ekohl Exp $
PATH_TO_TOP = ../..
TARGET_NORC = yes
TARGET_TYPE = program
TARGET_APPTYPE = console
TARGET_NAME = mutex
TARGET_SDKLIBS = ntdll.a kernel32.a
TARGET_OBJECTS = $(TARGET_NAME).o
include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk
# EOF

View file

@ -0,0 +1,116 @@
#include <ddk/ntddk.h>
#include <windows.h>
#include <string.h>
#include <stdio.h>
HANDLE OutputHandle;
HANDLE InputHandle;
HANDLE hThread[2];
DWORD dwCounter = 0;
HANDLE hMutex;
void dprintf(char* fmt, ...)
{
va_list args;
char buffer[255];
va_start(args,fmt);
vsprintf(buffer,fmt,args);
WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
va_end(args);
}
DWORD WINAPI thread1(LPVOID crap)
{
DWORD dwError = 0;
DWORD i;
dprintf("Thread 1 running!\n");
for (i = 0; i < 10; i++)
{
dwError = WaitForSingleObject(hMutex, INFINITE);
if (dwError == WAIT_FAILED)
{
dprintf("Thread2: WaitForSingleObject failed!\n");
return 1;
}
else if (dwError == WAIT_ABANDONED_0)
{
dprintf("Thread2: WaitForSingleObject returned WAIT_ABANDONED_0\n");
}
dprintf("Thread1: dwCounter : %lu -->", dwCounter);
dwCounter++;
dprintf(" %lu\n", dwCounter);
ReleaseMutex(hMutex);
}
return 1;
}
DWORD WINAPI thread2(LPVOID crap)
{
DWORD dwError = 0;
DWORD i;
dprintf("Thread 2 running!\n");
for (i = 0; i < 10; i++)
{
dwError = WaitForSingleObject(hMutex, INFINITE);
if (dwError == WAIT_FAILED)
{
dprintf("Thread2: WaitForSingleObject failed!\n");
return 1;
}
else if (dwError == WAIT_ABANDONED_0)
{
dprintf("Thread2: WaitForSingleObject returned WAIT_ABANDONED_0\n");
}
dprintf("Thread2: dwCounter : %lu -->", dwCounter);
dwCounter++;
dprintf(" %lu\n", dwCounter);
ReleaseMutex(hMutex);
}
return 1;
}
int main(int argc, char* argv[])
{
DWORD dwError;
DWORD id1,id2;
AllocConsole();
InputHandle = GetStdHandle(STD_INPUT_HANDLE);
OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
dprintf("Calling CreateMutex()\n");
hMutex = CreateMutexW(NULL, FALSE, L"TestMutex");
if (hMutex == INVALID_HANDLE_VALUE)
{
dprintf("CreateMutex() failed! Error: %lu\n", GetLastError);
return 0;
}
dprintf("CreateMutex() succeeded!\n");
hThread[0] = CreateThread(0, 0, thread1, 0, 0, &id1);
hThread[1] = CreateThread(0, 0, thread2, 0, 0, &id2);
dprintf("Calling WaitForMultipleObject()\n");
dwError = WaitForMultipleObjects(2, hThread, TRUE, INFINITE);
dprintf("WaitForMultipleObject() Error: %lu\n", dwError);
CloseHandle(hThread[0]);
CloseHandle(hThread[1]);
CloseHandle(hMutex);
return 0;
}

View file

@ -17,6 +17,8 @@ md %ROS_INSTALL%\system32\drivers
md %ROS_INSTALL%\media
md %ROS_INSTALL%\media\fonts
copy boot.bat %ROS_INSTALL%
copy aboot.bat %ROS_INSTALL%
copy boot.hiv %ROS_INSTALL%
copy loaders\dos\loadros.com %ROS_INSTALL%
copy ntoskrnl\ntoskrnl.exe %ROS_INSTALL%\system32
copy hal\halx86\hal.dll %ROS_INSTALL%\system32
@ -40,6 +42,8 @@ copy services\net\dd\ne2000\ne2000.sys %ROS_INSTALL%\system32\drivers
copy services\net\ndis\ndis.sys %ROS_INSTALL%\system32\drivers
copy services\net\tcpip\tcpip.sys %ROS_INSTALL%\system32\drivers
copy services\net\wshtcpip\wshtcpip.dll %ROS_INSTALL%\system32
copy services\storage\atapi\atapi.sys %ROS_INSTALL%\system32\drivers
copy services\storage\scsiport\scsiport.sys %ROS_INSTALL%\system32\drivers
copy apps\system\shell\shell.exe %ROS_INSTALL%\system32
copy apps\system\winlogon\winlogon.exe %ROS_INSTALL%\system32
copy apps\system\services\services.exe %ROS_INSTALL%\system32
@ -78,6 +82,8 @@ copy apps\nptest\npserver.exe %ROS_INSTALL%\bin
copy apps\nptest\npclient.exe %ROS_INSTALL%\bin
copy apps\atomtest\atomtest.exe %ROS_INSTALL%\bin
copy apps\partinfo\partinfo.exe %ROS_INSTALL%\bin
copy apps\objdir\objdir.exe %ROS_INSTALL%\bin
copy apps\mutex\mutex.exe %ROS_INSTALL%\bin
copy apps\net\ping\ping.exe %ROS_INSTALL%\bin
copy apps\net\roshttpd\roshttpd.exe %ROS_INSTALL%\bin
copy apps\net\telnet\telnet.exe %ROS_INSTALL%\bin