diff options
| author | Tom Tromey | 2012-08-15 13:14:14 -0600 |
|---|---|---|
| committer | Tom Tromey | 2012-08-15 13:14:14 -0600 |
| commit | 8d3566c6a0eb3977c3115ae100a357f8d63cf77e (patch) | |
| tree | 7343b2236bdf20d5026483eb7f4dc15b76ee331a | |
| parent | fc196ac95224330384227da8f5706631701e3610 (diff) | |
| download | emacs-8d3566c6a0eb3977c3115ae100a357f8d63cf77e.tar.gz emacs-8d3566c6a0eb3977c3115ae100a357f8d63cf77e.zip | |
This adds names to mutexes. This seemed like a nice debugging
extension.
| -rw-r--r-- | src/print.c | 10 | ||||
| -rw-r--r-- | src/thread.c | 25 | ||||
| -rw-r--r-- | src/thread.h | 9 |
3 files changed, 31 insertions, 13 deletions
diff --git a/src/print.c b/src/print.c index 42e7241ecba..b14a769dc74 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -1957,10 +1957,14 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag | |||
| 1957 | } | 1957 | } |
| 1958 | else if (MUTEXP (obj)) | 1958 | else if (MUTEXP (obj)) |
| 1959 | { | 1959 | { |
| 1960 | int len; | ||
| 1961 | strout ("#<mutex ", -1, -1, printcharfun); | 1960 | strout ("#<mutex ", -1, -1, printcharfun); |
| 1962 | len = sprintf (buf, "%p", XMUTEX (obj)); | 1961 | if (STRINGP (XMUTEX (obj)->name)) |
| 1963 | strout (buf, len, len, printcharfun); | 1962 | print_string (XMUTEX (obj)->name, printcharfun); |
| 1963 | else | ||
| 1964 | { | ||
| 1965 | int len = sprintf (buf, "%p", XMUTEX (obj)); | ||
| 1966 | strout (buf, len, len, printcharfun); | ||
| 1967 | } | ||
| 1964 | PRINTCHAR ('>'); | 1968 | PRINTCHAR ('>'); |
| 1965 | } | 1969 | } |
| 1966 | else | 1970 | else |
diff --git a/src/thread.c b/src/thread.c index 80557e5d5ee..9ec418f9871 100644 --- a/src/thread.c +++ b/src/thread.c | |||
| @@ -39,16 +39,9 @@ Lisp_Object Qthreadp, Qmutexp; | |||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | struct Lisp_Mutex | 42 | DEFUN ("make-mutex", Fmake_mutex, Smake_mutex, 0, 1, 0, |
| 43 | { | ||
| 44 | struct vectorlike_header header; | ||
| 45 | |||
| 46 | lisp_mutex_t mutex; | ||
| 47 | }; | ||
| 48 | |||
| 49 | DEFUN ("make-mutex", Fmake_mutex, Smake_mutex, 0, 0, 0, | ||
| 50 | doc: /* FIXME */) | 43 | doc: /* FIXME */) |
| 51 | (void) | 44 | (Lisp_Object name) |
| 52 | { | 45 | { |
| 53 | struct Lisp_Mutex *mutex; | 46 | struct Lisp_Mutex *mutex; |
| 54 | Lisp_Object result; | 47 | Lisp_Object result; |
| @@ -57,6 +50,7 @@ DEFUN ("make-mutex", Fmake_mutex, Smake_mutex, 0, 0, 0, | |||
| 57 | memset ((char *) mutex + offsetof (struct Lisp_Mutex, mutex), | 50 | memset ((char *) mutex + offsetof (struct Lisp_Mutex, mutex), |
| 58 | 0, sizeof (struct Lisp_Mutex) - offsetof (struct Lisp_Mutex, | 51 | 0, sizeof (struct Lisp_Mutex) - offsetof (struct Lisp_Mutex, |
| 59 | mutex)); | 52 | mutex)); |
| 53 | mutex->name = name; | ||
| 60 | lisp_mutex_init (&mutex->mutex); | 54 | lisp_mutex_init (&mutex->mutex); |
| 61 | 55 | ||
| 62 | XSETMUTEX (result, mutex); | 56 | XSETMUTEX (result, mutex); |
| @@ -107,6 +101,18 @@ DEFUN ("mutex-unlock", Fmutex_unlock, Smutex_unlock, 1, 1, 0, | |||
| 107 | return Qnil; | 101 | return Qnil; |
| 108 | } | 102 | } |
| 109 | 103 | ||
| 104 | DEFUN ("mutex-name", Fmutex_name, Smutex_name, 1, 1, 0, | ||
| 105 | doc: /* FIXME */) | ||
| 106 | (Lisp_Object obj) | ||
| 107 | { | ||
| 108 | struct Lisp_Mutex *mutex; | ||
| 109 | |||
| 110 | CHECK_MUTEX (obj); | ||
| 111 | mutex = XMUTEX (obj); | ||
| 112 | |||
| 113 | return mutex->name; | ||
| 114 | } | ||
| 115 | |||
| 110 | void | 116 | void |
| 111 | finalize_one_mutex (struct Lisp_Mutex *mutex) | 117 | finalize_one_mutex (struct Lisp_Mutex *mutex) |
| 112 | { | 118 | { |
| @@ -542,6 +548,7 @@ syms_of_threads (void) | |||
| 542 | defsubr (&Smake_mutex); | 548 | defsubr (&Smake_mutex); |
| 543 | defsubr (&Smutex_lock); | 549 | defsubr (&Smutex_lock); |
| 544 | defsubr (&Smutex_unlock); | 550 | defsubr (&Smutex_unlock); |
| 551 | defsubr (&Smutex_name); | ||
| 545 | 552 | ||
| 546 | Qthreadp = intern_c_string ("threadp"); | 553 | Qthreadp = intern_c_string ("threadp"); |
| 547 | staticpro (&Qthreadp); | 554 | staticpro (&Qthreadp); |
diff --git a/src/thread.h b/src/thread.h index d3ec38a22b9..1a193b1e4ae 100644 --- a/src/thread.h +++ b/src/thread.h | |||
| @@ -168,7 +168,14 @@ struct thread_state | |||
| 168 | struct thread_state *next_thread; | 168 | struct thread_state *next_thread; |
| 169 | }; | 169 | }; |
| 170 | 170 | ||
| 171 | struct Lisp_Mutex; | 171 | struct Lisp_Mutex |
| 172 | { | ||
| 173 | struct vectorlike_header header; | ||
| 174 | |||
| 175 | Lisp_Object name; | ||
| 176 | |||
| 177 | lisp_mutex_t mutex; | ||
| 178 | }; | ||
| 172 | 179 | ||
| 173 | extern struct thread_state *current_thread; | 180 | extern struct thread_state *current_thread; |
| 174 | 181 | ||