|
|
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: /*
25: * ioThread.h
26: */
27:
28: #import <mach/mach.h>
29: #import <kernserv/queue.h>
30: #import <machkit/NXLock.h>
31: #import <libc.h>
32: #import <driverkit/IODevice.h>
33: #import <driverkit/generalFuncs.h>
34:
35: /*
36: * Commands to be passed to I/O thread.
37: */
38: typedef enum {
39: IOC_GETNUM, // get a number from stdin
40: IOC_PRINTNUM, // print a number
41: IOC_QUIT // exit
42: } ioCmd_t;
43:
44: /*
45: * This struct is the means by which exported methods pass commands to the
46: * I/O thread.
47: */
48:
49: typedef struct {
50: id cmdLock; // NXConditionLock. Clients await
51: // completion notification via
52: // this lock.
53: ioCmd_t cmd; // operation to perform
54: int aNumber; // some data
55: queue_chain_t link; // for enqueueing on ioQueue
56: } cmdBuf_t;
57:
58: /*
59: * Condition values for cmdLock.
60: */
61: #define CMD_BUSY 0
62: #define CMD_COMPLETE 1
63:
64: /*
65: * Simple driver class.
66: */
67: @interface MyDevice:IODevice
68: {
69: id ioQueueLock; // NXConditionLock. Protects ioQueue;
70: // the ioThread awaits input via
71: // this lock.
72: queue_head_t ioQueue; // queue of cmdBuf_t's
73: IOThread ioThread;
74: }
75:
76: /*
77: * Condition values for ioQueueLock.
78: */
79: #define QUEUE_EMPTY 0
80: #define QUEUE_FULL 1 // at least one element in queue
81:
82: /*
83: * Initialization.
84: */
85: - myDeviceInit;
86:
87: /*
88: * Exported run-time methods.
89: */
90: - (int)getNumber; // have I/O thread get a number
91: // from user
92: - (void)printNumber : (int)ack; // have I/O thread print a number
93: - free;
94:
95: @end
96:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.