Index: s-linux-android.ads =================================================================== --- s-linux-android.ads (revision 219191) +++ s-linux-android.ads (working copy) @@ -47,6 +47,7 @@ subtype long is Interfaces.C.long; subtype suseconds_t is Interfaces.C.long; subtype time_t is Interfaces.C.long; + subtype clockid_t is Interfaces.C.int; type timespec is record tv_sec : time_t; Index: s-osinte-aix.ads =================================================================== --- s-osinte-aix.ads (revision 219191) +++ s-osinte-aix.ads (working copy) @@ -206,6 +206,11 @@ tp : access timespec) return int; pragma Import (C, clock_gettime, "clock_gettime"); + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + pragma Import (C, clock_getres, "clock_getres"); + function To_Duration (TS : timespec) return Duration; pragma Inline (To_Duration); Index: s-osinte-android.ads =================================================================== --- s-osinte-android.ads (revision 219191) +++ s-osinte-android.ads (working copy) @@ -211,6 +211,11 @@ (clock_id : clockid_t; tp : access timespec) return int; + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + pragma Import (C, clock_getres, "clock_getres"); + function To_Duration (TS : timespec) return Duration; pragma Inline (To_Duration); Index: s-osinte-darwin.adb =================================================================== --- s-osinte-darwin.adb (revision 219191) +++ s-osinte-darwin.adb (working copy) @@ -129,6 +129,36 @@ return Result; end clock_gettime; + ------------------ + -- clock_getres -- + ------------------ + + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int + is + pragma Unreferenced (clock_id); + + -- Darwin Threads don't have clock_getres. + + Nano : constant := 10**9; + nsec : int := 0; + Result : int := -1; + + function clock_get_res return int; + pragma Import (C, clock_get_res, "__gnat_clock_get_res"); + + begin + nsec := clock_get_res; + res.all := To_Timespec (Duration (0.0) + Duration (nsec) / Nano); + + if nsec > 0 then + Result := 0; + end if; + + return Result; + end clock_getres; + ----------------- -- sched_yield -- ----------------- Index: s-osinte-darwin.ads =================================================================== --- s-osinte-darwin.ads (revision 219191) +++ s-osinte-darwin.ads (working copy) @@ -189,6 +189,10 @@ (clock_id : clockid_t; tp : access timespec) return int; + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + function To_Duration (TS : timespec) return Duration; pragma Inline (To_Duration); Index: s-osinte-freebsd.ads =================================================================== --- s-osinte-freebsd.ads (revision 219191) +++ s-osinte-freebsd.ads (working copy) @@ -202,6 +202,11 @@ type clockid_t is new int; + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + pragma Import (C, clock_getres, "clock_getres"); + function clock_gettime (clock_id : clockid_t; tp : access timespec) Index: s-osinte-mingw.ads =================================================================== --- s-osinte-mingw.ads (revision 219191) +++ s-osinte-mingw.ads (working copy) @@ -53,6 +53,8 @@ subtype int is Interfaces.C.int; subtype long is Interfaces.C.long; + subtype LARGE_INTEGER is System.Win32.LARGE_INTEGER; + ------------------- -- General Types -- ------------------- @@ -104,6 +106,18 @@ procedure kill (sig : Signal); pragma Import (C, kill, "raise"); + ------------ + -- Clock -- + ------------ + + procedure QueryPerformanceFrequency + (lpPerformanceFreq : access LARGE_INTEGER); + pragma Import + (Stdcall, QueryPerformanceFrequency, "QueryPerformanceFrequency"); + + -- According to the spec, on XP and later than function cannot fail, + -- so we ignore the return value and import it as a procedure. + ------------- -- Threads -- ------------- Index: s-osinte-solaris-posix.ads =================================================================== --- s-osinte-solaris-posix.ads (revision 219191) +++ s-osinte-solaris-posix.ads (working copy) @@ -189,6 +189,11 @@ type clockid_t is new int; + function clock_getres + (clock_id : clockid_t; + res : access timespec) return int; + pragma Import (C, clock_getres, "clock_getres"); + function clock_gettime (clock_id : clockid_t; tp : access timespec) return int; Index: s-taprop-mingw.adb =================================================================== --- s-taprop-mingw.adb (revision 219191) +++ s-taprop-mingw.adb (working copy) @@ -1076,8 +1076,10 @@ ------------------- function RT_Resolution return Duration is + Ticks_Per_Second : aliased LARGE_INTEGER; begin - return 0.000_001; -- 1 micro-second + QueryPerformanceFrequency (Ticks_Per_Second'Access); + return Duration (1.0 / Ticks_Per_Second); end RT_Resolution; ---------------- Index: s-taprop-posix.adb =================================================================== --- s-taprop-posix.adb (revision 219191) +++ s-taprop-posix.adb (working copy) @@ -743,8 +743,13 @@ ------------------- function RT_Resolution return Duration is + TS : aliased timespec; + Result : Interfaces.C.int; begin - return 10#1.0#E-6; + Result := clock_getres (OSC.CLOCK_REALTIME, TS'Unchecked_Access); + pragma Assert (Result = 0); + + return To_Duration (TS); end RT_Resolution; ------------ Index: s-taprop-solaris.adb =================================================================== --- s-taprop-solaris.adb (revision 219191) +++ s-taprop-solaris.adb (working copy) @@ -785,8 +785,13 @@ ------------------- function RT_Resolution return Duration is + TS : aliased timespec; + Result : Interfaces.C.int; begin - return 10#1.0#E-6; + Result := clock_getres (OSC.CLOCK_REALTIME, TS'Unchecked_Access); + pragma Assert (Result = 0); + + return To_Duration (TS); end RT_Resolution; ----------- Index: thread.c =================================================================== --- thread.c (revision 219191) +++ thread.c (working copy) @@ -54,3 +54,35 @@ } #endif + +#if defined (__APPLE__) +#include +#include +#endif + +/* Return the clock ticks per nanosecond for Posix systems lacking the + Posix extension function clock_getres, or else 0 nsecs on error. */ + +int +__gnat_clock_get_res (void) +{ +#if defined (__APPLE__) + clock_serv_t clock_port; + mach_msg_type_number_t count; + int nsecs; + int result; + + count = 1; + result = host_get_clock_service + (mach_host_self (), SYSTEM_CLOCK, &clock_port); + + if (result == KERN_SUCCESS) + result = clock_get_attributes (clock_port, CLOCK_GET_TIME_RES, + (clock_attr_t) &nsecs, &count); + + if (result == KERN_SUCCESS) + return nsecs; +#endif + + return 0; +}