⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 synobj.h

📁 自己动手写操作系统源代码,不可多得的代码
💻 H
字号:
//***********************************************************************/
//    Author                    : Garry
//    Original Date             : Nov 04, 2004
//    Module Name               : synobj.h
//    Module Funciton           : 
//                                This module countains synchronization object's definition
//                                code.
//                                The following synchronization object(s) is(are) defined
//                                in this file:
//                                  1. EVENT
//                                  2. MUTEX
//                                  3. SEMAPHORE
//                                  4. TIMER
//
//                                ************
//                                This file is the most important file of Hello China.
//                                ************
//    Last modified Author      :
//    Last modified Date        :
//    Last modified Content     :
//                                1.
//                                2.
//    Lines number              :
//***********************************************************************/

#ifndef __SYNOBJ_H__
#define __SYNOBJ_H__
#endif

//
//Common synchronization object's definition.
//The common synchronization object is a abstract object,all synchronization objects,such
//as event,mutex,etc,all inherited from this object.
//

BEGIN_DEFINE_OBJECT(__COMMON_SYNCHRONIZATION_OBJECT)
    DWORD                (*WaitForThisObject)(__COMMON_SYNCHRONIZATION_OBJECT*);
END_DEFINE_OBJECT()

//
//The following macro is defined to be used by other objects to inherit from
//common synchronization object.
//
#define INHERIT_FROM_COMMON_SYNCHRONIZATION_OBJECT \
	DWORD                (*WaitForThisObject)(__COMMON_OBJECT*);

//
//Event object's definition.
//The event object is inherited from common object and common synchronization object.
//

BEGIN_DEFINE_OBJECT(__EVENT)
    INHERIT_FROM_COMMON_OBJECT
	INHERIT_FROM_COMMON_SYNCHRONIZATION_OBJECT
	DWORD                 dwEventStatus;
    __PRIORITY_QUEUE*     lpWaitingQueue;
	DWORD                 (*SetEvent)(__COMMON_OBJECT*);
	DWORD                 (*ResetEvent)(__COMMON_OBJECT*);
	DWORD                 (*WaitForThisObjectEx)(__COMMON_OBJECT*,
		                                         DWORD);    //Time out waiting operation.
END_DEFINE_OBJECT()

#define EVENT_STATUS_FREE            0x00000001    //Event status.
#define EVENT_STATUS_OCCUPIED        0x00000002

//
//The following values are returned by WaitForThisObjectEx.
//
#define EVENT_WAIT_FAILED            0x00000000
#define EVENT_WAIT_RESOURCE          0x00000001
#define EVENT_WAIT_TIMEOUT           0x00000002

BOOL EventInitialize(__COMMON_OBJECT*);            //The event object's initializing routine
VOID EventUninitialize(__COMMON_OBJECT*);          //and uninitializing routine.

//
//The following routines are used by kernel thread to create event or destroy event.
//

__COMMON_OBJECT*    CreateEvent(BOOL bInitialState,LPVOID lpReserved);
VOID                DestroyEvent(__COMMON_OBJECT* lpEvent);

//--------------------------------------------------------------------------------------
//
//                                MUTEX
//
//---------------------------------------------------------------------------------------

//
//The definition of MUTEX object.
//

BEGIN_DEFINE_OBJECT(__MUTEX)
    INHERIT_FROM_COMMON_OBJECT                  //Inherit from __COMMON_OBJECT.
	INHERIT_FROM_COMMON_SYNCHRONIZATION_OBJECT  //Inherit from common synchronization object.
	DWORD             dwMutexStatus;
    DWORD             (*ReleaseMutex)(__COMMON_OBJECT* lpThis);
END_DEFINE_OBJECT()

#define MUTEX_STATUS_FREE      0x00000001
#define MUTEX_STATUS_OCCUPIED  0x00000002

//
//The initializing routine of MUTEX object and uninitializing routine.
//

BOOL MutexInitialize(__COMMON_OBJECT* lpThis);
VOID MutexUninitialize(__COMMON_OBJECT* lpThis);

//
//The following global routines are used to operate mutex object,including create a mutex
//and destroy a mutex object.
//

__COMMON_OBJECT*    CreateMutex(LPVOID lpReserved);
VOID                DestroyMutex(__COMMON_OBJECT* lpMutexObject);


//-----------------------------------------------------------------------------------
//
//                            SEMAPHORE
//
//-----------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -