CELLP load_f(CELLP arg) { FILE *lfp, *bak; char fname[NAMELEN] = {0}; if (arg->id != _CELL) { return error(NEA); } bak = cur_fpi; pushbuf(); for (;;) { if (arg->car->id != _ATOM) { return error(IAA); } getfname((STR)fname, (ATOMP)(arg->car)); fprintf(cur_fpo, "\nloading... %s\n", fname); if ((lfp = fopen(fname, "r")) == NULL) { return error(FNA); } cur_fpi = lfp; toplevel_function(); // トップレベルループを呼んでS式の読み込みと評価を行う fclose(lfp); ec; *txtp = '\0'; if ((arg = arg->cdr)->id != _CELL) { break; } } cur_fpi = bak; return (CELLP)t; }
CELLP read_f(CELLP arg) { FILE* nfp = cur_fpi; CELLP cp; // ファイルディスクリプタが指定された時 if (dirin(arg) != (CELLP)nil) { ec; cp = read_s(TOP); pushbuf(); cur_fpi = nfp; return cp; } cp = read_s(TOP); return read_s(TOP); }
int main(void) { int i; int numbuf = 32; struct buf_node* bufnode = NULL; init_buflist(&empty_listbuf, numbuf, 255); InitializeCriticalSection(&cs_code); create_semophare(0, numbuf); create_threads(NUM_THREAD); while (fgets(buf, sizeof(buf), stdin) != NULL) { i = 0; while (i < numbuf) { EnterCriticalSection(&cs_code); if ((bufnode = pullbuf(&empty_listbuf)) == NULL) { LeaveCriticalSection(&cs_code); Sleep(10); continue; } sprintf(bufnode->buf, "%d", i); pushbuf(bufnode, &filled_listbuf); LeaveCriticalSection(&cs_code); ReleaseSemaphore(handle_semfilled, 1, NULL); ++i; } } WaitForMultipleObjects(NUM_THREAD, handle_thread, 1, INFINITE); for (i=0; i<NUM_THREAD; ++i) { CloseHandle(handle_thread[i]); } CloseHandle(handle_semfilled); DeleteCriticalSection(&cs_code); return 0; }
unsigned int __stdcall processBufferData(void* pPM) { struct buf_node* bufnode = NULL; (void)pPM; printf("child thread %ld created.\n", GetCurrentThreadId()); while (1) { WaitForSingleObject(handle_semfilled, INFINITE); #ifdef _DEBUG EnterCriticalSection(&cs_code); ++countsem_wait; LeaveCriticalSection(&cs_code); #endif EnterCriticalSection(&cs_code); bufnode = pullbuf(&filled_listbuf); #ifdef _DEBUG ++pullcount; #endif if (bufnode == NULL) continue; LeaveCriticalSection(&cs_code); process_msg(bufnode, GetCurrentThreadId()); Sleep(200); EnterCriticalSection(&cs_code); #ifdef _DEBUG ++pushcount; #endif pushbuf(bufnode, &empty_listbuf); LeaveCriticalSection(&cs_code); } return 0; }
// 入力先の変更を行う CELLP dirin(CELLP arg) { int i; if (arg->id != _CELL) { return (CELLP)nil; } if (arg->car->id != _FIX) { return error(IFD); } i = (int)((NUMP)(arg->car))->value.fix; if (i < 0 || i >= NFILES) { return error(IFD); } if (fp[i].ptr == NULL) { return error(FNO); } if (!(fp[i].mode & IFREAD)) { return error(FWO); } pushbuf(); cur_fpi = fp[i].ptr; return arg->car; }