Hi experts,
I have a pb w/ the source below. The appl. opens a device and attaches the
fd w/ select_attach().
The prio of the thread is set to 15 on startup but the callback is called w/
prio 10.
What I’m doing wrong.
BTW: If I start the appl. w/ the ‘on -p15 ionotisl’, the callback is called
w/ prio 15.
TIA, peter
/*
-
ionotisl.c
-
To test it:
-
ionotify -v &
-
ionotisl &
-
echo hello > /dev/ionotify
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <string.h>
#include <pthread.h>
#include <wchar.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <sys/neutrino.h>
#include <sched.h>
char *progname = “ionotisl”;
int ionotify_fd; /* file descriptor for talking to ionotify.c */
#define IONOTIFY_NAME “/dev/ionotify”
void
print_prio(char *str)
{
struct sched_param param;
int policy;
pthread_getschedparam(pthread_self(), &policy, ¶m);
printf("%s: func %s: tid=%d prio %d(%d)\n", progname, str,
pthread_self(), param.sched_curpriority, param.sched_priority);
}
int vfuWork(select_context_t *psuSelectContext_p, int lFd_p,
unsigned dwFlags_p, void *pvHandle_p)
{
int n;
unsigned char buf[81];
print_prio(“inside callback”);
n = read(ionotify_fd, buf, sizeof(buf));
buf[n] = NULL;
printf("%s: read: %s\n", progname, buf);
return 0;
}
void *
func1(void *handle)
{
dispatch_t *dpp;
select_attr_t suSelectAttr;
dispatch_context_t *ctp;
int i = 0;
print_prio(“prior dispatcher”);
// Dispatch Handle allokieren und initialisieren
if(NULL == (dpp = dispatch_create())){
printf("%s: disptach_create(), %s\n", progname, strerror(errno));
return NULL;
} // end if
if ((ionotify_fd = open (IONOTIFY_NAME, O_RDWR | O_NONBLOCK)) == -1) {
fprintf (stderr, “%s: open(’%s’) failed: %s\n”, progname, IONOTIFY_NAME,
strerror (errno));
return NULL;
}
memset(&suSelectAttr, 0, sizeof(suSelectAttr));
if(select_attach(dpp, &suSelectAttr, ionotify_fd, SELECT_FLAG_READ |
SELECT_FLAG_REARM,
vfuWork, NULL) == -1){
printf("%s: select_attach(), %s\n",progname, strerror(errno));
return NULL;
} // end if
ctp = dispatch_context_alloc(dpp);
if(ctp == NULL){
printf("%s: disptach_context_alloc(), %s\n", progname, strerror(errno));
return NULL;
} // end if
while(1){
if(NULL != (ctp = dispatch_block(ctp))){
dispatch_handler(ctp);
print_prio(“after dispatch_handler”);
i++;
} // end else
} // end while
}
int main (int argc, char **argv)
{
struct sched_param param;
pthread_attr_t attrib;
pthread_t threadID;
print_prio(“main”);
pthread_attr_init (&attrib);
pthread_attr_setinheritsched (&attrib, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy (&attrib, SCHED_FIFO);
param.sched_priority = 15;
pthread_attr_setschedparam (&attrib, ¶m);
pthread_create (&threadID, &attrib, func1, NULL);
pthread_join(threadID, NULL);
exit(0);
}