Example #1
0
		public static void Quit ()
		{
			lock (m_Lock) {
				// if we only have one ref count 
				// destroy all the service threads
				// else just decrement the refrence
				// counter.
				if (m_nRefCount == 1) {
					if (m_Threads != null) {
						// Set the thread to drop through.
						ThreadProcess.m_Stop.Set ();
						foreach (Thread thread in m_Threads)
							thread.Join ();
						m_Threads = null;

						// Unregister all the nodes.
						foreach (MPCList<dLightWeightProcessBase>.Node node in m_Processes) {
							node.Data.internal_DecrementRegister ();
							node.Data.internal_UnRegister ();
						}
						m_Processes = null;

						ThreadProcess.Term ();
					}
				}
				// Prevent the count going below 0
				m_nRefCount = Math.Max (m_nRefCount - 1, 0);
			}
		}
Example #2
0
		internal static void Init (int _nThreadCount)
		{
			lock (m_Lock) {
				m_nRefCount++;
				if (m_nRefCount == 1) {
					m_Processes = new MPCList<dLightWeightProcessBase> ();

					ThreadProcess.Init ();

					m_Threads = new List<Thread> ();
					int nThreadCount = _nThreadCount;
					for (int i = 0; i < nThreadCount; i++) {
						Thread thread = new Thread (delegate () { ThreadProcess process = new ThreadProcess (); process.MainLoop (); });
						thread.Name = String.Format ("dLightWeightProcessThread_{0}", i);
						thread.Start ();

						m_Threads.Add (thread);
					}
				}
			}
		}