mirror of
				https://github.com/Zygo/bees.git
				synced 2025-11-04 04:00:36 +01:00 
			
		
		
		
	BeesNote: if thread name was not set, get it from Task or pthread_getname_np
Threads from the Task module in libcrucible don't set BeesNote::tl_name. Even if they did, in Task context the thread name is unspecific to the point of meaninglessness. Use the Task::print method as the name for such threads, and be sure that future Task print functions are designed for that usage. The extra complexity in BeesNote::get_name() seems preferable to bombarding pthread_setname_np hundreds or thousands of times per second. FIXME: we are now calling Task::print() on every BeesNote, which is effectively unconditionally. Maybe we should have Task::print() and get_name() return a closure, or just evaluate Task::print() once and cache it in TaskState, or define Task's constructor with a string argument instead of the current print_fn closure. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
		
							
								
								
									
										14
									
								
								src/bees.cc
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/bees.cc
									
									
									
									
									
								
							@@ -120,7 +120,7 @@ BeesNote::~BeesNote()
 | 
			
		||||
BeesNote::BeesNote(function<void(ostream &os)> f) :
 | 
			
		||||
	m_func(f)
 | 
			
		||||
{
 | 
			
		||||
	m_name = tl_name;
 | 
			
		||||
	m_name = get_name();
 | 
			
		||||
	m_prev = tl_next;
 | 
			
		||||
	tl_next = this;
 | 
			
		||||
	unique_lock<mutex> lock(s_mutex);
 | 
			
		||||
@@ -137,10 +137,16 @@ string
 | 
			
		||||
BeesNote::get_name()
 | 
			
		||||
{
 | 
			
		||||
	if (tl_name.empty()) {
 | 
			
		||||
		return "bees";
 | 
			
		||||
	} else {
 | 
			
		||||
		return tl_name;
 | 
			
		||||
		char buf[100];
 | 
			
		||||
		memset(buf, '\0', sizeof(buf));
 | 
			
		||||
		pthread_getname_np(pthread_self(), buf, sizeof(buf));
 | 
			
		||||
		buf[sizeof(buf) - 1] = '\0';
 | 
			
		||||
		tl_name = buf;
 | 
			
		||||
		if (tl_name.empty()) {
 | 
			
		||||
			tl_name = "bees";
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return tl_name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BeesNote::ThreadStatusMap
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user