Corrected some bugs in the implementation of thread_sleep/1. Changed implementation to make the call succeed and return immediately when the argument is zero or a negative value (matching the current threads standardization proposal).
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1757 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
9de3c0c7a9
commit
139e50a1ca
29
C/threads.c
29
C/threads.c
@ -201,26 +201,11 @@ p_thread_sleep(void)
|
||||
struct timespec req, oreq ;
|
||||
req.tv_sec = time;
|
||||
req.tv_nsec = ntime;
|
||||
if (!nanosleep(&req, &oreq)) {
|
||||
if (nanosleep(&req, &oreq)) {
|
||||
#if HAVE_STRERROR
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "%s in thread_sleep/2", strerror(errno));
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "%s in thread_sleep/1", strerror(errno));
|
||||
#else
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "error %d in thread_sleep/2", errno);
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
return Yap_unify(ARG3,MkIntegerTerm(oreq.tv_sec)) &&
|
||||
Yap_unify(ARG4,MkIntegerTerm(oreq.tv_nsec));
|
||||
#elif HAVE_NANOSLEEP
|
||||
UInt ntime = IntegerOfTerm(Deref(ARG2));
|
||||
struct timespec req, oreq ;
|
||||
req.tv_sec = time;
|
||||
req.tv_nsec = ntime;
|
||||
if (!nanosleep(&req, &oreq)) {
|
||||
#if HAVE_STRERROR
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "%s in thread_sleep/2", strerror(errno));
|
||||
#else
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "error %d in thread_sleep/2", errno);
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "error %d in thread_sleep/1", errno);
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
@ -230,15 +215,15 @@ p_thread_sleep(void)
|
||||
UInt rtime;
|
||||
if ((rtime = sleep(time)) < 0) {
|
||||
#if HAVE_STRERROR
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "%s in thread_sleep/2", strerror(errno));
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "%s in thread_sleep/1", strerror(errno));
|
||||
#else
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "error %d in thread_sleep/2", errno);
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "error %d in thread_sleep/1", errno);
|
||||
#endif
|
||||
}
|
||||
return Yap_unify(ARG3,MkIntegerTerm(rtime)) &&
|
||||
Yap_unify(ARG4,MkIntTerm(0L));
|
||||
#else
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "no support for thread_sleep in this YAP configuration");
|
||||
Yap_Error(OPERATING_SYSTEM_ERROR, ARG1, "no support for thread_sleep/1 in this YAP configuration");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -622,7 +607,7 @@ void Yap_InitThreadPreds(void)
|
||||
Yap_InitCPred("$signal_thread", 1, p_thread_signal, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred("$nof_threads", 1, p_nof_threads, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred("$nof_threads_created", 1, p_nof_threads_created, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred("$thread_sleep", 2, p_thread_sleep, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred("$thread_sleep", 4, p_thread_sleep, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred("$thread_runtime", 1, p_thread_runtime, SafePredFlag|HiddenPredFlag);
|
||||
}
|
||||
|
||||
|
@ -10512,7 +10512,8 @@ and succeeds silently.
|
||||
@snindex thread_sleep/1
|
||||
@cnindex thread_sleep/1
|
||||
Make current thread sleep for @var{Time} seconds. @var{Time} may be an
|
||||
integer or a floating point number. This call should not be used if
|
||||
integer or a floating point number. When time is zero or a negative value
|
||||
the call succeeds and returns immediately. This call should not be used if
|
||||
alarms are also being used.
|
||||
@end table
|
||||
|
||||
|
@ -504,16 +504,19 @@ thread_sleep(Time) :-
|
||||
var(Time), !,
|
||||
'$do_error'(instantiation_error,thread_sleep(Time)).
|
||||
thread_sleep(Time) :-
|
||||
integer(Time), Time >= 0, !,
|
||||
'$thread_sleep'(Time,0,_,_).
|
||||
integer(Time), !,
|
||||
( Time > 0 ->
|
||||
'$thread_sleep'(Time,0,_,_)
|
||||
; true
|
||||
).
|
||||
thread_sleep(Time) :-
|
||||
float(Time), Time >= 0, !,
|
||||
float(Time), !,
|
||||
( Time > 0 ->
|
||||
STime is integer(float_integer_part(Time)),
|
||||
NTime is integer(float_fractional_part(Time))*1000000000,
|
||||
'$thread_sleep'(STime,NTime,_,_).
|
||||
thread_sleep(Time) :-
|
||||
number(Time),
|
||||
'$do_error'(domain_error(not_less_than_zero,Time),thread_sleep(Time)).
|
||||
'$thread_sleep'(STime,NTime,_,_)
|
||||
; true
|
||||
).
|
||||
thread_sleep(Time) :-
|
||||
'$do_error'(type_error(number,Time),thread_sleep(Time)).
|
||||
|
||||
|
Reference in New Issue
Block a user