From eacde9d0818dac743bc5c2562e35f0a6e949327e Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Mon, 9 Apr 2001 04:55:59 +0000 Subject: Update. 2001-04-08 Hans-Peter Nilsson * sysdeps/unix/sysv/linux/cris/Dist: New file. * sysdeps/unix/sysv/linux/cris/Makefile: New file. * sysdeps/unix/sysv/linux/cris/_G_config.h: New file. * sysdeps/unix/sysv/linux/cris/bits/fcntl.h: New file. * sysdeps/unix/sysv/linux/cris/bits/mman.h: New file. * sysdeps/unix/sysv/linux/cris/bits/resource.h: New file. * sysdeps/unix/sysv/linux/cris/brk.c: New file. * sysdeps/unix/sysv/linux/cris/chown.c: New file. * sysdeps/unix/sysv/linux/cris/clone.S: New file. * sysdeps/unix/sysv/linux/cris/fchown.c: New file. * sysdeps/unix/sysv/linux/cris/fcntl.c: New file. * sysdeps/unix/sysv/linux/cris/fxstat.c: New file. * sysdeps/unix/sysv/linux/cris/getegid.c: New file. * sysdeps/unix/sysv/linux/cris/geteuid.c: New file. * sysdeps/unix/sysv/linux/cris/getgid.c: New file. * sysdeps/unix/sysv/linux/cris/getgroups.c: New file. * sysdeps/unix/sysv/linux/cris/getresgid.c: New file. * sysdeps/unix/sysv/linux/cris/getresuid.c: New file. * sysdeps/unix/sysv/linux/cris/getrlimit.c: New file. * sysdeps/unix/sysv/linux/cris/getrlimit64.c: New file. * sysdeps/unix/sysv/linux/cris/getuid.c: New file. * sysdeps/unix/sysv/linux/cris/lchown.c: New file. * sysdeps/unix/sysv/linux/cris/lockf64.c: New file. * sysdeps/unix/sysv/linux/cris/lxstat.c: New file. * sysdeps/unix/sysv/linux/cris/mmap.S: New file. * sysdeps/unix/sysv/linux/cris/mmap64.S: New file. * sysdeps/unix/sysv/linux/cris/msgctl.c: New file. * sysdeps/unix/sysv/linux/cris/profil-counter.h: New file. * sysdeps/unix/sysv/linux/cris/register-dump.h: New file. * sysdeps/unix/sysv/linux/cris/semctl.c: New file. * sysdeps/unix/sysv/linux/cris/setegid.c: New file. * sysdeps/unix/sysv/linux/cris/seteuid.c: New file. * sysdeps/unix/sysv/linux/cris/setfsgid.c: New file. * sysdeps/unix/sysv/linux/cris/setfsuid.c: New file. * sysdeps/unix/sysv/linux/cris/setgid.c: New file. * sysdeps/unix/sysv/linux/cris/setgroups.c: New file. * sysdeps/unix/sysv/linux/cris/setregid.c: New file. * sysdeps/unix/sysv/linux/cris/setresgid.c: New file. * sysdeps/unix/sysv/linux/cris/setresuid.c: New file. * sysdeps/unix/sysv/linux/cris/setreuid.c: New file. * sysdeps/unix/sysv/linux/cris/setrlimit.c: New file. * sysdeps/unix/sysv/linux/cris/setuid.c: New file. * sysdeps/unix/sysv/linux/cris/shmctl.c: New file. * sysdeps/unix/sysv/linux/cris/socket.S: New file. * sysdeps/unix/sysv/linux/cris/sys/ucontext.h: New file. * sysdeps/unix/sysv/linux/cris/syscall.S: New file. * sysdeps/unix/sysv/linux/cris/sysdep.S: New file. * sysdeps/unix/sysv/linux/cris/sysdep.h: New file. * sysdeps/unix/sysv/linux/cris/vfork.S: New file. * sysdeps/unix/sysv/linux/cris/xstat.c: New file. 2001-04-08 Hans-Peter Nilsson * sysdeps/cris/Dist: New file. * sysdeps/cris/Implies: New file. * sysdeps/cris/Makefile: New file. * sysdeps/cris/__longjmp.S: New file. * sysdeps/cris/_mcount.S: New file. * sysdeps/cris/bits/endian.h: New file. * sysdeps/cris/bits/setjmp.h: New file. * sysdeps/cris/bits/string.h: New file. * sysdeps/cris/dl-machine.h: New file. * sysdeps/cris/elf/start.S: New file. * sysdeps/cris/machine-gmon.h: New file. * sysdeps/cris/memcopy.h: New file. * sysdeps/cris/memusage.h: New file. * sysdeps/cris/setjmp.S: New file. * sysdeps/cris/sysdep.h: New file. * sysdeps/cris/wordcopy.c: New file. 2001-04-08 Hans-Peter Nilsson * elf/elf.h: Add new relocations for CRIS. 2001-04-08 Hans-Peter Nilsson * shlib-versions: Add cases for Linux on CRIS. 2001-04-08 Hans-Peter Nilsson * configure.in (ASM_LINE_SEP tests): Handle CRIS assembly, with ';' for comments and '@' for line separator. 2001-04-08 Hans-Peter Nilsson * sysdeps/unix/sysv/linux/hppa/sysdep.h (INLINE_SYSCALL): Fix typo; s/==/=/ for assignment. 2001-04-08 Hans-Peter Nilsson * malloc/Makefile: Correct comment; mtrace is Perl, not AWK. 2001-04-08 Hans-Peter Nilsson * iconv/gconv_simple.c (internal_ucs4_loop_unaligned): Check for empty input before checking full output. 2001-04-08 Hans-Peter Nilsson * iconv/gconv.c (__gconv): Don't derefer parameter cd before checking if == -1L. 2001-04-08 Ulrich Drepper * inet/rexec.c (rexec_af): Avoid calling perror with errno being set. --- manual/examples/swapcontext.c | 99 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 manual/examples/swapcontext.c (limited to 'manual/examples') diff --git a/manual/examples/swapcontext.c b/manual/examples/swapcontext.c new file mode 100644 index 0000000000..f733510f88 --- /dev/null +++ b/manual/examples/swapcontext.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include + +/* Set by the signal handler. */ +static volatile int expired; + +/* The contexts. */ +static ucontext_t uc[3]; + +/* We do only a certain number of switches. */ +static int switches; + + +/* This is the function doing the work. It is just a + skeleton, real code has to be filled in. */ +static void +f (int n) +{ + int m = 0; + while (1) + { + /* This is where the work would be done. */ + if (++m % 100 == 0) + { + putchar ('.'); + fflush (stdout); + } + + /* Regularly the @var{expire} variable must be checked. */ + if (expired) + { + /* We do not want the program to run forever. */ + if (++switches == 20) + return; + + printf ("\nswitching from %d to %d\n", n, 3 - n); + expired = 0; + /* Switch to the other context, saving the current one. */ + swapcontext (&uc[n], &uc[3 - n]); + } + } +} + +/* This is the signal handler which simply set the variable. */ +void +handler (int signal) +{ + expired = 1; +} + + +int +main (void) +{ + struct sigaction sa; + struct itimerval it; + char st1[8192]; + char st2[8192]; + + /* Initialize the data structures for the interval timer. */ + sa.sa_flags = SA_RESTART; + sigfillset (&sa.sa_mask); + sa.sa_handler = handler; + it.it_interval.tv_sec = 0; + it.it_interval.tv_usec = 1; + it.it_value = it.it_interval; + + /* Install the timer and get the context we can manipulate. */ + if (sigaction (SIGPROF, &sa, NULL) < 0 + || setitimer (ITIMER_PROF, &it, NULL) < 0 + || getcontext (&uc[1]) == -1 + || getcontext (&uc[2]) == -1) + abort (); + + /* Create a context with a separate stack which causes the + function @code{f} to be call with the parameter @code{1}. + Note that the @code{uc_link} points to the main context + which will cause the program to terminate once the function + return. */ + uc[1].uc_link = &uc[0]; + uc[1].uc_stack.ss_sp = st1; + uc[1].uc_stack.ss_size = sizeof st1; + makecontext (&uc[1], (void (*) (void)) f, 1, 1); + + /* Similarly, but @code{2} is passed as the parameter to @code{f}. */ + uc[2].uc_link = &uc[0]; + uc[2].uc_stack.ss_sp = st2; + uc[2].uc_stack.ss_size = sizeof st2; + makecontext (&uc[2], (void (*) (void)) f, 1, 2); + + /* Start running. */ + swapcontext (&uc[0], &uc[1]); + putchar ('\n'); + + return 0; +} -- cgit 1.4.1