mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
WIP: timed mutex lock
This commit is contained in:
parent
1da1659a89
commit
5cb5540d2e
1 changed files with 30 additions and 1 deletions
31
srfi/18.sld
31
srfi/18.sld
|
@ -196,7 +196,12 @@
|
|||
}
|
||||
return_closcall1(data, k, lock); ")
|
||||
|
||||
(define-c mutex-lock!
|
||||
(define (mutex-lock! mutex . timeout)
|
||||
(if (pair? timeout)
|
||||
(%mutex-timedlock! mutex (car timeout))
|
||||
(%mutex-lock! mutex)))
|
||||
|
||||
(define-c %mutex-lock!
|
||||
"(void *data, int argc, closure _, object k, object obj)"
|
||||
" mutex m = (mutex) obj;
|
||||
Cyc_check_mutex(data, obj);
|
||||
|
@ -207,6 +212,30 @@
|
|||
}
|
||||
return_thread_runnable(data, boolean_t); ")
|
||||
|
||||
;; TODO: WIP, this is broken right now!
|
||||
(define-c %mutex-timedlock!
|
||||
"(void *data, int argc, closure _, object k, object obj, object timeout)"
|
||||
" mutex m = (mutex) obj;
|
||||
struct timespec tim;
|
||||
double value;
|
||||
Cyc_check_mutex(data, obj);
|
||||
Cyc_check_num(data, timeout);
|
||||
value = unbox_number(timeout);
|
||||
printf(\"tv_sec = %ld\\n\", tim.tv_sec);
|
||||
printf(\"tv_nsec = %ld\\n\", tim.tv_nsec);
|
||||
set_thread_blocked(data, k);
|
||||
// clock_gettime(CLOCK_REALTIME, &tim);
|
||||
// clock_gettime(CLOCK_MONOTONIC, &tim);
|
||||
gettimeofday(&tim, NULL);
|
||||
tim.tv_sec += (long)value;
|
||||
tim.tv_nsec += (long)((value - tim.tv_sec) * 1000 * NANOSECONDS_PER_MILLISECOND);
|
||||
int result = pthread_mutex_timedlock(&(m->lock), &tim);
|
||||
if (result != 0) {
|
||||
printf(\"result = %d\\n\", result);
|
||||
return_thread_runnable(data, boolean_f);
|
||||
}
|
||||
return_thread_runnable(data, boolean_t); ")
|
||||
|
||||
(define (mutex-unlock! mutex . opts)
|
||||
(cond
|
||||
((null? opts)
|
||||
|
|
Loading…
Add table
Reference in a new issue