+ /* Set this new thread with an avg_blocked of 2. We do this so that its creation affects the
+ * load average for the system. If we don't do this then we create a mass of threads at the same time
+ * because the creation didn't affect the load average.
+ */
+ this_thread->avg_blocked = 2;
+
+ return (this_thread);
+}
+
+
+
+
+/*
+ * Internal function to create a thread.
+ */
+CtdlThreadNode *ctdl_internal_create_thread(char *name, long flags, void *(*thread_func) (void *arg), void *args)
+{
+ int ret = 0;
+ CtdlThreadNode *this_thread;
+
+ if (num_threads >= 32767)
+ {
+ CtdlLogPrintf(CTDL_EMERG, "Thread system. Thread list full.\n");
+ return NULL;
+ }
+
+ this_thread = malloc(sizeof(CtdlThreadNode));
+ if (this_thread == NULL) {
+ CtdlLogPrintf(CTDL_EMERG, "Thread system, can't allocate CtdlThreadNode, exiting\n");
+ return NULL;
+ }
+
+ /* Initialise the thread structure */
+ if (ctdl_internal_init_thread_struct(this_thread, flags) == NULL)
+ {
+ free(this_thread);
+ CtdlLogPrintf(CTDL_EMERG, "Thread system, can't initialise CtdlThreadNode, exiting\n");
+ return NULL;
+ }