diff options
Diffstat (limited to 'src/thread.c')
| -rw-r--r-- | src/thread.c | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/src/thread.c b/src/thread.c index 5da2e10f1ae..80557e5d5ee 100644 --- a/src/thread.c +++ b/src/thread.c | |||
| @@ -35,7 +35,83 @@ static struct thread_state *all_threads = &primary_thread; | |||
| 35 | 35 | ||
| 36 | sys_mutex_t global_lock; | 36 | sys_mutex_t global_lock; |
| 37 | 37 | ||
| 38 | Lisp_Object Qthreadp; | 38 | Lisp_Object Qthreadp, Qmutexp; |
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | struct Lisp_Mutex | ||
| 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 */) | ||
| 51 | (void) | ||
| 52 | { | ||
| 53 | struct Lisp_Mutex *mutex; | ||
| 54 | Lisp_Object result; | ||
| 55 | |||
| 56 | mutex = ALLOCATE_PSEUDOVECTOR (struct Lisp_Mutex, mutex, PVEC_MUTEX); | ||
| 57 | memset ((char *) mutex + offsetof (struct Lisp_Mutex, mutex), | ||
| 58 | 0, sizeof (struct Lisp_Mutex) - offsetof (struct Lisp_Mutex, | ||
| 59 | mutex)); | ||
| 60 | lisp_mutex_init (&mutex->mutex); | ||
| 61 | |||
| 62 | XSETMUTEX (result, mutex); | ||
| 63 | return result; | ||
| 64 | } | ||
| 65 | |||
| 66 | static void | ||
| 67 | mutex_lock_callback (void *arg) | ||
| 68 | { | ||
| 69 | struct Lisp_Mutex *mutex = arg; | ||
| 70 | |||
| 71 | /* This calls post_acquire_global_lock. */ | ||
| 72 | lisp_mutex_lock (&mutex->mutex); | ||
| 73 | } | ||
| 74 | |||
| 75 | DEFUN ("mutex-lock", Fmutex_lock, Smutex_lock, 1, 1, 0, | ||
| 76 | doc: /* FIXME */) | ||
| 77 | (Lisp_Object obj) | ||
| 78 | { | ||
| 79 | struct Lisp_Mutex *mutex; | ||
| 80 | |||
| 81 | CHECK_MUTEX (obj); | ||
| 82 | mutex = XMUTEX (obj); | ||
| 83 | |||
| 84 | flush_stack_call_func (mutex_lock_callback, mutex); | ||
| 85 | return Qnil; | ||
| 86 | } | ||
| 87 | |||
| 88 | static void | ||
| 89 | mutex_unlock_callback (void *arg) | ||
| 90 | { | ||
| 91 | struct Lisp_Mutex *mutex = arg; | ||
| 92 | |||
| 93 | /* This calls post_acquire_global_lock. */ | ||
| 94 | lisp_mutex_unlock (&mutex->mutex); | ||
| 95 | } | ||
| 96 | |||
| 97 | DEFUN ("mutex-unlock", Fmutex_unlock, Smutex_unlock, 1, 1, 0, | ||
| 98 | doc: /* FIXME */) | ||
| 99 | (Lisp_Object obj) | ||
| 100 | { | ||
| 101 | struct Lisp_Mutex *mutex; | ||
| 102 | |||
| 103 | CHECK_MUTEX (obj); | ||
| 104 | mutex = XMUTEX (obj); | ||
| 105 | |||
| 106 | flush_stack_call_func (mutex_unlock_callback, mutex); | ||
| 107 | return Qnil; | ||
| 108 | } | ||
| 109 | |||
| 110 | void | ||
| 111 | finalize_one_mutex (struct Lisp_Mutex *mutex) | ||
| 112 | { | ||
| 113 | lisp_mutex_destroy (&mutex->mutex); | ||
| 114 | } | ||
| 39 | 115 | ||
| 40 | 116 | ||
| 41 | 117 | ||
| @@ -463,7 +539,12 @@ syms_of_threads (void) | |||
| 463 | defsubr (&Sthread_alive_p); | 539 | defsubr (&Sthread_alive_p); |
| 464 | defsubr (&Sthread_join); | 540 | defsubr (&Sthread_join); |
| 465 | defsubr (&Sall_threads); | 541 | defsubr (&Sall_threads); |
| 542 | defsubr (&Smake_mutex); | ||
| 543 | defsubr (&Smutex_lock); | ||
| 544 | defsubr (&Smutex_unlock); | ||
| 466 | 545 | ||
| 467 | Qthreadp = intern_c_string ("threadp"); | 546 | Qthreadp = intern_c_string ("threadp"); |
| 468 | staticpro (&Qthreadp); | 547 | staticpro (&Qthreadp); |
| 548 | Qmutexp = intern_c_string ("mutexp"); | ||
| 549 | staticpro (&Qmutexp); | ||
| 469 | } | 550 | } |