-
Notifications
You must be signed in to change notification settings - Fork 0
/
pth_ext.c
103 lines (90 loc) · 2.83 KB
/
pth_ext.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
** GNU Pth - The GNU Portable Threads
** Copyright (c) 1999-2006 Ralf S. Engelschall <[email protected]>
**
** This file is part of GNU Pth, a non-preemptive thread scheduling
** library which can be found at http://www.gnu.org/software/pth/.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
** USA, or contact Ralf S. Engelschall <[email protected]>.
**
** pth_ext.c: Pth extensions
*/
/* ``Killing for peace is
like fucking for virginity.''
-- Unknown */
#include "pth_p.h"
/*
* Sfio Extension:
*
* We provide an Sfio discipline which can be pushed on an Sfio_t* stream
* to use the Pth thread-aware I/O routines (pth_read/pth_write).
*/
#if PTH_EXT_SFIO
static ssize_t pth_sfio_read(Sfio_t *f, Void_t *buf, size_t n, Sfdisc_t *disc)
{
ssize_t rv;
rv = pth_read(sffileno(f), buf, n);
return rv;
}
static ssize_t pth_sfio_write(Sfio_t *f, const Void_t *buf, size_t n, Sfdisc_t *disc)
{
ssize_t rv;
rv = pth_write(sffileno(f), buf, n);
return rv;
}
static Sfoff_t pth_sfio_seek(Sfio_t *f, Sfoff_t addr, int type, Sfdisc_t *disc)
{
return sfsk(f, addr, type, disc);
}
static int pth_sfio_except(Sfio_t *f, int type, Void_t* data, Sfdisc_t *disc)
{
int rv;
switch (type) {
case SF_LOCKED:
case SF_READ:
case SF_WRITE:
case SF_SEEK:
case SF_NEW:
case SF_CLOSE:
case SF_FINAL:
case SF_DPUSH:
case SF_DPOP:
case SF_DBUFFER:
case SF_DPOLL:
case SF_READY:
case SF_SYNC:
case SF_PURGE:
default:
rv = 0; /* perform default action */
}
return rv;
}
#endif /* PTH_EXT_SFIO */
Sfdisc_t *pth_sfiodisc(void)
{
#if PTH_EXT_SFIO
Sfdisc_t *disc;
if ((disc = (Sfdisc_t *)malloc(sizeof(Sfdisc_t))) == NULL)
return pth_error((SFdisc_t *)NULL, errno);
disc->readf = pth_sfio_read;
disc->writef = pth_sfio_write;
disc->seekf = pth_sfio_seek;
disc->exceptf = pth_sfio_except;
return disc;
#else
return pth_error((Sfdisc_t *)NULL, ENOSYS);
#endif /* PTH_EXT_SFIO */
}