| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "native_client/src/shared/platform/nacl_check.h" | 9 #include "native_client/src/shared/platform/nacl_check.h" |
| 10 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 10 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 11 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 11 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
| 12 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 12 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| 13 | 13 |
| 14 | 14 |
| 15 void NaClAppThreadSetSuspendState(struct NaClAppThread *natp, |
| 16 enum NaClSuspendState old_state, |
| 17 enum NaClSuspendState new_state) { |
| 18 NaClXMutexLock(&natp->mu); |
| 19 while ((natp->suspend_state & NACL_APP_THREAD_SUSPENDING) != 0) { |
| 20 /* |
| 21 * We are being suspended, but SuspendThread() has not taken effect yet. |
| 22 */ |
| 23 NaClXCondVarWait(&natp->cv, &natp->mu); |
| 24 } |
| 25 DCHECK(natp->suspend_state == old_state); |
| 26 natp->suspend_state = new_state; |
| 27 NaClXMutexUnlock(&natp->mu); |
| 28 } |
| 29 |
| 15 void NaClUntrustedThreadSuspend(struct NaClAppThread *natp) { | 30 void NaClUntrustedThreadSuspend(struct NaClAppThread *natp) { |
| 16 enum NaClSuspendState old_state; | 31 enum NaClSuspendState old_state; |
| 17 | 32 |
| 18 /* | 33 /* |
| 19 * Note that if we are being called from a NaCl syscall (which is | 34 * Note that if we are being called from a NaCl syscall (which is |
| 20 * likely), natp could be the thread we are running in. That is | 35 * likely), natp could be the thread we are running in. That is |
| 21 * fine, because this thread will be in the | 36 * fine, because this thread will be in the |
| 22 * NACL_APP_THREAD_TRUSTED state, and so we will not call | 37 * NACL_APP_THREAD_TRUSTED state, and so we will not call |
| 23 * SuspendThread() on it. | 38 * SuspendThread() on it. |
| 24 */ | 39 */ |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 size_t index; | 127 size_t index; |
| 113 for (index = 0; index < nap->threads.num_entries; index++) { | 128 for (index = 0; index < nap->threads.num_entries; index++) { |
| 114 struct NaClAppThread *natp = NaClGetThreadMu(nap, (int) index); | 129 struct NaClAppThread *natp = NaClGetThreadMu(nap, (int) index); |
| 115 if (natp != NULL) { | 130 if (natp != NULL) { |
| 116 NaClUntrustedThreadResume(natp); | 131 NaClUntrustedThreadResume(natp); |
| 117 } | 132 } |
| 118 } | 133 } |
| 119 | 134 |
| 120 NaClXMutexUnlock(&nap->threads_mu); | 135 NaClXMutexUnlock(&nap->threads_mu); |
| 121 } | 136 } |
| OLD | NEW |