| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * be found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * NaCl Server Runtime interruptible binary mutex, based on nacl_sync | 8 * NaCl Server Runtime interruptible binary mutex, based on nacl_sync |
| 9 * interface. | 9 * interface. |
| 10 */ | 10 */ |
| 11 | 11 |
| 12 #include "native_client/src/include/portability.h" | 12 #include "native_client/src/include/portability.h" |
| 13 #include "native_client/src/shared/platform/nacl_interruptible_mutex.h" | 13 #include "native_client/src/shared/platform/nacl_interruptible_mutex.h" |
| 14 #include "native_client/src/shared/platform/nacl_log.h" | 14 #include "native_client/src/shared/platform/nacl_log.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 NaClXCondVarSignal(&mp->cv); | 87 NaClXCondVarSignal(&mp->cv); |
| 88 NaClXMutexUnlock(&mp->mu); | 88 NaClXMutexUnlock(&mp->mu); |
| 89 return rv; | 89 return rv; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void NaClIntrMutexIntr(struct NaClIntrMutex *mp) { | 92 void NaClIntrMutexIntr(struct NaClIntrMutex *mp) { |
| 93 NaClXMutexLock(&mp->mu); | 93 NaClXMutexLock(&mp->mu); |
| 94 if (NACL_INTR_LOCK_HELD == mp->lock_state) { | 94 if (NACL_INTR_LOCK_HELD == mp->lock_state) { |
| 95 /* potentially there are threads waiting for this thread */ | 95 /* potentially there are threads waiting for this thread */ |
| 96 mp->lock_state = NACL_INTR_LOCK_INTERRUPTED; | 96 mp->lock_state = NACL_INTR_LOCK_INTERRUPTED; |
| 97 NaClCondVarBroadcast(&mp->cv); | 97 NaClXCondVarBroadcast(&mp->cv); |
| 98 } else { | 98 } else { |
| 99 mp->lock_state = NACL_INTR_LOCK_INTERRUPTED; | 99 mp->lock_state = NACL_INTR_LOCK_INTERRUPTED; |
| 100 } | 100 } |
| 101 NaClXMutexUnlock(&mp->mu); | 101 NaClXMutexUnlock(&mp->mu); |
| 102 } | 102 } |
| 103 | 103 |
| 104 /* | 104 /* |
| 105 * Reset the interruptible mutex, presumably after the condition | 105 * Reset the interruptible mutex, presumably after the condition |
| 106 * causing the interrupt has been cleared. In our case, this would be | 106 * causing the interrupt has been cleared. In our case, this would be |
| 107 * an E_MOVE_ADDRESS_SPACE induced address space move. | 107 * an E_MOVE_ADDRESS_SPACE induced address space move. |
| 108 * | 108 * |
| 109 * This is safe to invoke only after all threads are known to be in a | 109 * This is safe to invoke only after all threads are known to be in a |
| 110 * quiescent state -- i.e., will no longer call | 110 * quiescent state -- i.e., will no longer call |
| 111 * NaClIntrMutex{Try,}Lock on the interruptible mutex -- since there | 111 * NaClIntrMutex{Try,}Lock on the interruptible mutex -- since there |
| 112 * is no guarntee that all the threads awaken by NaClIntrMutexIntr | 112 * is no guarntee that all the threads awaken by NaClIntrMutexIntr |
| 113 * have actually been run yet. | 113 * have actually been run yet. |
| 114 */ | 114 */ |
| 115 void NaClIntrMutexReset(struct NaClIntrMutex *mp) { | 115 void NaClIntrMutexReset(struct NaClIntrMutex *mp) { |
| 116 NaClXMutexLock(&mp->mu); | 116 NaClXMutexLock(&mp->mu); |
| 117 if (NACL_INTR_LOCK_INTERRUPTED != mp->lock_state) { | 117 if (NACL_INTR_LOCK_INTERRUPTED != mp->lock_state) { |
| 118 NaClLog(LOG_FATAL, | 118 NaClLog(LOG_FATAL, |
| 119 "NaClIntrMutexReset: lock at 0x%08"NACL_PRIxPTR" not interrupted\n", | 119 "NaClIntrMutexReset: lock at 0x%08"NACL_PRIxPTR" not interrupted\n", |
| 120 (uintptr_t) mp); | 120 (uintptr_t) mp); |
| 121 } | 121 } |
| 122 mp->lock_state = NACL_INTR_LOCK_FREE; | 122 mp->lock_state = NACL_INTR_LOCK_FREE; |
| 123 NaClXMutexUnlock(&mp->mu); | 123 NaClXMutexUnlock(&mp->mu); |
| 124 } | 124 } |
| OLD | NEW |