diff options
| author | Tom Tromey | 2012-08-19 03:31:57 -0600 |
|---|---|---|
| committer | Tom Tromey | 2012-08-19 03:31:57 -0600 |
| commit | 1fb339bccd65db50adc2ad7f7290099808fc439d (patch) | |
| tree | 90cc4f1b9b4bf17f09031320825267232fa43143 | |
| parent | 9dad5e59e30c1b0d1047838048510f59552be492 (diff) | |
| download | emacs-1fb339bccd65db50adc2ad7f7290099808fc439d.tar.gz emacs-1fb339bccd65db50adc2ad7f7290099808fc439d.zip | |
add condition-mutex and condition-name
| -rw-r--r-- | src/thread.c | 27 | ||||
| -rw-r--r-- | test/automated/threads.el | 18 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/thread.c b/src/thread.c index b8ffb0662c3..4c21418d1c3 100644 --- a/src/thread.c +++ b/src/thread.c | |||
| @@ -425,6 +425,31 @@ thread. */) | |||
| 425 | return Qnil; | 425 | return Qnil; |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 428 | DEFUN ("condition-mutex", Fcondition_mutex, Scondition_mutex, 1, 1, 0, | ||
| 429 | doc: /* Return the mutex associated with CONDITION. */) | ||
| 430 | (Lisp_Object condition) | ||
| 431 | { | ||
| 432 | struct Lisp_CondVar *cvar; | ||
| 433 | |||
| 434 | CHECK_CONDVAR (condition); | ||
| 435 | cvar = XCONDVAR (condition); | ||
| 436 | |||
| 437 | return cvar->mutex; | ||
| 438 | } | ||
| 439 | |||
| 440 | DEFUN ("condition-name", Fcondition_name, Scondition_name, 1, 1, 0, | ||
| 441 | doc: /* Return the name of CONDITION. | ||
| 442 | If no name was given when CONDITION was created, return nil. */) | ||
| 443 | (Lisp_Object condition) | ||
| 444 | { | ||
| 445 | struct Lisp_CondVar *cvar; | ||
| 446 | |||
| 447 | CHECK_CONDVAR (condition); | ||
| 448 | cvar = XCONDVAR (condition); | ||
| 449 | |||
| 450 | return cvar->name; | ||
| 451 | } | ||
| 452 | |||
| 428 | void | 453 | void |
| 429 | finalize_one_condvar (struct Lisp_CondVar *condvar) | 454 | finalize_one_condvar (struct Lisp_CondVar *condvar) |
| 430 | { | 455 | { |
| @@ -898,6 +923,8 @@ syms_of_threads (void) | |||
| 898 | defsubr (&Smake_condition_variable); | 923 | defsubr (&Smake_condition_variable); |
| 899 | defsubr (&Scondition_wait); | 924 | defsubr (&Scondition_wait); |
| 900 | defsubr (&Scondition_notify); | 925 | defsubr (&Scondition_notify); |
| 926 | defsubr (&Scondition_mutex); | ||
| 927 | defsubr (&Scondition_name); | ||
| 901 | 928 | ||
| 902 | Qthreadp = intern_c_string ("threadp"); | 929 | Qthreadp = intern_c_string ("threadp"); |
| 903 | staticpro (&Qthreadp); | 930 | staticpro (&Qthreadp); |
diff --git a/test/automated/threads.el b/test/automated/threads.el index ce929fc0add..87e5eec218f 100644 --- a/test/automated/threads.el +++ b/test/automated/threads.el | |||
| @@ -188,4 +188,22 @@ | |||
| 188 | (should (eq (type-of (make-condition-variable (make-mutex))) | 188 | (should (eq (type-of (make-condition-variable (make-mutex))) |
| 189 | 'condition-variable))) | 189 | 'condition-variable))) |
| 190 | 190 | ||
| 191 | (ert-deftest threads-condvar-mutex () | ||
| 192 | "simple test of condition-mutex" | ||
| 193 | (should | ||
| 194 | (let ((m (make-mutex))) | ||
| 195 | (eq m (condition-mutex (make-condition-variable m)))))) | ||
| 196 | |||
| 197 | (ert-deftest threads-condvar-name () | ||
| 198 | "simple test of condition-name" | ||
| 199 | (should | ||
| 200 | (eq nil (condition-name (make-condition-variable (make-mutex)))))) | ||
| 201 | |||
| 202 | (ert-deftest threads-condvar-name-2 () | ||
| 203 | "another simple test of condition-name" | ||
| 204 | (should | ||
| 205 | (string= "hi bob" | ||
| 206 | (condition-name (make-condition-variable (make-mutex) | ||
| 207 | "hi bob"))))) | ||
| 208 | |||
| 191 | ;;; threads.el ends here | 209 | ;;; threads.el ends here |