ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.156 by root, Thu Nov 12 00:01:52 2009 UTC vs.
Revision 1.161 by root, Sun Jan 10 20:28:43 2010 UTC

11#include <stddef.h> 11#include <stddef.h>
12#include <stdlib.h> 12#include <stdlib.h>
13#include <errno.h> 13#include <errno.h>
14#include <sys/types.h> 14#include <sys/types.h>
15#include <sys/stat.h> 15#include <sys/stat.h>
16#include <sys/statvfs.h>
16#include <limits.h> 17#include <limits.h>
17#include <fcntl.h> 18#include <fcntl.h>
18#include <sched.h> 19#include <sched.h>
20
21#if _POSIX_MEMLOCK
22# include <sys/mman.h>
23#endif
19 24
20/* perl namespace pollution */ 25/* perl namespace pollution */
21#undef VERSION 26#undef VERSION
22 27
23#ifdef _WIN32 28#ifdef _WIN32
119 124
120#ifndef POSIX_FADV_NORMAL 125#ifndef POSIX_FADV_NORMAL
121# define POSIX_FADV_NORMAL 0 126# define POSIX_FADV_NORMAL 0
122# define NO_FADVISE 1 127# define NO_FADVISE 1
123#endif 128#endif
124
125#ifndef POSIX_FADV_SEQUENTIAL 129#ifndef POSIX_FADV_SEQUENTIAL
126# define POSIX_FADV_SEQUENTIAL 0 130# define POSIX_FADV_SEQUENTIAL 0
127#endif 131#endif
128
129#ifndef POSIX_FADV_RANDOM 132#ifndef POSIX_FADV_RANDOM
130# define POSIX_FADV_RANDOM 0 133# define POSIX_FADV_RANDOM 0
131#endif 134#endif
132
133#ifndef POSIX_FADV_NOREUSE 135#ifndef POSIX_FADV_NOREUSE
134# define POSIX_FADV_NOREUSE 0 136# define POSIX_FADV_NOREUSE 0
135#endif 137#endif
136
137#ifndef POSIX_FADV_WILLNEED 138#ifndef POSIX_FADV_WILLNEED
138# define POSIX_FADV_WILLNEED 0 139# define POSIX_FADV_WILLNEED 0
139#endif 140#endif
140
141#ifndef POSIX_FADV_DONTNEED 141#ifndef POSIX_FADV_DONTNEED
142# define POSIX_FADV_DONTNEED 0 142# define POSIX_FADV_DONTNEED 0
143#endif
144
145#ifndef ST_NODEV
146# define ST_NODEV 0
147#endif
148#ifndef ST_NOEXEC
149# define ST_NOEXEC 0
150#endif
151#ifndef ST_SYNCHRONOUS
152# define ST_SYNCHRONOUS 0
153#endif
154#ifndef ST_MANDLOCK
155# define ST_MANDLOCK 0
156#endif
157#ifndef ST_WRITE
158# define ST_WRITE 0
159#endif
160#ifndef ST_APPEND
161# define ST_APPEND 0
162#endif
163#ifndef ST_IMMUTABLE
164# define ST_IMMUTABLE 0
165#endif
166#ifndef ST_NOATIME
167# define ST_NOATIME 0
168#endif
169#ifndef ST_NODIRATIME
170# define ST_NODIRATIME 0
171#endif
172#ifndef ST_RELATIME
173# define ST_RELATIME 0
174#endif
175
176#ifndef MCL_CURRENT
177# define MCL_CURRENT 0
178#endif
179#ifndef MCL_FUTURE
180# define MCL_FUTURE 0
143#endif 181#endif
144 182
145static int req_invoke (eio_req *req); 183static int req_invoke (eio_req *req);
146#define EIO_FINISH(req) req_invoke (req) 184#define EIO_FINISH(req) req_invoke (req)
147static void req_destroy (eio_req *grp); 185static void req_destroy (eio_req *grp);
343 fh = (SV *)gv; 381 fh = (SV *)gv;
344 } 382 }
345 383
346 PUSHs (fh); 384 PUSHs (fh);
347 } 385 }
386 break;
387
388 case EIO_STATVFS:
389 case EIO_FSTATVFS:
390 {
391 SV *rv = &PL_sv_undef;
392
393 if (req->result >= 0)
394 {
395 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req);
396 HV *hv = newHV ();
397
398 rv = sv_2mortal (newRV_noinc ((SV *)hv));
399
400 hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0);
401 hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0);
402 hv_store (hv, "blocks" , sizeof ("blocks" ) - 1, newSVval64 (f->f_blocks ), 0);
403 hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0);
404 hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0);
405 hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0);
406 hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0);
407 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0);
408 hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0);
409 hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0);
410 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0);
411 }
412
413 PUSHs (rv);
414 }
415
348 break; 416 break;
349 417
350 case EIO_GROUP: 418 case EIO_GROUP:
351 req->int1 = 2; /* mark group as finished */ 419 req->int1 = 2; /* mark group as finished */
352 420
545 const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) 613 const_iv (FADV_RANDOM , POSIX_FADV_RANDOM)
546 const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) 614 const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
547 const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) 615 const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
548 const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) 616 const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED)
549 617
618 const_iv (ST_RDONLY , ST_RDONLY)
619 const_iv (ST_NOSUID , ST_NOSUID)
620 const_iv (ST_NODEV , ST_NODEV)
621 const_iv (ST_NOEXEC , ST_NOEXEC)
622 const_iv (ST_SYNCHRONOUS , ST_SYNCHRONOUS)
623 const_iv (ST_MANDLOCK , ST_MANDLOCK)
624 const_iv (ST_WRITE , ST_WRITE)
625 const_iv (ST_APPEND , ST_APPEND)
626 const_iv (ST_IMMUTABLE , ST_IMMUTABLE)
627 const_iv (ST_NOATIME , ST_NOATIME)
628 const_iv (ST_NODIRATIME , ST_NODIRATIME)
629 const_iv (ST_RELATIME , ST_RELATIME)
630
631 const_iv (MCL_FUTURE , MCL_FUTURE)
632 const_iv (MCL_CURRENT , MCL_CURRENT)
633
634 const_eio (MS_ASYNC)
635 const_eio (MS_INVALIDATE)
636 const_eio (MS_SYNC)
637
638 const_eio (MT_MODIFY)
639
550 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) 640 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE)
551 const_eio (SYNC_FILE_RANGE_WRITE) 641 const_eio (SYNC_FILE_RANGE_WRITE)
552 const_eio (SYNC_FILE_RANGE_WAIT_AFTER) 642 const_eio (SYNC_FILE_RANGE_WAIT_AFTER)
553 643
554 const_eio (READDIR_DENTS) 644 const_eio (READDIR_DENTS)
807} 897}
808 898
809void 899void
810aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) 900aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef)
811 ALIAS: 901 ALIAS:
812 aio_stat = EIO_STAT 902 aio_stat = EIO_STAT
813 aio_lstat = EIO_LSTAT 903 aio_lstat = EIO_LSTAT
904 aio_statvfs = EIO_STATVFS
814 PPCODE: 905 PPCODE:
815{ 906{
816 dREQ; 907 dREQ;
817 908
818 req->sv1 = newSVsv (fh_or_path); 909 req->sv1 = newSVsv (fh_or_path);
822 req->type = ix; 913 req->type = ix;
823 req->ptr1 = SvPVbyte_nolen (req->sv1); 914 req->ptr1 = SvPVbyte_nolen (req->sv1);
824 } 915 }
825 else 916 else
826 { 917 {
827 req->type = EIO_FSTAT; 918 req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT;
828 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); 919 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
829 } 920 }
830 921
831 REQ_SEND; 922 REQ_SEND;
832} 923}
995 1086
996 REQ_SEND; 1087 REQ_SEND;
997} 1088}
998 1089
999void 1090void
1091aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef)
1092 ALIAS:
1093 aio_mtouch = EIO_MTOUCH
1094 aio_msync = EIO_MSYNC
1095 PROTOTYPE: $$$$;$
1096 PPCODE:
1097{
1098 STRLEN svlen;
1099 UV len = SvUV (length);
1100 char *svptr = SvPVbyte (data, svlen);
1101
1102 if (offset < 0)
1103 offset += svlen;
1104
1105 if (offset < 0 || offset > svlen)
1106 croak ("offset outside of scalar");
1107
1108 if (!SvOK (length) || len + offset > svlen)
1109 len = svlen - offset;
1110
1111 {
1112 dREQ;
1113
1114 req->type = ix;
1115 req->size = len;
1116 req->sv2 = SvREFCNT_inc (data);
1117 req->ptr2 = (char *)svptr + offset;
1118 req->int1 = flags;
1119
1120 REQ_SEND;
1121 }
1122}
1123
1124void
1000aio_busy (double delay, SV *callback=&PL_sv_undef) 1125aio_busy (double delay, SV *callback=&PL_sv_undef)
1001 PPCODE: 1126 PPCODE:
1002{ 1127{
1003 dREQ; 1128 dREQ;
1004 1129
1144 1269
1145ssize_t 1270ssize_t
1146sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1271sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1147 PROTOTYPE: $$$$ 1272 PROTOTYPE: $$$$
1148 CODE: 1273 CODE:
1149 eio_sendfile_sync (ofh, ifh, offset, count); 1274 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1275 OUTPUT:
1276 RETVAL
1277
1278int
1279mlockall (int flags)
1280 PROTOTYPE: $
1281 CODE:
1282#if _POSIX_MEMLOCK
1283#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7
1284 extern int mallopt (int, int);
1285 mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */
1286#endif
1287 mlockall (flags);
1288#else
1289 RETVAL =-1;
1290 errno = ENOSYS;
1291#endif
1292 OUTPUT:
1293 RETVAL
1294
1295int
1296munlockall ()
1297 PROTOTYPE:
1298 CODE:
1299#if _POSIX_MEMLOCK
1300 munlockall ();
1301#else
1302 RETVAL =-1;
1303 errno = ENOSYS;
1304#endif
1305 OUTPUT:
1306 RETVAL
1150 1307
1151void _on_next_submit (SV *cb) 1308void _on_next_submit (SV *cb)
1152 CODE: 1309 CODE:
1153 SvREFCNT_dec (on_next_submit); 1310 SvREFCNT_dec (on_next_submit);
1154 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 1311 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines