File indexing completed on 2025-05-11 08:24:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifdef HAVE_CONFIG_H
0041 #include "config.h"
0042 #endif
0043
0044 #include <unistd.h>
0045 #include <signal.h>
0046
0047 #include <rtems/score/todimpl.h>
0048 #include <rtems/score/watchdogimpl.h>
0049
0050 #if ISR_LOCK_NEEDS_OBJECT
0051 static ISR_lock_Control _POSIX_signals_Alarm_lock =
0052 ISR_LOCK_INITIALIZER( "POSIX Alarm" );
0053 #endif
0054
0055 static void _POSIX_signals_Alarm_TSR( Watchdog_Control *the_watchdog )
0056 {
0057 int status;
0058
0059 status = kill( getpid(), SIGALRM );
0060
0061 #if defined(RTEMS_DEBUG)
0062
0063
0064
0065
0066 _Assert(status == 0);
0067 #else
0068 (void) status;
0069 #endif
0070 }
0071
0072 static Watchdog_Control _POSIX_signals_Alarm_watchdog = WATCHDOG_INITIALIZER(
0073 _POSIX_signals_Alarm_TSR
0074 );
0075
0076 unsigned int alarm(
0077 unsigned int seconds
0078 )
0079 {
0080 unsigned int remaining;
0081 Watchdog_Control *the_watchdog;
0082 ISR_lock_Context lock_context;
0083 ISR_lock_Context lock_context2;
0084 Per_CPU_Control *cpu;
0085 uint64_t now;
0086 uint32_t ticks_per_second;
0087 uint32_t ticks;
0088
0089 the_watchdog = &_POSIX_signals_Alarm_watchdog;
0090 ticks_per_second = TOD_TICKS_PER_SECOND;
0091 ticks = seconds * ticks_per_second;
0092
0093 _ISR_lock_ISR_disable_and_acquire(
0094 &_POSIX_signals_Alarm_lock,
0095 &lock_context
0096 );
0097
0098 cpu = _Watchdog_Get_CPU( the_watchdog );
0099 _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context2 );
0100 now = cpu->Watchdog.ticks;
0101
0102 remaining = (unsigned long) _Watchdog_Cancel(
0103 &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ],
0104 the_watchdog,
0105 now
0106 );
0107
0108 if ( ticks != 0 ) {
0109 _Watchdog_Insert(
0110 &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ],
0111 the_watchdog,
0112 now + ticks
0113 );
0114 }
0115
0116 _Watchdog_Per_CPU_release_critical( cpu, &lock_context2 );
0117 _ISR_lock_Release_and_ISR_enable(
0118 &_POSIX_signals_Alarm_lock,
0119 &lock_context
0120 );
0121
0122 return ( remaining + ticks_per_second - 1 ) / ticks_per_second;
0123 }