From 1fb339bccd65db50adc2ad7f7290099808fc439d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 19 Aug 2012 03:31:57 -0600 Subject: [PATCH] add condition-mutex and condition-name --- src/thread.c | 27 +++++++++++++++++++++++++++ test/automated/threads.el | 18 ++++++++++++++++++ 2 files changed, 45 insertions(+) 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. */) return Qnil; } +DEFUN ("condition-mutex", Fcondition_mutex, Scondition_mutex, 1, 1, 0, + doc: /* Return the mutex associated with CONDITION. */) + (Lisp_Object condition) +{ + struct Lisp_CondVar *cvar; + + CHECK_CONDVAR (condition); + cvar = XCONDVAR (condition); + + return cvar->mutex; +} + +DEFUN ("condition-name", Fcondition_name, Scondition_name, 1, 1, 0, + doc: /* Return the name of CONDITION. +If no name was given when CONDITION was created, return nil. */) + (Lisp_Object condition) +{ + struct Lisp_CondVar *cvar; + + CHECK_CONDVAR (condition); + cvar = XCONDVAR (condition); + + return cvar->name; +} + void finalize_one_condvar (struct Lisp_CondVar *condvar) { @@ -898,6 +923,8 @@ syms_of_threads (void) defsubr (&Smake_condition_variable); defsubr (&Scondition_wait); defsubr (&Scondition_notify); + defsubr (&Scondition_mutex); + defsubr (&Scondition_name); Qthreadp = intern_c_string ("threadp"); 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 @@ (should (eq (type-of (make-condition-variable (make-mutex))) 'condition-variable))) +(ert-deftest threads-condvar-mutex () + "simple test of condition-mutex" + (should + (let ((m (make-mutex))) + (eq m (condition-mutex (make-condition-variable m)))))) + +(ert-deftest threads-condvar-name () + "simple test of condition-name" + (should + (eq nil (condition-name (make-condition-variable (make-mutex)))))) + +(ert-deftest threads-condvar-name-2 () + "another simple test of condition-name" + (should + (string= "hi bob" + (condition-name (make-condition-variable (make-mutex) + "hi bob"))))) + ;;; threads.el ends here -- 2.39.5