mirror of
				http://www.pogo.org.uk/~mark/trx.git
				synced 2025-11-04 14:12:04 +01:00 
			
		
		
		
	Do not use the ambiguous sched_setscheduler()
POSIX specifies this is per-process, and GNU implemented it on the thread. Musl realises the problem with this and so doesn't implement it at all, forcing this more specific alternative to be used.
This commit is contained in:
		
							parent
							
								
									5c844e6996
								
							
						
					
					
						commit
						0c5ab0dfc1
					
				
							
								
								
									
										17
									
								
								sched.c
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								sched.c
									
									
									
									
									
								
							@ -17,6 +17,8 @@
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
#include <sched.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
@ -28,23 +30,20 @@
 | 
			
		||||
int go_realtime(void)
 | 
			
		||||
{
 | 
			
		||||
	int max_pri;
 | 
			
		||||
	struct sched_param sp;
 | 
			
		||||
 | 
			
		||||
	if (sched_getparam(0, &sp)) {
 | 
			
		||||
		perror("sched_getparam");
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
	const struct sched_param sp = {
 | 
			
		||||
		.sched_priority = REALTIME_PRIORITY,
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	max_pri = sched_get_priority_max(SCHED_FIFO);
 | 
			
		||||
	sp.sched_priority = REALTIME_PRIORITY;
 | 
			
		||||
 | 
			
		||||
	if (sp.sched_priority > max_pri) {
 | 
			
		||||
		fprintf(stderr, "Invalid priority (maximum %d)\n", max_pri);
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (sched_setscheduler(0, SCHED_FIFO, &sp)) {
 | 
			
		||||
		perror("sched_setscheduler");
 | 
			
		||||
	errno = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp);
 | 
			
		||||
	if (errno) {
 | 
			
		||||
		perror("pthread_setschedparam");
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user