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

📄 1139.html

📁 著名的linux英雄站点的文档打包
💻 HTML
📖 第 1 页 / 共 3 页
字号:
NULL,<br>
tdd_read,<br>
tdd_write,<br>
NULL,<br>
NULL,<br>
tdd_ioctl,<br>
NULL,<br>
tdd_open,<br>
tdd_release,<br>
NULL,<br>
NULL,<br>
NULL,<br>
NULL<br>
};<br>
<br>
<br>
<br>
<br>
[目录]<br>
<br>
--------------------------------------------------------------------------------<br>
<br>
<br>
init.c<br>
<br>
/***********************************************************************<br>
Case study source code from the book `The linux A to Z'<br>
by Phil Cornes. Published by Prentice Hall, 1996.<br>
Copyright (C) 1996 Phil Cornes<br>
This program is free software; you can redistribute it and/or modify<br>
it under the terms of the GNU General Public License as published by<br>
the Free Software Foundation; either version 2 of the License, or<br>
(at your option) any later version.<br>
<br>
This program is distributed in the hope that it will be useful,<br>
but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
GNU General Public License for more details.<br>
<br>
You should have received a copy of the GNU General Public License<br>
along with this program; if not, write to the Free Software<br>
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.<br>
***********************************************************************/<br>
<br>
void tdd_init(void)<br>
{<br>
tdd_trace = TRUE;<br>
<br>
if (register_chrdev(30, "tdd", &tdd_fops))<br>
TRACE_TXT("Cannot register tdd driver as major device 30")<br>
else<br>
TRACE_TXT("Tiny device driver registered successfully")<br>
<br>
<br>
[目录]<br>
<br>
--------------------------------------------------------------------------------<br>
<br>
<br>
newthread<br>
<br>
/***********************************************************************<br>
Case study source code from the book `The linux A to Z'<br>
by Phil Cornes. Published by Prentice Hall, 1996.<br>
Copyright (C) 1996 Phil Cornes<br>
This program is free software; you can redistribute it and/or modify<br>
it under the terms of the GNU General Public License as published by<br>
the Free Software Foundation; either version 2 of the License, or<br>
(at your option) any later version.<br>
<br>
This program is distributed in the hope that it will be useful,<br>
but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
GNU General Public License for more details.<br>
<br>
You should have received a copy of the GNU General Public License<br>
along with this program; if not, write to the Free Software<br>
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.<br>
***********************************************************************/<br>
<br>
new_thread(int (*start_addr)(void), int stack_size)<br>
{<br>
struct context *ptr;<br>
int esp;<br>
<br>
/* 1 */<br>
if (!(ptr = (struct context *)malloc(sizeof(struct context))))<br>
return 0;<br>
<br>
/* 2 */<br>
if (!(ptr-&gt;stack = (char *)malloc(stack_size)))<br>
return 0;<br>
<br>
/* 3 */<br>
esp = (int)(ptr-&gt;stack+(stack_size-4));<br>
*(int *)esp = (int)exit_thread;<br>
*(int *)(esp-4) = (int)start_addr;<br>
*(int *)(esp-icon_cool.gif = esp-4;<br>
ptr-&gt;ebp = esp-8;<br>
<br>
/* 4 */<br>
if (thread_count++)<br>
{<br>
/* 5 */<br>
ptr-&gt;next = current-&gt;next;<br>
ptr-&gt;prev = current;<br>
current-&gt;next-&gt;prev = ptr;<br>
current-&gt;next = ptr;<br>
}<br>
else<br>
{<br>
/* 6 */<br>
ptr-&gt;next = ptr;<br>
ptr-&gt;prev = ptr;<br>
current = ptr;<br>
switch_context(&main_thread, current);<br>
}<br>
<br>
return 1;<br>
}<br>
<br>
<br>
<br>
<br>
[目录]<br>
<br>
--------------------------------------------------------------------------------<br>
<br>
<br>
exitthead<br>
<br>
/***********************************************************************<br>
Case study source code from the book `The linux A to Z'<br>
by Phil Cornes. Published by Prentice Hall, 1996.<br>
Copyright (C) 1996 Phil Cornes<br>
This program is free software; you can redistribute it and/or modify<br>
it under the terms of the GNU General Public License as published by<br>
the Free Software Foundation; either version 2 of the License, or<br>
(at your option) any later version.<br>
<br>
This program is distributed in the hope that it will be useful,<br>
but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
GNU General Public License for more details.<br>
<br>
You should have received a copy of the GNU General Public License<br>
along with this program; if not, write to the Free Software<br>
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.<br>
***********************************************************************/<br>
<br>
static exit_thread(void)<br>
{<br>
struct context dump, *ptr;<br>
<br>
/* 1 */<br>
if (--thread_count)<br>
{<br>
/* 2 */<br>
ptr = current;<br>
current-&gt;prev-&gt;next = current-&gt;next;<br>
current-&gt;next-&gt;prev = current-&gt;prev;<br>
current = current-&gt;next;<br>
free(ptr-&gt;stack);<br>
free(ptr);<br>
switch_context(&dump, current);<br>
}<br>
else<br>
{<br>
/* 3 */<br>
free(current-&gt;stack);<br>
free(current);<br>
switch_context(&dump, &main_thread);<br>
}<br>
}<br>
<br>
<br>
<br>
<br>
[目录]<br>
<br>
--------------------------------------------------------------------------------<br>
<br>
<br>
getchannel<br>
<br>
/***********************************************************************<br>
Case study source code from the book `The linux A to Z'<br>
by Phil Cornes. Published by Prentice Hall, 1996.<br>
Copyright (C) 1996 Phil Cornes<br>
This program is free software; you can redistribute it and/or modify<br>
it under the terms of the GNU General Public License as published by<br>
the Free Software Foundation; either version 2 of the License, or<br>
(at your option) any later version.<br>
<br>
This program is distributed in the hope that it will be useful,<br>
but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
GNU General Public License for more details.<br>
<br>
You should have received a copy of the GNU General Public License<br>
along with this program; if not, write to the Free Software<br>
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.<br>
***********************************************************************/<br>
<br>
get_channel(int number)<br>
{<br>
struct channel *ptr;<br>
<br>
/* 1 */<br>
for (ptr = channel_list; ptr; ptr = ptr-&gt;link)<br>
if (ptr-&gt;number==number)<br>
return((int)ptr);<br>
<br>
/* 2 */<br>
if (!(ptr = (struct channel *)malloc(sizeof(struct channel))))<br>
return 0;<br>
<br>
/* 3 */<br>
ptr-&gt;number = number;<br>
ptr-&gt;message_list = 0;<br>
ptr-&gt;message_tail = 0;<br>
ptr-&gt;sr_flag = 0;<br>
ptr-&gt;link = channel_list;<br>
channel_list = ptr;<br>
return((int)ptr);<br>
}<br>
<br>
<br>
<br>
<br>
[目录]<br>
<br>
--------------------------------------------------------------------------------<br>
<br>
<br>
def<br>
<br>
/***********************************************************************<br>
Case study source code from the book `The linux A to Z'<br>
by Phil Cornes. Published by Prentice Hall, 1996.<br>
Copyright (C) 1996 Phil Cornes<br>
This program is free software; you can redistribute it and/or modify<br>
it under the terms of the GNU General Public License as published by<br>
the Free Software Foundation; either version 2 of the License, or<br>
(at your option) any later version.<br>
<br>
This program is distributed in the hope that it will be useful,<br>
but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
GNU General Public License for more details.<br>
<br>
You should have received a copy of the GNU General Public License<br>
along with this program; if not, write to the Free Software<br>
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.<br>
***********************************************************************/<br>
<br>
#include &lt;string.h&gt;<br>
<br>
struct context /* One structure for each thread */<br>
{<br>
int ebp; /* Base pointer (stack frame pointer) store */<br>
char *stack; /* Pointer to memory block for thread stack */<br>
struct context *next; /* Round robin circular list pointer */<br>
struct context *prev; /* Round robin circular list pointer */<br>
};<br>
<br>
struct channel /* One structure for each communication channel */<br>
{<br>
int number; /* Channel number */<br>
int sr_flag; /* 0=no queue, 1=send queued, 2=receive queued */<br>
struct channel *link; /* Link to next channel in list */<br>
struct message *message_list; /* Head of message queue */<br>
struct message *message_tail; /* Tail of message queue */<br>
};<br>
<br>
struct message /* One structure for each pending send/receive */<br>
{<br>
int size; /* Size of message in bytes */<br>
char *addr; /* Pointer to start of message */<br>
struct message *link; /* Link to next message in queue */<br>
struct context *thread; /* Which thread blocks on this struct */<br>
};<br>
<br>
static struct context main_thread; /* Storage for main() details */<br>
static struct context *current; /* Currently executing thread */<br>
static int thread_count = 0; /* Number of threads to schedule */<br>
static struct channel *channel_list = 0; /* List of all channels */<br>
<br>

⌨️ 快捷键说明

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