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

📄 async.c

📁 This is a java virtual machine implement in c
💻 C
字号:
/*0001*//*
/*0002./ * Copyright (c) 1998-2001 Sun Microsystems, Inc. All Rights Reserved.
/*0003./ *
/*0004./ * This software is the confidential and proprietary information of Sun
/*0005./ * Microsystems, Inc. ("Confidential Information").  You shall not
/*0006./ * disclose such Confidential Information and shall use it only in
/*0007./ * accordance with the terms of the license agreement you entered into
/*0008./ * with Sun.
/*0009./ *
/*0010./ * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
/*0011./ * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
/*0012./ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/*0013./ * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
/*0014./ * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
/*0015./ * THIS SOFTWARE OR ITS DERIVATIVES.
/*0016./ *
/*0017./ */
/*0018*/
/*0019*//*=========================================================================
/*0020./ * SYSTEM:    KVM
/*0021./ * SUBSYSTEM: KVM
/*0022./ * FILE:      async.c
/*0023./ * OVERVIEW:  Functions to support asynchronous I/O
/*0024./ * AUTHOR:    Nik Shaylor, Sun C&E
/*0025./ *=======================================================================*/
/*0026*/
/*0027*//*=========================================================================
/*0028./ * Include files
/*0029./ *=======================================================================*/
/*0030*/
/*0031*/#include <global.h>
/*0032*/#include <async.h>
/*0033*/
/*0034*//*=========================================================================
/*0035./ * Variables
/*0036./ *=======================================================================*/
/*0037*/
/*0038*/ASYNCIOCB  IocbRoots[ASYNC_IOCB_COUNT];
/*0039*/ASYNCIOCB *IocbFreeList = 0;
/*0040*/
/*0041*//*=========================================================================
/*0042./ * Functions
/*0043./ *=======================================================================*/
/*0044*/
/*0045*//*=========================================================================
/*0046./ * FUNCTION:      AcquireAsyncIOCB()
/*0047./ * TYPE:          Public routine for asynchronous native methods
/*0048./ * OVERVIEW:      Allocate an Acync I/O control block
/*0049./ * INTERFACE:
/*0050./ *   parameters:  <none>
/*0051./ *   returns:     An ASYNCIOCB
/*0052./ *=======================================================================*/
/*0053*/
/*0054*/ASYNCIOCB *AcquireAsyncIOCB(void) {
/*0055*/    ASYNCIOCB *result = 0;
/*0056*/    while (result == 0) {
/*0057*/        START_CRITICAL_SECTION
/*0058*/            if (IocbFreeList != 0) {
/*0059*/                result       = IocbFreeList;
/*0060*/                IocbFreeList = IocbFreeList->nextFree;
/*0061*/                result->nextFree = 0;
/*0062*/            }
/*0063*/        END_CRITICAL_SECTION
/*0064*/        if (result == 0) {
/*0065*/            Yield_md();
/*0066*/        }
/*0067*/    }
/*0068*/    if (result->thread != 0) {
/*0069*/        fatalError("Problem in AcquireAsyncIOCB");
/*0070*/    }
/*0071*/    result->thread = CurrentThread;
/*0072*/    asyncFunctionProlog();
/*0073*/    return result;
/*0074*/}
/*0075*/
/*0076*//*=========================================================================
/*0077./ * FUNCTION:      FreeAsyncIOCB()
/*0078./ * TYPE:          Private routine for asynchronous native methods
/*0079./ * OVERVIEW:      Free an Acync I/O control block
/*0080./ * INTERFACE:
/*0081./ *   parameters:  An ASYNCIOCB
/*0082./ *   returns:     <nothing>
/*0083./ *=======================================================================*/
/*0084*/
/*0085*/static void FreeAsyncIOCB(ASYNCIOCB *aiocb) {
/*0086*/    aiocb->thread       = 0;
/*0087*/    aiocb->instance     = 0;
/*0088*/    aiocb->array        = 0;
/*0089*/    aiocb->exception    = 0;
/*0090*/    aiocb->nextFree     = IocbFreeList;
/*0091*/    IocbFreeList        = aiocb;
/*0092*/}
/*0093*/
/*0094*//*=========================================================================
/*0095./ * FUNCTION:      AbortAsyncIOCB()
/*0096./ * TYPE:          Public routine for asynchronous native methods
/*0097./ * OVERVIEW:      Free an Acync I/O control block
/*0098./ * INTERFACE:
/*0099./ *   parameters:  An ASYNCIOCB
/*0100./ *   returns:     <nothing>
/*0101./ *=======================================================================*/
/*0102*/
/*0103*/void AbortAsyncIOCB(ASYNCIOCB *aiocb) {
/*0104*/    START_CRITICAL_SECTION
/*0105*/        FreeAsyncIOCB(aiocb);
/*0106*/    END_CRITICAL_SECTION
/*0107*/}
/*0108*/
/*0109*//*=========================================================================
/*0110./ * FUNCTION:      ReleaseAsyncIOCB()
/*0111./ * TYPE:          Public routine for asynchronous native methods
/*0112./ * OVERVIEW:      Free an Acync I/O control block
/*0113./ * INTERFACE:
/*0114./ *   parameters:  An ASYNCIOCB
/*0115./ *   returns:     <nothing>
/*0116./ *=======================================================================*/
/*0117*/
/*0118*/void ReleaseAsyncIOCB(ASYNCIOCB *aiocb) {
/*0119*/    if (aiocb->thread == 0) {
/*0120*/        fatalError("Problem in ReleaseAsyncIOCB");
/*0121*/    }
/*0122*/    asyncFunctionEpilog(aiocb->thread);
/*0123*/    AbortAsyncIOCB(aiocb);
/*0124*/}
/*0125*/
/*0126*//*=========================================================================
/*0127./ * FUNCTION:      ActiveAsyncOperations()
/*0128./ * TYPE:          Private routine for asynchronous native methods
/*0129./ * OVERVIEW:      Return the number of active IOCBs
/*0130./ * INTERFACE:
/*0131./ *   parameters:  <none>
/*0132./ *   returns:     Number of active IOCBs
/*0133./ *=======================================================================*/
/*0134*/
/*0135*/static int ActiveAsyncOperations() {
/*0136*/    int active = ASYNC_IOCB_COUNT;
/*0137*/    ASYNCIOCB *aiocb = IocbFreeList;
/*0138*/    while (aiocb != 0) {
/*0139*/        aiocb = aiocb->nextFree;
/*0140*/        active--;
/*0141*/    }
/*0142*/    return active;
/*0143*/}
/*0144*/
/*0145*//*=========================================================================
/*0146./ * FUNCTION:      InitalizeAsynchronousIO()
/*0147./ * TYPE:          Public routine for asynchronous native methods
/*0148./ * OVERVIEW:      Initialize the system
/*0149./ * INTERFACE:
/*0150./ *   parameters:  <none>
/*0151./ *   returns:     <nothing>
/*0152./ *=======================================================================*/
/*0153*/
/*0154*//*
/*0155./ * A brief explanation of "VersionOfTheWorld"
/*0156./ *
/*0157./ * This variable is incremented every time InitalizeAsynchronousIO is called.
/*0158./ * The first time the code will initialize the queue of IOCBs. The subsequent
/*0159./ * times the code will wait for any I/O activity to end before returning.
/*0160./ *
/*0161./ * The only systems that need this feature are those who restart the VM after
/*0162./ * it has ended, These are only the test suites used by CLDC and MIDP.
/*0163./ *
/*0164./ * The implication is that these systems must correctly rundown all async I/O
/*0165./ * before starting up a new VM. This is typically done by the native function
/*0166./ * finalization code which will typically do something like close a socket.
/*0167./ * This in turn should wake up any threads that are waiting for I/O. These will
/*0168./ * either complete by throwing an exception, or, if the VersionOfTheWorld
/*0169./ * has been incremented, will release there IOCB and silently exit.This is
/*0170./ * an automatic feature built in to the ASYNC_enableGarbageCollection
/*0171./ * and ASYNC_disableGarbageCollection macros.
/*0172./ *
/*0173./ */
/*0174*/
/*0175*/int VersionOfTheWorld = 0;
/*0176*/
/*0177*/void InitalizeAsynchronousIO(void) {
/*0178*/    if (VersionOfTheWorld++ == 0) {
/*0179*/        int i;
/*0180*/        for (i = 0 ; i < ASYNC_IOCB_COUNT ; i++) {
								 //\\async.h:87

⌨️ 快捷键说明

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