mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
[macos] no pthread_condattr_setclock() #2302
This commit is contained in:
parent
fec64cfc33
commit
b81ab750cc
@ -45,38 +45,11 @@ pid_t waitpid(pid_t pid, int* state, int options){ // FIXME
|
|||||||
*/
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pthread_condmonotonic_init(pthread_cond_t* cond){
|
|
||||||
if(pthread_cond_init(cond, &cat)){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#else // not windows
|
#else // not windows
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
// initializes a pthread_cond_t to use CLOCK_MONOTONIC (as opposed to the
|
|
||||||
// default CLOCK_REALTIME) if possible. if not possible, initializes a
|
|
||||||
// regular ol' CLOCK_REALTIME condvar.
|
|
||||||
int pthread_condmonotonic_init(pthread_cond_t* cond){
|
|
||||||
pthread_condattr_t cat;
|
|
||||||
if(pthread_condattr_init(&cat)){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(pthread_condattr_setclock(&cat, CLOCK_MONOTONIC)){
|
|
||||||
pthread_condattr_destroy(&cat);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(pthread_cond_init(cond, &cat)){
|
|
||||||
pthread_condattr_destroy(&cat);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pthread_condattr_destroy(&cat);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int set_fd_nonblocking(int fd, unsigned state, unsigned* oldstate){
|
int set_fd_nonblocking(int fd, unsigned state, unsigned* oldstate){
|
||||||
int flags = fcntl(fd, F_GETFL);
|
int flags = fcntl(fd, F_GETFL);
|
||||||
if(flags < 0){
|
if(flags < 0){
|
||||||
@ -152,3 +125,25 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *request
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// initializes a pthread_cond_t to use CLOCK_MONOTONIC (as opposed to the
|
||||||
|
// default CLOCK_REALTIME) if possible. if not possible, initializes a
|
||||||
|
// regular ol' CLOCK_REALTIME condvar.
|
||||||
|
int pthread_condmonotonic_init(pthread_cond_t* cond){
|
||||||
|
pthread_condattr_t cat;
|
||||||
|
if(pthread_condattr_init(&cat)){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#ifndef __APPLE__
|
||||||
|
if(pthread_condattr_setclock(&cat, CLOCK_MONOTONIC)){
|
||||||
|
pthread_condattr_destroy(&cat);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if(pthread_cond_init(cond, &cat)){
|
||||||
|
pthread_condattr_destroy(&cat);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pthread_condattr_destroy(&cat);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user