本文整理汇总了C++中ReleaseSemaphore函数的典型用法代码示例。如果您正苦于以下问题:C++ ReleaseSemaphore函数的具体用法?C++ ReleaseSemaphore怎么用?C++ ReleaseSemaphore使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReleaseSemaphore函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receive_interrupt
void __fastcall receive_interrupt (CONTEXT *context, int type, void *arg)
#endif
{
signal_queue_t* sq;
interrupt_queue_t* interrupt_info;
readytoreturn = FALSE;
if (DEBUG)
kprintf("SYS:Running user interrupt handler, context = 0x%x, arg = 0x%x.\n",
context, arg);
/* find the appropriate handler */
interrupt_info = interrupt_queue;
while (interrupt_info!=NULL && interrupt_info->type!=type)
interrupt_info = interrupt_info->next;
if (interrupt_info == NULL) {
/* we couldn't find the interrupt with type "type" so we crask the
sistem.
*/
kprintf("An interrupt of the unregistered type %d was received. Crashing.\n ",
type);
exit(-1);
} else {
/* now, call the appropriate interrupt handler */
if (DEBUG)
kprintf("SYS:interrupt of type %d.\n", type);
if (interrupt_info->handler != NULL)
interrupt_info->handler(arg);
}
WaitOnObject(mutex);
assert(signalq == NULL);
sq = (signal_queue_t *) malloc(sizeof(signal_queue_t));
sq->context = context;
sq->threadid = system_thread;
sq->next = signalq;
signalq = sq;
if (interrupt_level == ENABLED) {
if (DEBUG)
kprintf("SYS:disabling interrupts in handler.\n");
interrupt_level = DISABLED;
}
ReleaseMutex(mutex);
/*
* This is correct but not elegant (it's a kluge forced on us by Windows).
* We need an atomic way to wake up the
* assist thread and go to sleep ourselves. One could use SignalAndWait
* here, but SignalAndWait is not supported on CE
*/
ReleaseSemaphore(cleanup, 1, NULL); /* tell the return thread to run */
readytoreturn = TRUE;
/* if (DEBUG) kprintf("SYS:Looping forever.\n"); */
loopforever();
}
示例2: omni_thread_fatal
void
omni_semaphore::post(void)
{
if (!ReleaseSemaphore(nt_sem, 1, NULL))
throw omni_thread_fatal(GetLastError());
}
示例3: Stop
void CKDMTCriticalSection::Stop()
{
if (!ReleaseSemaphore(m_hSemaphore, 1, NULL))
TRACE(_T("CKDMTCriticalSection::Stop release semaphore failed\n"));
}
示例4: Semaphore_Release
static WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
{ return BOOLToWRes(ReleaseSemaphore(*p, releaseCount, previousCount)); }
示例5: mzrt_sema_post
int mzrt_sema_post(mzrt_sema *s)
{
ReleaseSemaphore(s->ws, 1, NULL);
return 0;
}
示例6: VERIFY
void Semaphore::post()
{
VERIFY(ReleaseSemaphore((HANDLE)handle, 1, 0));
}
示例7: get_site_entry
int get_site_entry(struct opusftp_globals *og,struct site_entry *e,IPCData *ipc)
{
struct List *list;
struct Node *node,*next;
int type=MATCH_NONE;
int result=0;
struct site_entry *site;
if (!e)
return(FALSE);
ObtainSemaphoreShared(&og->og_SiteList_semaphore);
if (!og->og_SiteList)
read_build_addressbook(og,ipc);
if (!og->og_SiteList)
goto done;
if (*e->se_name) type=MATCH_NAME;
else if (*e->se_host) type=MATCH_HOST;
else goto done;
list=&og->og_SiteList->list;
if (list && !IsListEmpty(list))
{
if ((node=list->lh_Head))
{
int count=0;
while ((next=node->ln_Succ))
{
int found;
count++;
site=(struct site_entry *)((Att_Node *)node)->data;
if (type==MATCH_NAME)
found=stricmp(e->se_name,site->se_name);
else
found=stricmp(e->se_host,site->se_host);
if (found==0)
{
// copy site entry
copy_site_entry(og,e,site);
// keep match position as return value
result=count;
break;
}
node=next;
}
}
}
done:
ReleaseSemaphore(&og->og_SiteList_semaphore);
return(result);
}
示例8: wince_init
// Internal API functions
static int wince_init(struct libusb_context *ctx)
{
int r = LIBUSB_ERROR_OTHER;
HANDLE semaphore;
LARGE_INTEGER li_frequency;
TCHAR sem_name[11+1+8]; // strlen(libusb_init)+'\0'+(32-bit hex PID)
_stprintf(sem_name, _T("libusb_init%08X"), (unsigned int)GetCurrentProcessId()&0xFFFFFFFF);
semaphore = CreateSemaphore(NULL, 1, 1, sem_name);
if (semaphore == NULL) {
usbi_err(ctx, "could not create semaphore: %s", windows_error_str(0));
return LIBUSB_ERROR_NO_MEM;
}
// A successful wait brings our semaphore count to 0 (unsignaled)
// => any concurent wait stalls until the semaphore's release
if (WaitForSingleObject(semaphore, INFINITE) != WAIT_OBJECT_0) {
usbi_err(ctx, "failure to access semaphore: %s", windows_error_str(0));
CloseHandle(semaphore);
return LIBUSB_ERROR_NO_MEM;
}
// NB: concurrent usage supposes that init calls are equally balanced with
// exit calls. If init is called more than exit, we will not exit properly
if ( ++concurrent_usage == 0 ) { // First init?
// Initialize pollable file descriptors
init_polling();
// Load DLL imports
if (init_dllimports() != LIBUSB_SUCCESS) {
usbi_err(ctx, "could not resolve DLL functions");
r = LIBUSB_ERROR_NOT_SUPPORTED;
goto init_exit;
}
// try to open a handle to the driver
driver_handle = UkwOpenDriver();
if (driver_handle == INVALID_HANDLE_VALUE) {
usbi_err(ctx, "could not connect to driver");
r = LIBUSB_ERROR_NOT_SUPPORTED;
goto init_exit;
}
// find out if we have access to a monotonic (hires) timer
if (QueryPerformanceFrequency(&li_frequency)) {
hires_frequency = li_frequency.QuadPart;
// The hires frequency can go as high as 4 GHz, so we'll use a conversion
// to picoseconds to compute the tv_nsecs part in clock_gettime
hires_ticks_to_ps = UINT64_C(1000000000000) / hires_frequency;
usbi_dbg("hires timer available (Frequency: %"PRIu64" Hz)", hires_frequency);
} else {
usbi_dbg("no hires timer available on this platform");
hires_frequency = 0;
hires_ticks_to_ps = UINT64_C(0);
}
}
// At this stage, either we went through full init successfully, or didn't need to
r = LIBUSB_SUCCESS;
init_exit: // Holds semaphore here.
if (!concurrent_usage && r != LIBUSB_SUCCESS) { // First init failed?
if (driver_handle != INVALID_HANDLE_VALUE) {
UkwCloseDriver(driver_handle);
driver_handle = INVALID_HANDLE_VALUE;
}
}
if (r != LIBUSB_SUCCESS)
--concurrent_usage; // Not expected to call libusb_exit if we failed.
ReleaseSemaphore(semaphore, 1, NULL); // increase count back to 1
CloseHandle(semaphore);
return r;
}
示例9: global_func_log
shared_memory::status shared_memory::lock(lock_descriptor& lck, unsigned msec)
{
//assert(lck.mode == lck_shared || lck.mode == lck_exclusive);
if(!(lck.mode == lck_shared || lck.mode == lck_exclusive))
global_func_log(__LINE__,__FILE__, NULL);
unsigned self = GetCurrentThreadId();
status result;
if (self == owner)
{
//assert(n_nested_exclusive_locks != 0 && pMonitor->n_writers == 1);
if(!(n_nested_exclusive_locks != 0 && pMonitor->n_writers == 1))
global_func_log(__LINE__,__FILE__, NULL);
if (lck.mode == lck_exclusive) {
n_nested_exclusive_locks += 1;
} else {
pMonitor->n_readers += 1;
lck.owner = self;
lck.next = shared_lock_chain;
shared_lock_chain = &lck;
}
return ok;
}
if (!enter_critical_section(result)) {
return result;
}
if (lck.mode == lck_shared) {
while (pMonitor->n_writers != 0) {
// storage is exclusivly locked by another process
if (msec != 0) {
if (pMonitor->n_waiters++ == 0) {
ResetEvent(hEvent);
}
}
if (!leave_critical_section(result)) {
return result;
}
if (msec == 0) {
return timeout_expired;
}
int rc = WaitForSingleObject(hEvent, msec);
if (rc == WAIT_TIMEOUT) {
msec = 0;
} else if (rc != WAIT_OBJECT_0) {
return status(GetLastError());
}
ReleaseSemaphore(hSemaphore, 1, NULL);
if (!enter_critical_section(result)) {
return result;
}
}
pMonitor->n_readers += 1;
lck.owner = self;
lck.next = shared_lock_chain;
shared_lock_chain = &lck;
} else { // exclusive lock
while (pMonitor->n_writers != 0
|| (pMonitor->n_readers != 0
&& (pMonitor->n_readers != 1
|| shared_lock_chain == NULL
|| shared_lock_chain->owner != self)))
{
// storage is locked by another process
if (msec != 0) {
if (pMonitor->n_waiters++ == 0) {
ResetEvent(hEvent);
}
}
if (!leave_critical_section(result)) {
return result;
}
if (msec == 0) {
return timeout_expired;
}
int rc = WaitForSingleObject(hEvent, msec);
if (rc == WAIT_TIMEOUT) {
msec = 0;
} else if (rc != WAIT_OBJECT_0) {
return status(GetLastError());
}
ReleaseSemaphore(hSemaphore, 1, NULL);
if (!enter_critical_section(result)) {
return result;
}
}
pMonitor->n_writers = 1;
n_nested_exclusive_locks = 1;
owner = self;
}
return leave_critical_section(result) ? ok : result;
}
示例10: semctl
//.........这里部分代码省略.........
iret=ipct->semb[semid][semnum].semval;
FreeIPCT(hIpct, ipct);
return iret;
case SETVAL:
if (semarg.val < 0)
{
errno = EINVAL;
FreeIPCT(hIpct, ipct);
return -1;
}
diffsemval=semarg.val-ipct->semb[semid][semnum].semval;
#ifndef TERMINAL_SERVICE
MakeSemstr(semstr, semnum, semid, ipct->semt[semid].key);
#else
if( osvi.dwMajorVersion >= 5 ) /* Windows 2000 */
MakeGlobalSemstr(semstr, semnum, semid, ipct->semt[semid].key);
else
MakeSemstr(semstr, semnum, semid, ipct->semt[semid].key);
#endif /* TERMINAL_SERVICE */
hsem=OpenSemaphore(SEMAPHORE_ALL_ACCESS, TRUE, semstr);
if (hsem==NULL)
{
errno=GetLastError();
FreeIPCT(hIpct, ipct);
return -1;
}
for (i=0; i<abs(diffsemval); i++)
{
if (diffsemval>0)
{
ret=ReleaseSemaphore(hsem, diffsemval, NULL);
if (ret==FALSE)
{
errno=GetLastError();
CloseHandle(hsem);
FreeIPCT(hIpct, ipct);
return -1;
}
break; /*2000.4.19*/
}
else if (diffsemval<0)
{
/********************
do
{
dwret=MsgWaitForMultipleObjects(1, &hsem,
FALSE, INFINITE,
QS_SENDMESSAGE|QS_POSTMESSAGE|QS_TIMER);
********************/
dwret=WaitForSingleObject(hsem, INFINITE);
switch (dwret)
{
/********************
case WAIT_OBJECT_0 + 1 :
if (l_peekmessage()<0)
{
CloseHandle(hsem);
FreeIPCT(hIpct, ipct);
return -1;
}
break;
********************/
示例11: myhtml_hread_mutex_post
myhtml_status_t myhtml_hread_mutex_post(mythread_t *mythread, mythread_context_t *ctx)
{
ReleaseSemaphore(ctx->mutex, 1, NULL);
return MyHTML_STATUS_OK;
}
示例12: ReleaseSemaphore
// ===============
void Semaphore::Post()
// ===============
{
// Post message notifying a wait call
ReleaseSemaphore(m_semaphore, 1, (long*)0);
}
示例13: GM_UNIQUENAME
static int GM_UNIQUENAME(Open)(LIBBASETYPEPTR hdskBase, struct IOExtTD *iotd, IPTR unitnum, ULONG flags)
{
STRPTR unitname;
struct unit *unit;
UBYTE unitflags = 0;
if (unitnum < 1024)
{
ULONG len = strlen(hdskBase->DiskDevice) + 5;
unitname = AllocVec(len, MEMF_ANY);
if (!unitname)
return FALSE;
unitflags = UNIT_FREENAME;
NewRawDoFmt(hdskBase->DiskDevice, (VOID_FUNC)RAWFMTFUNC_STRING, unitname, unitnum + hdskBase->unitBase);
}
else
unitname = (STRPTR)unitnum;
D(bug("hostdisk: open unit %s\n", unitname));
ObtainSemaphore(&hdskBase->sigsem);
unit = (struct unit *)FindName(&hdskBase->units, unitname);
if (unit)
{
unit->usecount++;
ReleaseSemaphore(&hdskBase->sigsem);
iotd->iotd_Req.io_Unit = (struct Unit *)unit;
iotd->iotd_Req.io_Error = 0;
iotd->iotd_Req.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
DOPEN(bug("hostdisk: in libopen func. Yep. Unit is already open\n"));
return TRUE;
}
DOPEN(bug("hostdisk: in libopen func. No, it is not. So creating new unit ...\n"));
unit = (struct unit *)AllocMem(sizeof(struct unit), MEMF_PUBLIC | MEMF_CLEAR);
if (unit != NULL)
{
ULONG p = strlen(GM_UNIQUENAME(LibName));
char taskName[p + strlen(unitname) + 2];
struct Task *unitTask;
DOPEN(bug("hostdisk: in libopen func. Allocation of unit memory okay. Setting up unit and calling CreateNewProc ...\n"));
CopyMem(GM_UNIQUENAME(LibName), taskName, p);
taskName[p] = ' ';
strcpy(&taskName[p + 1], unitname);
unit->n.ln_Name = unitname;
unit->usecount = 1;
unit->hdskBase = hdskBase;
unit->flags = unitflags;
NEWLIST((struct List *)&unit->changeints);
iotd->iotd_Req.io_Unit = (struct Unit *)unit;
SetSignal(0, SIGF_SINGLE);
unitTask = NewCreateTask(TASKTAG_PC , unitentry,
TASKTAG_NAME, taskName,
TASKTAG_ARG1, iotd,
TAG_DONE);
DOPEN(bug("hostdisk: in libopen func. NewCreateTask() called. Task = 0x%p\n", unitTask));
if (unitTask)
{
DOPEN(bug("hostdisk: in libopen func. Waiting for signal from unit task...\n"));
Wait(SIGF_SINGLE);
DOPEN(bug("hostdisk: in libopen func. Unit error %u, flags 0x%02X\n", iotd->iotd_Req.io_Error, unit->flags));
if (!iotd->iotd_Req.io_Error)
{
AddTail((struct List *)&hdskBase->units, &unit->n);
ReleaseSemaphore(&hdskBase->sigsem);
return TRUE;
}
}
else
iotd->iotd_Req.io_Error = TDERR_NoMem;
freeUnit(unit);
}
else
iotd->iotd_Req.io_Error = TDERR_NoMem;
ReleaseSemaphore(&hdskBase->sigsem);
return FALSE;
}
示例14: ReleaseSemaphore
void Semaphore::post() {
ReleaseSemaphore(hSemaphore, 1, NULL);
}
示例15: wf_peer_main_loop
DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
{
wfInfo* wfi;
DWORD nCount;
DWORD status;
HANDLE handles[32];
rdpSettings* settings;
wfPeerContext* context;
freerdp_peer* client = (freerdp_peer*) lpParam;
if (!getenv("HOME"))
{
char home[MAX_PATH * 2] = "HOME=";
strcat(home, getenv("HOMEDRIVE"));
strcat(home, getenv("HOMEPATH"));
_putenv(home);
}
wf_peer_init(client);
settings = client->settings;
settings->RemoteFxCodec = TRUE;
settings->ColorDepth = 32;
settings->NSCodec = FALSE;
settings->JpegCodec = FALSE;
wf_peer_read_settings(client);
client->PostConnect = wf_peer_post_connect;
client->Activate = wf_peer_activate;
client->Logon = wf_peer_logon;
client->input->SynchronizeEvent = wf_peer_synchronize_event;
client->input->KeyboardEvent = wf_peer_keyboard_event;
client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event;
client->input->MouseEvent = wf_peer_mouse_event;
client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event;
client->Initialize(client);
context = (wfPeerContext*) client->context;
if (context->socketClose)
return 0;
wfi = context->info;
if (wfi->input_disabled)
{
DEBUG_WARN("client input is disabled\n");
client->input->KeyboardEvent = wf_peer_keyboard_event_dummy;
client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event_dummy;
client->input->MouseEvent = wf_peer_mouse_event_dummy;
client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event_dummy;
}
context->socketEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
context->socketSemaphore = CreateSemaphore(NULL, 0, 1, NULL);
context->socketThread = CreateThread(NULL, 0, wf_peer_socket_listener, client, 0, NULL);
DEBUG_WARN("We've got a client %s\n", client->local ? "(local)" : client->hostname);
nCount = 0;
handles[nCount++] = context->updateEvent;
handles[nCount++] = context->socketEvent;
while (1)
{
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
if ((status == WAIT_FAILED) || (status == WAIT_TIMEOUT))
{
DEBUG_WARN("WaitForMultipleObjects failed\n");
break;
}
if (WaitForSingleObject(context->updateEvent, 0) == 0)
{
if (client->activated)
wf_update_peer_send(wfi, context);
ResetEvent(context->updateEvent);
ReleaseSemaphore(wfi->updateSemaphore, 1, NULL);
}
if (WaitForSingleObject(context->socketEvent, 0) == 0)
{
if (client->CheckFileDescriptor(client) != TRUE)
{
//printf("Failed to check peer file descriptor\n");
context->socketClose = TRUE;
}
ResetEvent(context->socketEvent);
ReleaseSemaphore(context->socketSemaphore, 1, NULL);
if (context->socketClose)
break;
}
//force disconnect
//.........这里部分代码省略.........