Bugzilla entry # 363:

skygw_thread_t and simple_mutex_t make own copy of name argrument. Changed init calls to both accordingly.
This commit is contained in:
vraatikka 2013-11-27 10:51:45 +02:00
parent 8d1553b693
commit 41298a09df
4 changed files with 20 additions and 18 deletions

View File

@ -358,7 +358,7 @@ static bool logmanager_init_nomutex(
}
/** Initialize and start filewriter thread */
fw->fwr_thread = skygw_thread_init(strdup("filewriter thr"),
fw->fwr_thread = skygw_thread_init("filewriter thr",
thr_filewriter_fun,
(void *)fw);

View File

@ -153,7 +153,7 @@ int main(int argc, char* argv[])
#if defined(TEST1)
mes = skygw_message_init();
mtx = simple_mutex_init(NULL, strdup("testmtx"));
mtx = simple_mutex_init(NULL, "testmtx");
/** Test starts */
fprintf(stderr, "\nStarting test #1 \n");

View File

@ -322,9 +322,7 @@ mlist_t* mlist_init(
list->mlist_name = name;
}
/** Create mutex, return NULL if fails. */
if (simple_mutex_init(
&list->mlist_mutex,
strdup("writebuf mutex")) == NULL)
if (simple_mutex_init(&list->mlist_mutex, "writebuf mutex") == NULL)
{
ss_dfprintf(stderr, "* Creating rwlock for mlist failed\n");
mlist_free_memory(list, name);
@ -977,20 +975,21 @@ void slist_done(
* @node Initialize thread data structure
*
* Parameters:
* @param void - <usage>
* <description>
* @param name copy is taken and stored to thread structure
*
* @param sth_thrfun - <usage>
* <description>
*
* @return
* @param data thread data pointer
*
* @return thread pointer or NULL in case of failure
*
*
* @details (write detailed description here)
*
*/
skygw_thread_t* skygw_thread_init(
char* name,
const char* name,
void* (*sth_thrfun)(void* data),
void* data)
{
@ -1006,8 +1005,8 @@ skygw_thread_t* skygw_thread_init(
th->sth_chk_tail = CHK_NUM_THREAD;
th->sth_parent = pthread_self();
ss_debug(th->sth_state = THR_INIT;)
th->sth_name = name;
th->sth_mutex = simple_mutex_init(NULL, strdup(name));
th->sth_name = strndup(name, PATH_MAX);
th->sth_mutex = simple_mutex_init(NULL, name);
if (th->sth_mutex == NULL) {
thread_free_memory(th, th->sth_name);
@ -1214,10 +1213,13 @@ void release_lock(
* @node Create a simple_mutex structure which encapsulates pthread_mutex.
*
* Parameters:
* @param name - <usage>
* <description>
* @param mutexptr if mutex is initialized within caller's memory, this is
* the address for it. If mutex is flat, there is value, otherwise it is NULL.
*
* @return
* @param name name of mutex, passed argument is copied and pointer is stored
* to mutex struct.
*
* @return simple_mutex pointer or NULL in case of failure.
*
*
* @details If mutex is flat, sm_enabled can be read if the memory is not freed.
@ -1228,7 +1230,7 @@ void release_lock(
*/
simple_mutex_t* simple_mutex_init(
simple_mutex_t* mutexptr,
char* name)
const char* name)
{
int err;
simple_mutex_t* sm;
@ -1245,7 +1247,7 @@ simple_mutex_t* simple_mutex_init(
sm->sm_chk_top = CHK_NUM_SIMPLE_MUTEX;
sm->sm_chk_tail = CHK_NUM_SIMPLE_MUTEX;
#endif
sm->sm_name = name;
sm->sm_name = strndup(name, PATH_MAX);
/** Create pthread mutex */
err = pthread_mutex_init(&sm->sm_mutex, NULL);

View File

@ -117,7 +117,7 @@ bool mlist_cursor_step_ahead(mlist_cursor_t* c);
/** Skygw thread routines */
skygw_thread_t* skygw_thread_init(
char* name,
const char* name,
void* (*sth_thrfun)(void* data),
void* data);
void skygw_thread_done(skygw_thread_t* th);
@ -159,7 +159,7 @@ EXTERN_C_BLOCK_BEGIN
void acquire_lock(int* l);
void release_lock(int* l);
simple_mutex_t* simple_mutex_init(simple_mutex_t* mutexptr, char* name);
simple_mutex_t* simple_mutex_init(simple_mutex_t* mutexptr, const char* name);
int simple_mutex_done(simple_mutex_t* sm);
int simple_mutex_lock(simple_mutex_t* sm, bool block);
int simple_mutex_unlock(simple_mutex_t* sm);