This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
TP-TR/chap1/canvas.c
Super_JK bd84de1a32 :,)
2022-03-29 17:17:15 +02:00

51 lines
1.3 KiB
C

#include <stdlib.h> // e x i t ( . . ) , EXIT_SUCCESS
#include "application-sigrt.h"
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#define __START__ 0
#define EXPECTING 1
#define OPERATING 2
#define __FINAL__ 3
sigset_t mask ;
volatile sig_atomic_t state = __START__ ;
void handleStart ( int signum , siginfo_t * info , void * context ) {
state = OPERATING ;
sigaddset (& mask , SIGRT_START );
sigprocmask ( SIG_SETMASK , & mask , NULL );
}
void handleFinal ( int signum , siginfo_t * info , void * context ) {
state = __FINAL__ ;
sigaddset (& mask , SIGRT_FINAL );
sigprocmask ( SIG_SETMASK , & mask , NULL );
}
int main ( int argc , char * argv []) {
sigfillset (& mask );
sigprocmask ( SIG_SETMASK , & mask , NULL );
struct sigaction descriptor ;
memset(& descriptor , 0 , sizeof ( descriptor ));
descriptor.sa_flags = SA_SIGINFO ;
descriptor.sa_sigaction = handleStart ;
sigaction ( SIGRT_START , & descriptor , NULL );
descriptor.sa_sigaction = handleFinal ;
sigaction ( SIGRT_FINAL , & descriptor , NULL );
state = EXPECTING ;
sigdelset (& mask , SIGRT_START );
sigprocmask ( SIG_SETMASK , & mask , NULL );
while ( state == EXPECTING )
pause();
sigdelset (& mask , SIGRT_FINAL );
sigprocmask ( SIG_SETMASK , & mask , NULL );
while ( state == OPERATING ) {
// Working on something . . .
printf("f");
}
exit ( EXIT_SUCCESS );
}