コード例 #1
0
 public static void Configure(AiCoreConfiguration configuration)
 {
     if (running)
     {
         return;
     }
     AiCore.configuration = configuration;
     // cannot be configured if started.
     threads = new AiWorkerThread[configuration.threadCount];
     for (int i = 0; i < configuration.threadCount; i++)
     {
         threads[i] = new AiWorkerThread();
     }
     configured = true;
 }
コード例 #2
0
 public static void InitCore(AiCoreConfiguration configuration)
 {
     AiCore.configuration = configuration;
     threads = new AiWorkerThread[configuration.threadCount];
     for (int i = 0; i < configuration.threadCount; i++)
     {
         threads[i] = new AiWorkerThread();
     }
     configured      = true;
     AddListMutex    = new Mutex();
     RemoveListMutex = new Mutex();
     add_list        = new List <AiBrain>();
     remove_list     = new List <AiBrain>();
     BrainMapping    = new Dictionary <AiBrain, int>();
     Console.WriteLine("Initialized AI Core");
 }
コード例 #3
0
        public static void ThreadWork(object arg)
        {
            int            tid       = (int)arg;
            AiWorkerThread my_thread = threads[tid];

            while (running)
            {
                my_thread.threadLock.WaitOne();
                AiBrain current_brain = null;
                if (my_thread.NumBrains > 0)
                {
                    current_brain = my_thread.readyQueue[0];
                    my_thread.readyQueue.RemoveAt(0);
                    my_thread.readyQueue.Add(current_brain);
                }
                my_thread.threadLock.ReleaseMutex();
                if (current_brain != null)
                {
                    Console.WriteLine("Processing Brain");
                    current_brain.Process();
                }
            }
            Console.WriteLine("Exiting {0}", tid);
        }