Mercurial > hg > Members > nobuyasu > test
changeset 10:41634f26cd6f
add regen
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 19 Jun 2011 16:33:33 +0900 |
parents | 493c96d030c0 |
children | 1e0cd7fade8b |
files | pyrect/pyrect/a.out pyrect/pyrect/a.out.dSYM/Contents/Resources/DWARF/a.out pyrect/pyrect/grep.c pyrect/pyrect/grep.c~ |
diffstat | 4 files changed, 84 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/pyrect/pyrect/grep.c Tue Jun 14 17:24:03 2011 +0900 +++ b/pyrect/pyrect/grep.c Sun Jun 19 16:33:33 2011 +0900 @@ -111,13 +111,14 @@ int i; for (i=0; i<num; i++){ - iret = pthread_create( &threads[i], NULL, matcherp, (void*)thargs[0] ); + iret = pthread_create( &threads[i], NULL, matcherp, (void*)thargs[i] ); } // matcher(beg, beg, end); for ( i=0; i<num; i++) { pthread_join( threads[i], NULL); } + munmap(file_mmap, size); return; } @@ -156,7 +157,8 @@ env.count = 0; goto entry(beg, buf, end, &env); _return: - return env.count; + pthread_cancel(pthread_self()); + // return env.count; } void *matcherp(void *p) { @@ -209,13 +211,12 @@ off_t rem = size % num; UCHARP end; for ( i=1; i<num+1; i++) { - p[1-i] = malloc(sizeof(THARG)); + p[i-1] = malloc(sizeof(THARG)); end = beg + dsize * i; - createArg( p[1-i], fdp, beg+dsize*(i-1), buf+dsize*(i-1), end); + createArg( p[i-1], fdp, beg+dsize*(i-1), buf+dsize*(i-1), end); } } - void mallocTh(pthread_t *threads, int num) { int i; threads = malloc(sizeof(pthread_t) * num);
--- a/pyrect/pyrect/grep.c~ Tue Jun 14 17:24:03 2011 +0900 +++ b/pyrect/pyrect/grep.c~ Sun Jun 19 16:33:33 2011 +0900 @@ -6,6 +6,7 @@ #include <fcntl.h> #include <unistd.h> #include <string.h> +#include <pthread.h> typedef unsigned char UCHAR; typedef unsigned char *UCHARP; @@ -15,13 +16,24 @@ } ENV; typedef ENV *ENVP; +typedef struct THARG { + int *fdp; + UCHARP beg, buf, end; +} THARG; +typedef THARG *THARGP; + int matcher(UCHARP beg, UCHARP buf, UCHARP end); +void *matcherp(void *p); + __code entry(UCHARP beg, UCHARP buf, UCHARP end, ENVP envp); __code accept(UCHARP beg, UCHARP buf, UCHARP end, ENVP envp); __code reject(UCHARP beg, UCHARP buf, UCHARP end, ENVP envp); UCHARP get_line_beg(UCHARP p, UCHARP beg); +void createArg(THARGP p, int *fdp, UCHARP beg, UCHARP buf, UCHARP end); +void mallocTh(pthread_t *threads, int num); +void createArgs(THARGP *p, int *fdp, UCHARP beg, UCHARP buf, off_t size, int num); __code quick_filter(UCHARP beg, UCHARP buf, UCHARP end, ENVP envp) { static const UCHAR key[] = "ABC"; @@ -60,6 +72,7 @@ fwrite(beg, sizeof(char), (end - beg + 1), stdout); } + void grep(char *regexp, int fd, char *name) { caddr_t file_mmap; UCHARP buf, end, beg; @@ -81,9 +94,30 @@ beg = buf = (UCHARP) file_mmap; end = beg + size - 1; + + int iret; + THARG tharg; + + int num = 2; + THARGP *thargs = malloc(sizeof(THARG) * num); + createArgs( thargs, &fd, beg, buf, size, num); - matcher(beg, beg, end); + + pthread_t *threads = malloc(sizeof(pthread_t) * num); + mallocTh( threads, num); + + // createArg( &tharg, &fd, beg, buf, end); + // iret = pthread_create( &threads[0], NULL, matcherp, (void*)&tharg ); + int i; + for (i=0; i<num; i++){ + iret = pthread_create( &threads[i], NULL, matcherp, (void*)thargs[0] ); + } + // matcher(beg, beg, end); + + for ( i=0; i<num; i++) { + pthread_join( threads[i], NULL); + } munmap(file_mmap, size); return; } @@ -125,6 +159,20 @@ return env.count; } +void *matcherp(void *p) { + __label__ _end; + void __end() { + goto _end; + } + ENV env; + env.ret = __end; + env.count = 0; + THARGP tharg = (THARGP)p; + goto entry(tharg->beg, tharg->buf, tharg->end, &env); +_end: + exit(0); +} + __code entry(UCHARP beg, UCHARP buf, UCHARP end, ENVP envp) { goto quick_filter(beg, buf, end, envp); } @@ -147,3 +195,32 @@ goto entry(beg, buf, end, envp); } +void createArg(THARGP p, int *fdp, UCHARP beg, UCHARP buf, UCHARP end ) { + p->fdp = fdp; + p->beg = beg; + p->buf = buf; + p->end = end; +} + +void createArgs(THARGP *p, int *fdp, UCHARP beg, UCHARP buf, off_t size, int num) { + int i; + + off_t dsize = size / num; + off_t rem = size % num; + UCHARP end; + for ( i=1; i<num+1; i++) { + p[1-i] = malloc(sizeof(THARG)); + end = beg + dsize * i; + createArg( p[1-i], fdp, beg+dsize*(i-1), buf+dsize*(i-1), end); + } +} + + +void mallocTh(pthread_t *threads, int num) { + int i; + threads = malloc(sizeof(pthread_t) * num); + + for( i=0; i<num; i++) { + threads[i] = malloc(sizeof(pthread_t)); + } +}