void engine_open(engine_t * engine){ int affinity; char *my_dir; if( (my_dir = _getcwd( NULL, 0 )) == NULL ) my_fatal("Can't build path: %s\n",strerror(errno)); if(SetCurrentDirectory(option_get_string("EngineDir"))==0){ printf("tellusererror Polyglot:EngineDir error: %s\n",option_get_string("EngineDir")); fflush(stdout); Sleep(50000); my_fatal("EngineDir path error: %s\n",option_get_string("EngineDir")); } pipeEngine.Open(option_get_string("EngineCommand")); //play with affinity #ifndef NO_AFFINITY affinity=option_get_int("Affinity"); if(affinity!=-1){ my_log("POLYGLOT SetProcess Affinity\n"); SetProcessAffinityMask(child,affinity); // } #endif //lets go back SetCurrentDirectory(my_dir); // set priority if (option_get_bool("UseNice")){ my_log("POLYGLOT Adjust Engine Piority\n"); SetPriorityClass(child, GetWin32Priority(option_get_int("NiceValue"))); } }
bool AI_CreateThread(AI_ThreadRoutine routine, void* opaque, int priority) { // create internal thread data ThreadInternal* internal = new ThreadInternal; internal->routine = routine; internal->opaque = opaque; // create the actual thread unsigned threadid; HANDLE handle = (HANDLE)_beginthreadex( 0, 0, InternalThreadRoutine, internal, CREATE_SUSPENDED, &threadid); if (handle) { if (SupportsThreadPriority()) { SetThreadPriority(handle, GetWin32Priority(priority)); } ResumeThread(handle); CloseHandle(handle); return true; } else { return false; } }