Annotation of driverkit/Examples/IOStub/IOStubThread.m, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: /*     IOStubThread.m          1.0     02/04/91        (c) 1991 NeXT   
        !            25:  *
        !            26:  * IOStubThread.m - IOStub Device Thread support.
        !            27:  *
        !            28:  * HISTORY
        !            29:  * 04-Feb-91    Doug Mitchell at NeXT
        !            30:  *      Created.
        !            31:  */
        !            32: 
        !            33: #import <bsd/sys/types.h>
        !            34: #import <mach/cthreads.h>
        !            35: #import <driverkit/IODevice.h>
        !            36: #import "IOStub.h"
        !            37: #import "IOStubThread.h"
        !            38: #import "IOStubDevice.h"
        !            39: #import "IOStubUxpr.h"
        !            40: #import <bsd/libc.h>
        !            41: #import <machkit/NXLock.h>
        !            42: 
        !            43: @implementation IOStub(Thread)
        !            44: 
        !            45: /*
        !            46:  * Enqueue an IOBuf on IOQueue and wake up anyone who might be waiting 
        !            47:  * for something to do.
        !            48:  */
        !            49: - (void)enqueueIoBuf : (IOBuf_t *)buf
        !            50: {
        !            51:        xpr_stub("enqueueIoBuf: IOBuf 0x%x\n", buf, 2,3,4,5);
        !            52:        [ioQLock lock];
        !            53:        queue_enter(&ioQueue, buf, IOBuf_t *, link);
        !            54:        [ioQLock unlockWith:WORK_AVAILABLE];
        !            55: }
        !            56: 
        !            57: /*
        !            58:  * Get an IOBuf from ioQueue. Blocks if necessary.
        !            59:  */
        !            60: - (IOBuf_t *)dequeueIoBuf
        !            61: {
        !            62:        IOBuf_t *buf;
        !            63:        
        !            64:        xpr_stub("dequeueIoBuf: entry\n", 1,2,3,4,5);
        !            65:        [ioQLock lockWhen:WORK_AVAILABLE];
        !            66:        buf = (IOBuf_t *)queue_first(&ioQueue);
        !            67:        queue_remove(&ioQueue, buf, IOBuf_t *, link);
        !            68:        if(queue_empty(&ioQueue))
        !            69:                [ioQLock unlockWith:NO_WORK_AVAILABLE];
        !            70:        else
        !            71:                [ioQLock unlockWith:WORK_AVAILABLE];
        !            72:        return buf;
        !            73: }
        !            74: 
        !            75: @end
        !            76: 
        !            77: /*
        !            78:  * I/O thread. This handles IOBufs which have been enqueued by 
        !            79:  * exported methods (like read: and write:).
        !            80:  *
        !            81:  * This thread merely loops doing the  following:
        !            82:  *    -- get an IOBuf off of the IOQueue.
        !            83:  *    -- perform the task specified. 
        !            84:  *    -- if async request, ioComplete: the result, else 
        !            85:  *      condition_signal() the waiting thread.
        !            86:  */
        !            87:  
        !            88: volatile void IOStub_thread(IOStub *stubId)
        !            89: {
        !            90:        IOBuf_t *IOBuf;
        !            91:        
        !            92:        xpr_stub("IOStub_thread: starting\n", 1,2,3,4,5);
        !            93:        while(1) {
        !            94:                IOBuf = [stubId dequeueIoBuf];  
        !            95:                xpr_stub("IOStub_thread: IOBuf 0x%x received\n", IOBuf,
        !            96:                        2,3,4,5); 
        !            97:        
        !            98:                switch(IOBuf->cmd) {    
        !            99:                    case STUB_READ:
        !           100:                        [stubId deviceRead:IOBuf];
        !           101:                        break;      
        !           102:                    case STUB_WRITE:
        !           103:                        [stubId deviceWrite:IOBuf];
        !           104:                        break;      
        !           105:                    case STUB_ZERO:
        !           106:                        [stubId deviceZero:IOBuf];
        !           107:                        break;      
        !           108:                    case STUB_ABORT:
        !           109:                        /*
        !           110:                         * I/O complete this request before we die.
        !           111:                         */
        !           112:                        [IOBuf->waitLock unlockWith:YES];
        !           113:                        IOExitThread();
        !           114:                        break;
        !           115:                }                       
        !           116:        }
        !           117:        /* NOT REACHED */
        !           118: }
        !           119: 
        !           120: /* end of IOThread.m */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.