void CtdlThreadStop(struct CtdlThreadNode *thread);
int CtdlThreadCheckStop(struct CtdlThreadNode *this_thread);
void CtdlThreadCancel(struct CtdlThreadNode *thread);
-char *CtdlThreadName(struct CtdlThreadNode *thread, char *name);
+const char *CtdlThreadName(struct CtdlThreadNode *thread, const char *name);
struct CtdlThreadNode *CtdlThreadSelf(void);
int CtdlThreadGetCount(void);
int CtdlThreadGetWorkers(void);
double CtdlThreadGetLoadAvg(void);
void CtdlThreadGC(void);
void CtdlThreadStopAll(void);
-int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout, struct CtdlThreadNode *self);
+int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout, struct CtdlThreadNode *self);
/* Macros to speed up getting outr thread */
#define CT _this_cit_thread
* If the thread is created *node will point to the thread control structure for the created thread.
* If the thread creation fails *node remains NULL
* Do not free the memory pointed to by *node, it doesn't belong to you.
- * If your thread function returns it will be started again without creating a new thread.
- * If your thread function wants to exit it should call CtdlThreadExit(ret_code);
* This new interface duplicates much of the eCrash stuff. We should go for closer integration since that would
* remove the need for the calls to eCrashRegisterThread and friends
*/
return;
}
- this_thread->name = strdup("Garbage Collection Thread");
+ this_thread->name = "Garbage Collection Thread";
this_thread->tid = GC_thread;
/*
* A function to rename a thread
- * Returns a char * and the caller owns the memory and should free it
+ * Returns a const char *
*/
-char *CtdlThreadName(struct CtdlThreadNode *thread, char *name)
+const char *CtdlThreadName(struct CtdlThreadNode *thread, const char *name)
{
struct CtdlThreadNode *this_thread;
- char *old_name;
+ const char *old_name;
if (!thread)
this_thread = CtdlThreadSelf();
pthread_mutex_lock(&this_thread->ThreadMutex);
old_name = this_thread->name;
if (name)
- this_thread->name = strdup (name);
- else
- old_name = strdup(old_name);
+ this_thread->name = name;
pthread_mutex_unlock(&this_thread->ThreadMutex);
// end_critical_section (S_THREAD_LIST);
return (old_name);
* Now we own that thread entry
*/
CtdlLogPrintf(CTDL_INFO, "Garbage Collection for thread \"%s\" (%ld).\n", that_thread->name, that_thread->tid);
- if(that_thread->name)
- free(that_thread->name);
pthread_mutex_destroy(&that_thread->ThreadMutex);
pthread_cond_destroy(&that_thread->ThreadCond);
pthread_mutex_destroy(&that_thread->SleepMutex);
*/
if(name)
{
- this_thread->name = strdup(name);
+ this_thread->name = name;
}
else
{
- this_thread->name = strdup("Un-named Thread");
+ this_thread->name = "Un-named Thread";
}
this_thread->flags = flags;
CtdlLogPrintf(CTDL_ALERT, "Thread system, Can't create thread: %s\n",
strerror(ret));
- if (this_thread->name)
- free (this_thread->name);
pthread_mutex_destroy(&(this_thread->ThreadMutex));
pthread_cond_destroy(&(this_thread->ThreadCond));
pthread_mutex_destroy(&(this_thread->SleepMutex));
/*
* A warapper function for select so we can show a thread as blocked
*/
-int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout, struct CtdlThreadNode *self)
+int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout, struct CtdlThreadNode *self)
{
int ret;
goto do_select;
}
}
-// else if(retval == 0) {
-// goto SKIP_SELECT;
-// }
+ else if(retval == 0) {
+ goto SKIP_SELECT;
+ }
/* Next, check to see if it's a new client connecting
* on a master socket.
*/