本文整理汇总了C++中NaClXMutexLock函数的典型用法代码示例。如果您正苦于以下问题:C++ NaClXMutexLock函数的具体用法?C++ NaClXMutexLock怎么用?C++ NaClXMutexLock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NaClXMutexLock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NaClFileLockManagerLock
void NaClFileLockManagerLock(struct NaClFileLockManager *self,
int desc) {
struct NaClFileLockEntry key;
struct NaClFileLockEntry **existing;
struct NaClFileLockEntry *entry;
(*self->set_file_identity_data)(&key, desc);
NaClXMutexLock(&self->mu);
existing = NaClFileLockManagerFindEntryMu(self, &key);
if (NULL == existing) {
/* make new entry */
entry = NaClFileLockManagerEntryFactory(self, desc);
entry->next = self->head;
self->head = entry;
NaClXMutexUnlock(&self->mu);
} else {
entry = *existing;
NaClXMutexLock(&entry->mu);
entry->num_waiting++;
/* arithmetic overflow */
CHECK(0 != entry->num_waiting);
/* drop container lock after ensuring that the entry will not be deleted */
NaClXMutexUnlock(&self->mu);
while (entry->holding_lock) {
NaClXCondVarWait(&entry->cv, &entry->mu);
}
entry->holding_lock = 1;
entry->num_waiting--;
NaClXMutexUnlock(&entry->mu);
}
(*self->take_file_lock)(desc);
}
示例2: NaClFileLockManagerUnlock
void NaClFileLockManagerUnlock(struct NaClFileLockManager *self,
int desc) {
struct NaClFileLockEntry key;
struct NaClFileLockEntry **existing;
struct NaClFileLockEntry *entry;
(*self->set_file_identity_data)(&key, desc);
NaClXMutexLock(&self->mu);
existing = NaClFileLockManagerFindEntryMu(self, &key);
CHECK(NULL != existing);
entry = *existing;
NaClXMutexLock(&entry->mu);
entry->holding_lock = 0;
if (0 == entry->num_waiting) {
*existing = entry->next;
NaClXMutexUnlock(&entry->mu);
NaClXMutexUnlock(&self->mu);
NaClFileLockManagerFileEntryRecycler(&entry);
} else {
NaClXMutexUnlock(&self->mu);
/* tell waiting threads that they can now compete for the lock */
NaClXCondVarBroadcast(&entry->cv);
NaClXMutexUnlock(&entry->mu);
}
(*self->drop_file_lock)(desc);
}
示例3: NaClNameServiceDeleteName
int NaClNameServiceDeleteName(struct NaClNameService *nnsp,
char const *name) {
struct NaClNameServiceEntry **nnsepp;
struct NaClNameServiceEntry *to_free = NULL;
int status = NACL_NAME_SERVICE_NAME_NOT_FOUND;
NaClXMutexLock(&nnsp->mu);
nnsepp = NameServiceSearch(&nnsp->head, name);
if (NULL != *nnsepp) {
to_free = *nnsepp;
*nnsepp = to_free->next;
status = NACL_NAME_SERVICE_SUCCESS;
}
NaClXMutexUnlock(&nnsp->mu);
/* do the free operations w/o holding the lock */
if (NULL != to_free) {
NaClDescSafeUnref(to_free->entry);
if (NULL != to_free->factory) {
(void) (*to_free->factory)(to_free->state,
to_free->name,
0,
(struct NaClDesc **) NULL);
}
free((void *) to_free->name);
free(to_free);
}
return status;
}
示例4: NaClGetTimeOfDayIntern
int NaClGetTimeOfDayIntern(struct nacl_abi_timeval *tv,
struct NaClTimeState *ntsp) {
FILETIME ft_now;
DWORD ms_counter_now;
uint64_t t_ms;
DWORD ms_counter_at_ft_now;
uint32_t ms_counter_diff;
uint64_t unix_time_ms;
if (ntsp->can_use_qpc)
return NaClGetTimeOfDayInternQpc(tv, ntsp, 1);
GetSystemTimeAsFileTime(&ft_now);
ms_counter_now = timeGetTime();
t_ms = NaClFileTimeToMs(&ft_now);
NaClXMutexLock(&ntsp->mu);
if (!ntsp->allow_low_resolution) {
NaClLog(5, "ms_counter_now %"NACL_PRIu32"\n",
(uint32_t) ms_counter_now);
NaClLog(5, "t_ms %"NACL_PRId64"\n", t_ms);
NaClLog(5, "system_time_start_ms %"NACL_PRIu64"\n",
ntsp->system_time_start_ms);
ms_counter_at_ft_now = (DWORD)
(ntsp->ms_counter_start +
(uint32_t) (t_ms - ntsp->system_time_start_ms));
NaClLog(5, "ms_counter_at_ft_now %"NACL_PRIu32"\n",
(uint32_t) ms_counter_at_ft_now);
ms_counter_diff = ms_counter_now - (uint32_t) ms_counter_at_ft_now;
NaClLog(5, "ms_counter_diff %"NACL_PRIu32"\n", ms_counter_diff);
if (ms_counter_diff <= kMaxMillsecondDriftBeforeRecalibration) {
t_ms = t_ms + ms_counter_diff;
} else {
NaClCalibrateWindowsClockMu(ntsp);
t_ms = ntsp->system_time_start_ms;
}
NaClLog(5, "adjusted t_ms = %"NACL_PRIu64"\n", t_ms);
}
unix_time_ms = t_ms - ntsp->epoch_start_ms;
NaClXMutexUnlock(&ntsp->mu);
NaClLog(5, "unix_time_ms = %"NACL_PRId64"\n", unix_time_ms);
/*
* Unix time is measured relative to a different epoch, Jan 1, 1970.
* See the module initialization for epoch_start_ms.
*/
tv->nacl_abi_tv_sec = (nacl_abi_time_t) (unix_time_ms / 1000);
tv->nacl_abi_tv_usec = (nacl_abi_suseconds_t) ((unix_time_ms % 1000) * 1000);
return 0;
}
示例5: NaClWaitForMainThreadToExit
int NaClWaitForMainThreadToExit(struct NaClApp *nap) {
struct NaClClosure *work;
while (NULL != (work = NaClSyncQueueDequeue(&nap->work_queue))) {
NaClLog(3, "NaClWaitForMainThreadToExit: got work %08"NACL_PRIxPTR"\n",
(uintptr_t) work);
NaClLog(3, " invoking Run fn %08"NACL_PRIxPTR"\n",
(uintptr_t) work->vtbl->Run);
(*work->vtbl->Run)(work);
NaClLog(3, "... done\n");
}
NaClLog(3, " taking NaClApp lock\n");
NaClXMutexLock(&nap->mu);
NaClLog(3, " waiting for exit status\n");
while (nap->running) {
NaClCondVarWait(&nap->cv, &nap->mu);
NaClLog(3, " wakeup, nap->running %d, nap->exit_status %d\n",
nap->running, nap->exit_status);
}
NaClXMutexUnlock(&nap->mu);
/*
* Some thread invoked the exit (exit_group) syscall.
*/
NaClDebugStop(nap->exit_status);
return (nap->exit_status);
}
示例6: NaClManifestProxyConnectionDtor
static void NaClManifestProxyConnectionDtor(struct NaClRefCount *vself) {
struct NaClManifestProxyConnection *self =
(struct NaClManifestProxyConnection *) vself;
NaClLog(4,
"Entered NaClManifestProxyConnectionDtor: self 0x%"NACL_PRIxPTR"\n",
(uintptr_t) self);
NaClXMutexLock(&self->mu);
while (!self->channel_initialized) {
NaClLog(4,
"NaClManifestProxyConnectionDtor:"
" waiting for connection initialization\n");
NaClXCondVarWait(&self->cv, &self->mu);
}
NaClXMutexUnlock(&self->mu);
NaClLog(4, "NaClManifestProxyConnectionDtor: dtoring\n");
NaClCondVarDtor(&self->cv);
NaClMutexDtor(&self->mu);
NaClSrpcDtor(&self->client_channel);
NACL_VTBL(NaClSimpleServiceConnection, self) =
&kNaClSimpleServiceConnectionVtbl;
(*NACL_VTBL(NaClRefCount, self)->Dtor)(vself);
}
示例7: NaClManifestProxyConnectionRevHandleConnect
void NaClManifestProxyConnectionRevHandleConnect(
struct NaClManifestProxyConnection *self,
struct NaClDesc *rev) {
NaClLog(4, "Entered NaClManifestProxyConnectionRevHandleConnect\n");
NaClXMutexLock(&self->mu);
if (self->channel_initialized) {
NaClLog(LOG_FATAL,
"NaClManifestProxyConnectionRevHandleConnect: double connect?\n");
}
/*
* If NaClSrpcClientCtor proves to take too long, we should spin off
* another thread to do the initialization so that the reverse
* client can accept additional reverse channels.
*/
NaClLog(4,
"NaClManifestProxyConnectionRevHandleConnect: Creating SrpcClient\n");
if (NaClSrpcClientCtor(&self->client_channel, rev)) {
NaClLog(4,
("NaClManifestProxyConnectionRevHandleConnect: SrpcClientCtor"
" succeded, announcing.\n"));
self->channel_initialized = 1;
NaClXCondVarBroadcast(&self->cv);
/* ownership of rev taken */
} else {
NaClLog(4,
("NaClManifestProxyConnectionRevHandleConnect: NaClSrpcClientCtor"
" failed\n"));
}
NaClXMutexUnlock(&self->mu);
NaClLog(4, "Leaving NaClManifestProxyConnectionRevHandleConnect\n");
}
示例8: NaClReverseHostInterfaceReportExitStatus
int NaClReverseHostInterfaceReportExitStatus(
struct NaClRuntimeHostInterface *vself,
int exit_status) {
struct NaClReverseHostInterface *self =
(struct NaClReverseHostInterface *) vself;
NaClSrpcError rpc_result;
int status = 0;
NaClLog(3,
"NaClReverseHostInterfaceReportExitStatus:"
" self 0x%08"NACL_PRIxPTR", exit_status 0x%x)\n",
(uintptr_t) self, exit_status);
NaClXMutexLock(&self->server->mu);
if (NACL_REVERSE_CHANNEL_INITIALIZED ==
self->server->reverse_channel_initialization_state) {
rpc_result = NaClSrpcInvokeBySignature(&self->server->reverse_channel,
NACL_REVERSE_CONTROL_REPORT_STATUS,
exit_status);
if (NACL_SRPC_RESULT_OK != rpc_result) {
NaClLog(LOG_FATAL, "NaClReverseHostInterfaceReportExitStatus:"
" RPC failed, result %d\n",
rpc_result);
}
} else {
NaClLog(4, "NaClReverseHostInterfaceReportExitStatus: no reverse channel"
", no plugin to talk to.\n");
status = -NACL_ABI_ENODEV;
}
NaClXMutexUnlock(&self->server->mu);
return status;
}
示例9: NaClClockGetTime
int NaClClockGetTime(nacl_clockid_t clk_id,
struct nacl_abi_timespec *tp) {
int rv = -NACL_ABI_EINVAL;
struct nacl_abi_timeval tv;
uint64_t t_mono_prev_us;
uint64_t t_mono_cur_us;
if (!g_NaClClock_is_initialized) {
NaClLog(LOG_FATAL,
"NaClClockGetTime invoked without successful NaClClockInit\n");
}
switch (clk_id) {
case NACL_CLOCK_REALTIME:
rv = NaClGetTimeOfDay(&tv);
if (0 == rv) {
tp->tv_sec = tv.nacl_abi_tv_sec;
tp->tv_nsec = tv.nacl_abi_tv_usec * 1000;
}
break;
case NACL_CLOCK_MONOTONIC:
/*
* Get real time, compare with last monotonic time. If later
* than last monotonic time, set last monotonic time to real
* time timestamp; otherwise we leave last monotonoic time
* alone. In either case, return last monotonic time.
*
* The interpretation used here is that "monotonic" means
* monotonic non-decreasing, as opposed to monotonic increasing.
* We don't assume that GetTimeOfDay only yields high-order bits
* so we can replace low-order bits of the time value with a
* counter to fake monotonicity. We are dangerously close to
* the resolution limit of 1ns imposed by the timespec structure
* already -- it's only a few Moore's Law generations away where
* we may have to return the same time stamp for repeated calls
* to clock_gettime (if CPU frequency clock is continued to be
* used to drive performance counters; RTDSC is moving to a
* fixed rate [constant_tsc], fortunately).
*/
rv = NaClGetTimeOfDay(&tv);
if (0 == rv) {
NaClXMutexLock(&g_nacl_clock_mu);
t_mono_prev_us = g_nacl_clock_tv.nacl_abi_tv_sec * 1000000
+ g_nacl_clock_tv.nacl_abi_tv_usec;
t_mono_cur_us = tv.nacl_abi_tv_sec * 1000000
+ tv.nacl_abi_tv_usec;
if (t_mono_cur_us >= t_mono_cur_us) {
g_nacl_clock_tv = tv;
}
tp->tv_sec = g_nacl_clock_tv.nacl_abi_tv_sec + MAGIC_OFFSET;
tp->tv_nsec = g_nacl_clock_tv.nacl_abi_tv_usec * 1000;
NaClXMutexUnlock(&g_nacl_clock_mu);
rv = 0;
}
break;
case NACL_CLOCK_PROCESS_CPUTIME_ID:
case NACL_CLOCK_THREAD_CPUTIME_ID:
break;
}
return rv;
}
示例10: NaClReverseHostInterfaceStartupInitializationComplete
int NaClReverseHostInterfaceStartupInitializationComplete(
struct NaClRuntimeHostInterface *vself) {
struct NaClReverseHostInterface *self =
(struct NaClReverseHostInterface *) vself;
NaClSrpcError rpc_result;
int status = 0;
NaClLog(3,
("NaClReverseHostInterfaceStartupInitializationComplete(0x%08"
NACL_PRIxPTR")\n"),
(uintptr_t) self);
NaClXMutexLock(&self->server->mu);
if (NACL_REVERSE_CHANNEL_INITIALIZED ==
self->server->reverse_channel_initialization_state) {
rpc_result = NaClSrpcInvokeBySignature(&self->server->reverse_channel,
NACL_REVERSE_CONTROL_INIT_DONE);
if (NACL_SRPC_RESULT_OK != rpc_result) {
NaClLog(LOG_FATAL,
"NaClReverseHostInterfaceStartupInitializationComplete:"
" RPC failed, result %d\n",
rpc_result);
}
} else {
NaClLog(4, "NaClReverseHostInterfaceStartupInitializationComplete:"
" no reverse channel, no plugin to talk to.\n");
status = -NACL_ABI_ENODEV;
}
NaClXMutexUnlock(&self->server->mu);
return status;
}
示例11: NaClXMutexLock
struct NaClDescInvalid const *NaClDescInvalidMake(void) {
NaClXMutexLock(mutex);
if (NULL == singleton) {
do {
/* Allocate an instance. */
singleton = (struct NaClDescInvalid *) malloc(sizeof(*singleton));
if (NULL == singleton) {
break;
}
/* Do the base class construction. */
if (!NaClDescCtor(&(singleton->base))) {
free(singleton);
singleton = NULL;
break;
}
/* Construct the derived class (simply set the vtbl). */
singleton->base.base.vtbl =
(struct NaClRefCountVtbl const *) &kNaClDescInvalidVtbl;
} while (0);
}
NaClXMutexUnlock(mutex);
/* If we reached this point and still have NULL == singleton there was an
* error in allocation or construction. Return NULL to indicate error.
*/
if (NULL == singleton) {
return NULL;
}
return (struct NaClDescInvalid *) NaClDescRef(&(singleton->base));
}
示例12: TestAbsWait
void TestAbsWait(void *arg) {
uint64_t sleep_usec;
struct nacl_abi_timeval now;
struct nacl_abi_timespec t;
sleep_usec = ((struct TestFunctorArg *) arg)->sleep_usec;
(void) NaClGetTimeOfDay(&now);
t.tv_sec = (nacl_abi_time_t) (now.nacl_abi_tv_sec + sleep_usec / kMicroXinX);
t.tv_nsec = (long int) (kNanoXinMicroX * (now.nacl_abi_tv_usec
+ (sleep_usec % kMicroXinX)));
while (t.tv_nsec > kNanoXinX) {
t.tv_nsec -= kNanoXinX;
++t.tv_sec;
}
if (gVerbosity > 1) {
printf("TestAbsWait: locking\n");
}
NaClXMutexLock(&gMu);
if (gVerbosity > 1) {
printf("TestAbsWait: waiting\n");
}
NaClXCondVarTimedWaitAbsolute(&gCv, &gMu, &t);
if (gVerbosity > 1) {
printf("TestAbsWait: unlocking\n");
}
NaClXMutexUnlock(&gMu);
}
示例13: NaClGlobalSecureRngUint32
uint32_t NaClGlobalSecureRngUint32(void) {
uint32_t rv;
NaClXMutexLock(&nacl_global_rng_mu);
rv = (*nacl_grngp->base.vtbl->GenUint32)(&nacl_grngp->base);
NaClXMutexUnlock(&nacl_global_rng_mu);
return rv;
}
示例14: NaClUntrustedThreadSuspend
void NaClUntrustedThreadSuspend(struct NaClAppThread *natp,
int save_registers) {
/*
* We claim suspend_mu here to block trusted/untrusted context
* switches by blocking NaClAppThreadSetSuspendState(). This blocks
* any untrusted->trusted context switch that might happen before
* SuspendThread() takes effect. It blocks any trusted->untrusted
* context switch that might happen if the syscall running in the
* target thread returns.
*/
NaClXMutexLock(&natp->suspend_mu);
if (natp->suspend_state == NACL_APP_THREAD_UNTRUSTED) {
CONTEXT temp_context;
CONTEXT *context;
HANDLE thread_handle = GetHostThreadHandle(natp);
if (SuspendThread(thread_handle) == (DWORD) -1) {
NaClLog(LOG_FATAL, "NaClUntrustedThreadSuspend: "
"SuspendThread() call failed\n");
}
if (save_registers) {
if (natp->suspended_registers == NULL) {
natp->suspended_registers = malloc(sizeof(*natp->suspended_registers));
if (natp->suspended_registers == NULL) {
NaClLog(LOG_FATAL, "NaClUntrustedThreadSuspend: malloc() failed\n");
}
}
context = &natp->suspended_registers->context;
context->ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
} else {
/*
* SuspendThread() can return before the thread has been
* suspended, because internally it only sends a message asking
* for the thread to be suspended.
* See http://code.google.com/p/nativeclient/issues/detail?id=2557
*
* As a workaround for that, we call GetThreadContext() even
* when save_registers=0. GetThreadContext() should only be
* able to return a snapshot of the register state once the
* thread has actually suspended.
*
* If save_registers=0, the set of registers we request via
* ContextFlags is unimportant as long as it is non-empty.
*/
context = &temp_context;
context->ContextFlags = CONTEXT_CONTROL;
}
if (!GetThreadContext(thread_handle, context)) {
NaClLog(LOG_FATAL, "NaClUntrustedThreadSuspend: "
"GetThreadContext() failed\n");
}
}
/*
* We leave suspend_mu held so that NaClAppThreadSetSuspendState()
* will block.
*/
}
示例15: PrintVmmap
static void PrintVmmap(struct NaClApp *nap) {
printf("In PrintVmmap\n");
fflush(stdout);
NaClXMutexLock(&nap->mu);
NaClVmmapVisit(&nap->mem_map, VmentryPrinter, (void *) 0);
NaClXMutexUnlock(&nap->mu);
}