#endif
#endif
-typedef void (*VixThreadFuncType)(void *);
-typedef void (*VixScheduleWorkFuncType)(VixThreadFuncType, void *);
+#include "vixExternalThread.h"
-typedef struct IVixThread {
- VixScheduleWorkFuncType ScheduleWorkFunc;
-} IVixThread;
+typedef enum VixThreadType {
+ VIX_THREAD_WORKER,
+ VIX_THREAD_IO,
+ VIX_THREAD_DEDICATED
+} VixThreadType;
-void Vix_SetExternalThreadInterface(IVixThread *threadInt);
+static struct FoundryWorkerThread *
+FoundryThreadsStartThreadInternal(FoundryThreadProc proc,
+ void *threadParam,
+ const char *threadName,
+ enum VixThreadType type);
static void FoundryThreadWrapperWrapper(void *);
/*
*-----------------------------------------------------------------------------
*
- * FoundryThreads_StartThread --
+ * FoundryThreadsStartThreadInternal --
*
- * Start a worker thread.
+ * Start a thread.
*
* Results:
* FoundryWorkerThread *
*-----------------------------------------------------------------------------
*/
-FoundryWorkerThread *
-FoundryThreads_StartThread(FoundryThreadProc proc, // IN
- void *threadParam, // IN
- const char *threadName) // IN
+static FoundryWorkerThread *
+FoundryThreadsStartThreadInternal(FoundryThreadProc proc, // IN
+ void *threadParam, // IN
+ const char *threadName, // IN
+ VixThreadType type) // IN
{
VixError err = VIX_OK;
FoundryWorkerThread *threadState = NULL;
threadState->threadName = threadName;
if (UseExternalThreadInterface()) {
- (*GlobalVixThreadInterface->ScheduleWorkFunc)(
- FoundryThreadWrapperWrapper, threadState);
+ switch (type) {
+ case VIX_THREAD_WORKER:
+ (*GlobalVixThreadInterface->ScheduleWorkFunc)(
+ FoundryThreadWrapperWrapper, threadState);
+ break;
+ case VIX_THREAD_IO:
+ (*GlobalVixThreadInterface->ScheduleIOFunc)(
+ FoundryThreadWrapperWrapper, threadState);
+ break;
+ case VIX_THREAD_DEDICATED:
+ (*GlobalVixThreadInterface->ScheduleDedicatedFunc)(
+ FoundryThreadWrapperWrapper, threadState);
+ break;
+ default:
+ NOT_IMPLEMENTED();
+ }
goto abort;
}
}
return threadState;
-} // FoundryThreads_StartThread
+} // FoundryThreadsStartThreadInternal
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * FoundryThreads_StartThread --
+ *
+ * Start a new thread or farm out the specified procedure to an
+ * external worker thread pool.
+ * A worker thread should not do blocking I/O.
+ *
+ * Results:
+ * FoundryWorkerThread *
+ *
+ * Side effects:
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+FoundryWorkerThread *
+FoundryThreads_StartThread(FoundryThreadProc proc, // IN
+ void *threadParam, // IN
+ const char *threadName) // IN
+{
+ return FoundryThreadsStartThreadInternal(proc, threadParam, threadName,
+ VIX_THREAD_WORKER);
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * FoundryThreads_StartIOThread --
+ *
+ * Start a new thread or farmed out the specified procedure to an
+ * external IO thread pool.
+ * An IO thread performs short IO operations.
+ * In hostd (vmacore) IO threads should generally complete quickly and
+ * should never wait on worker threads. Worker threads can wait on at
+ * most one IO thread.
+ *
+ * Results:
+ * FoundryWorkerThread *
+ *
+ * Side effects:
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+FoundryWorkerThread *
+FoundryThreads_StartIOThread(FoundryThreadProc proc, // IN
+ void *threadParam, // IN
+ const char *threadName) // IN
+{
+ return FoundryThreadsStartThreadInternal(proc, threadParam, threadName,
+ VIX_THREAD_IO);
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * FoundryThreads_StartDedicatedThread --
+ *
+ * Start a new thread or farmed out the specified procedure to an
+ * external dedicated thread pool.
+ * A dedicated thread has a life time of the containing process.
+ * Usually the thread alternates wait and work in a loop, such as a poll
+ * loop.
+ *
+ * Results:
+ * FoundryWorkerThread *
+ *
+ * Side effects:
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+FoundryWorkerThread *
+FoundryThreads_StartDedicatedThread(FoundryThreadProc proc, // IN
+ void *threadParam, // IN
+ const char *threadName) // IN
+{
+ return FoundryThreadsStartThreadInternal(proc, threadParam, threadName,
+ VIX_THREAD_DEDICATED);
+}
/*
--- /dev/null
+/*********************************************************
+ * Copyright (C) 2010 VMware, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation version 2.1 and no later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ *********************************************************/
+
+/*
+ * This header defines shared thread interface that need to be included in both
+ * vixSemiPublic.h and foundryThread.c
+ * foundryThread.c cannot include vixSemiPublic.h due to dependency issue
+ */
+
+#ifndef _VIX_EXTERNAL_THREAD_H_
+#define _VIX_EXTERNAL_THREAD_H_
+
+typedef void (*VixThreadFuncType)(void *);
+typedef void (*VixScheduleWorkFuncType)(VixThreadFuncType, void *);
+
+typedef struct IVixThread {
+ VixScheduleWorkFuncType ScheduleWorkFunc;
+ VixScheduleWorkFuncType ScheduleIOFunc;
+ VixScheduleWorkFuncType ScheduleDedicatedFunc;
+} IVixThread;
+
+void Vix_SetExternalThreadInterface(IVixThread *threadInt);
+
+#endif