CtdlThreadName now takes a const char * and returns a const char *
It is up to the caller to make sure the name never goes out of scope.
void CtdlThreadStop(struct CtdlThreadNode *thread);
int CtdlThreadCheckStop(struct CtdlThreadNode *this_thread);
void CtdlThreadCancel(struct CtdlThreadNode *thread);
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);
struct CtdlThreadNode *CtdlThreadSelf(void);
int CtdlThreadGetCount(void);
int CtdlThreadGetWorkers(void);
double CtdlThreadGetLoadAvg(void);
void CtdlThreadGC(void);
void CtdlThreadStopAll(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
/* 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 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
*/
* 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
*/
- this_thread->name = strdup("Garbage Collection Thread");
+ this_thread->name = "Garbage Collection Thread";
this_thread->tid = GC_thread;
this_thread->tid = GC_thread;
/*
* A function to rename a 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;
{
struct CtdlThreadNode *this_thread;
if (!thread)
this_thread = CtdlThreadSelf();
if (!thread)
this_thread = CtdlThreadSelf();
pthread_mutex_lock(&this_thread->ThreadMutex);
old_name = this_thread->name;
if (name)
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);
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);
* 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);
pthread_mutex_destroy(&that_thread->ThreadMutex);
pthread_cond_destroy(&that_thread->ThreadCond);
pthread_mutex_destroy(&that_thread->SleepMutex);
- this_thread->name = strdup(name);
+ this_thread->name = name;
- this_thread->name = strdup("Un-named Thread");
+ this_thread->name = "Un-named Thread";
}
this_thread->flags = flags;
}
this_thread->flags = flags;
CtdlLogPrintf(CTDL_ALERT, "Thread system, Can't create thread: %s\n",
strerror(ret));
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));
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
*/
/*
* 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)
-// 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.
*/
/* Next, check to see if it's a new client connecting
* on a master socket.
*/
long number; /* A unigue number for this thread (not implimented yet) */
int wakefd_recv; /* An fd that this thread can sleep on (not implimented yet) */
int wakefd_send; /* An fd that this thread can send out on (Not implimented yet) */
long number; /* A unigue number for this thread (not implimented yet) */
int wakefd_recv; /* An fd that this thread can sleep on (not implimented yet) */
int wakefd_send; /* An fd that this thread can send out on (Not implimented yet) */
- char *name; /* A name for this thread */
+ const char *name; /* A name for this thread */
void *(*thread_func) (void *arg); /* The actual function that does this threads work */
void *user_args; /* Arguments passed to this threads work function */
long flags; /* Flags that describe this thread */
void *(*thread_func) (void *arg); /* The actual function that does this threads work */
void *user_args; /* Arguments passed to this threads work function */
long flags; /* Flags that describe this thread */