+Mapgen *EmergeManager::getCurrentMapgen() {
+ for (unsigned int i = 0; i != emergethread.size(); i++) {
+ if (emergethread[i]->IsSameThread())
+ return emergethread[i]->mapgen;
+ }
+
+ return NULL;
+}
+
+
+void EmergeManager::startThreads() {
+ if (threads_active)
+ return;
+
+ for (unsigned int i = 0; i != emergethread.size(); i++)
+ emergethread[i]->Start();
+
+ threads_active = true;
+}
+
+
+void EmergeManager::stopThreads() {
+ if (!threads_active)
+ return;
+
+ // Request thread stop in parallel
+ for (unsigned int i = 0; i != emergethread.size(); i++) {
+ emergethread[i]->Stop();
+ emergethread[i]->qevent.signal();
+ }
+
+ // Then do the waiting for each
+ for (unsigned int i = 0; i != emergethread.size(); i++)
+ emergethread[i]->Wait();
+
+ threads_active = false;
+}
+
+