Skip to content
Permalink
Browse files

Merge pull request #3596 from donaldsharp/pthread_7.0

dev/7.0 DC of #3589 and #3590
  • Loading branch information...
mjstapp committed Jan 10, 2019
2 parents 8de312f + 119563f commit 532ff7f21e1c08c0382808cb5443fa6be4a545fe
Showing with 21 additions and 31 deletions.
  1. +5 −1 bgpd/bgp_keepalives.c
  2. +7 −23 lib/frr_pthread.c
  3. +3 −6 lib/frr_pthread.h
  4. +6 −1 lib/thread.c
@@ -181,7 +181,11 @@ void *bgp_keepalives_start(void *arg)
pthread_cond_init(peerhash_cond, &attrs);
pthread_condattr_destroy(&attrs);

frr_pthread_set_name(fpt, NULL, "bgpd_ka");
/*
* We are not using normal FRR pthread mechanics and are
* not using fpt_run
*/
frr_pthread_set_name(fpt);

/* initialize peer hashtable */
peerhash = hash_create_size(2048, peer_hash_key, peer_hash_cmp, NULL);
@@ -84,6 +84,8 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr,
fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name);
if (os_name)
snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name);
else
snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", name);
/* initialize startup synchronization primitives */
fpt->running_cond_mtx = XCALLOC(
MTYPE_PTHREAD_PRIM, sizeof(pthread_mutex_t));
@@ -115,36 +117,19 @@ void frr_pthread_destroy(struct frr_pthread *fpt)
XFREE(MTYPE_FRR_PTHREAD, fpt);
}

int frr_pthread_set_name(struct frr_pthread *fpt, const char *name,
const char *os_name)
int frr_pthread_set_name(struct frr_pthread *fpt)
{
int ret = 0;

if (name) {
pthread_mutex_lock(&fpt->mtx);
{
if (fpt->name)
XFREE(MTYPE_FRR_PTHREAD, fpt->name);
fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name);
}
pthread_mutex_unlock(&fpt->mtx);
thread_master_set_name(fpt->master, name);
}

if (os_name) {
pthread_mutex_lock(&fpt->mtx);
snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name);
pthread_mutex_unlock(&fpt->mtx);
#ifdef HAVE_PTHREAD_SETNAME_NP
# ifdef GNU_LINUX
ret = pthread_setname_np(fpt->thread, fpt->os_name);
ret = pthread_setname_np(fpt->thread, fpt->os_name);
# else /* NetBSD */
ret = pthread_setname_np(fpt->thread, fpt->os_name, NULL);
ret = pthread_setname_np(fpt->thread, fpt->os_name, NULL);
# endif
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(fpt->thread, fpt->os_name);
pthread_set_name_np(fpt->thread, fpt->os_name);
#endif
}

return ret;
}
@@ -273,8 +258,7 @@ static void *fpt_run(void *arg)

fpt->master->handle_signals = false;

if (fpt->os_name[0])
frr_pthread_set_name(fpt, NULL, fpt->os_name);
frr_pthread_set_name(fpt);

frr_pthread_notify_running(fpt);

@@ -133,16 +133,13 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr,
const char *name, const char *os_name);

/*
* Changes the name of the frr_pthread.
* Changes the name of the frr_pthread as reported by the operating
* system.
*
* @param fpt - the frr_pthread to operate on
* @param name - Human-readable name
* @param os_name - 16 characters thread name , including the null
* terminator ('\0') to set in os.
* @return - on success returns 0 otherwise nonzero error number.
*/
int frr_pthread_set_name(struct frr_pthread *fpt, const char *name,
const char *os_name);
int frr_pthread_set_name(struct frr_pthread *fpt);

/*
* Destroys an frr_pthread.
@@ -1572,8 +1572,13 @@ void thread_set_yield_time(struct thread *thread, unsigned long yield_time)

void thread_getrusage(RUSAGE_T *r)
{
#if defined RUSAGE_THREAD
#define FRR_RUSAGE RUSAGE_THREAD
#else
#define FRR_RUSAGE RUSAGE_SELF
#endif
monotime(&r->real);
getrusage(RUSAGE_SELF, &(r->cpu));
getrusage(FRR_RUSAGE, &(r->cpu));
}

/*

0 comments on commit 532ff7f

Please sign in to comment.
You can’t perform that action at this time.