当前位置: 首页>>代码示例>>C++>>正文


C++ Benaphore类代码示例

本文整理汇总了C++中Benaphore的典型用法代码示例。如果您正苦于以下问题:C++ Benaphore类的具体用法?C++ Benaphore怎么用?C++ Benaphore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Benaphore类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RemoveListener

void RemoveListener( LPARDUINOLISTENER listener )
	{
	LOG(MAINFUNC,"Arduino::RemoveListener");
	listener_lock.Lock();
	int i=0;
	while ( (i<listeners_count) && (listeners[i].callback!=listener) )
		i++;
	if (listeners[i].callback==listener)
		{
		// remove entry so that entries after this are simply moved 1 entry lower
		while (i<listeners_count-1)
			{
			listeners[i].callback = listeners[i+1].callback;
			listeners[i].data = listeners[i+1].data;
			i++;
			}
		listeners_count--;
		listener_lock.Unlock();
		LOG(MAINFUNC,"Arduino::RemoveListener - removed successfully");
		}
	else
		{
		listener_lock.Unlock();
		LOG(ERR,"Arduino::RemoveListener - no such listener found!");
		}
	}
开发者ID:miaozhendaoren,项目名称:SardineCAN-Win32,代码行数:26,代码来源:Arduino.cpp

示例2: IsConnected

bool IsConnected()
{
	init_lock.Lock();
	LOG(HELPERFUNC,"Arduino::IsConnected %d",isConnected);
	bool isconnected = isConnected;
	init_lock.Unlock();
	return isconnected;
}
开发者ID:miaozhendaoren,项目名称:SardineCAN-Win32,代码行数:8,代码来源:Arduino.cpp

示例3: CloseDevice

int CloseDevice()
{
	LOG(MAINFUNC,"Arduino::CloseDevice");
	init_lock.Lock();
	CloseHandle(hCommPort);
	hCommPort=INVALID_HANDLE_VALUE;
	isConnected=0;
	CloseHandle(ghWriteCompleteEvent);
	init_lock.Unlock();
	return 0;
}
开发者ID:miaozhendaoren,项目名称:SardineCAN-Win32,代码行数:11,代码来源:Arduino.cpp

示例4: Send

int Send(const char * cmd)
	{
	LOG(ARDUINO_MSG_VERBOSE,"Arduino::SendMsg - msg [%s]",cmd);
	write_lock.Lock();

	DWORD dwwritten = 0; 
	int len = strlen(cmd);

	char buf[256];
	if(len>256)
	{
		write_lock.Unlock();
		LOG(ERR,"Arduino::Send: Msg too long!");
		return -1;
	}

#ifndef USBCAN_PROTOCOL
	// surround message with {}
	sprintf_s(buf,256,"{%s}\r",cmd);
	len += 3;	// {}\r
#else
	sprintf_s(buf,256,"%s\r",cmd);
	len += 1;	// \r
#endif

	if  ( (dwwritten=blockingWrite(buf, len )) == -1)
		{
		LOG(ERR,"Arduino::SendMsg - Blocking write failed ! \n");
		write_lock.Unlock();
		return -1;
		}

	if (dwwritten != len)
		{
		write_lock.Unlock();
		LOG(ERR,"Arduino::SendMsg - Write didn't finish (%d out of %d bytes sent)\n", dwwritten,len);
		DWORD   dwErrors;
		COMSTAT comStat;
		ClearCommError(hCommPort, &dwErrors, &comStat);
		LOG(ERR,"Arduino::SendMsg - ClearCommError: Error flags: 0x%x, bytes in output queue: %d\n", dwErrors, comStat.cbOutQue);		
		return -1;
		}
	write_lock.Unlock();

#ifndef USBCAN_PROTOCOL
	LOG(ARDUINO_MSG_VERBOSE,"Arduino::SendMsg - completed succefully: %d written (%d bytes original)",dwwritten,dwwritten-3);
	return dwwritten-3;
#else
	LOG(ARDUINO_MSG_VERBOSE,"Arduino::SendMsg - completed succefully: %d written (%d bytes original)",dwwritten,dwwritten-1);
	return dwwritten-1;
#endif
}
开发者ID:miaozhendaoren,项目名称:SardineCAN-Win32,代码行数:52,代码来源:Arduino.cpp

示例5: RegisterListener

int RegisterListener( LPARDUINOLISTENER listener, void *data )
	{
	LOG(MAINFUNC,"Arduino::RegisterListener");
	listener_lock.Lock();
	if (listeners_count<MAX_LISTENERS)
		{
		listeners[listeners_count].callback = listener;
		listeners[listeners_count].data = data;
		listeners_count++;
		listener_lock.Unlock();
		LOG(MAINFUNC,"Arduino::RegisterListener - added succesfully");
		}
	else
		{
		listener_lock.Unlock();
		LOG(ERR,"Arduino::RegisterListener - too many listeners!");
		return -1;
		}
	return 0;
	}
开发者ID:miaozhendaoren,项目名称:SardineCAN-Win32,代码行数:20,代码来源:Arduino.cpp

示例6: device_free

status_t device_free(void *dev)
{
    LogFlowFunc(("device_free\n"));

    DeviceInfo& di = *(DeviceInfo *)dev;
    gLock.Acquire();

    if (di.openCount <= 1)
    {
        // TODO deinit device!
        delete_area(di.sharedArea);
        di.sharedArea = -1;
        di.sharedInfo = NULL;
    }

    if (di.openCount > 0)
        di.openCount--;

    gLock.Release();

    return B_OK;
}
开发者ID:MadHacker217,项目名称:VirtualBox-OSE,代码行数:22,代码来源:driver.cpp

示例7: uninit_driver

void uninit_driver()
{
    LogFlowFunc(("uninit_driver\n"));
    gLock.Delete();
    put_module(VBOXGUEST_MODULE_NAME);
}
开发者ID:MadHacker217,项目名称:VirtualBox-OSE,代码行数:6,代码来源:driver.cpp

示例8: init_driver

status_t init_driver()
{
    LogFlowFunc(("init_driver\n"));

    gLock.Init("VBoxVideo driver lock");

    uint32 pciIndex = 0;

    while (gPCI->get_nth_pci_info(pciIndex, &gDeviceInfo.pciInfo) == B_OK)
    {
        if (gDeviceInfo.pciInfo.vendor_id == VENDOR_ID && gDeviceInfo.pciInfo.device_id == DEVICE_ID)
        {
            sprintf(gDeviceInfo.name, "graphics/" DEVICE_FORMAT,
                    gDeviceInfo.pciInfo.vendor_id, gDeviceInfo.pciInfo.device_id,
                    gDeviceInfo.pciInfo.bus, gDeviceInfo.pciInfo.device, gDeviceInfo.pciInfo.function);
            TRACE("found device %s\n", gDeviceInfo.name);

            gCanHasDevice = true;
            gDeviceInfo.openCount = 0;

            size_t sharedSize = (sizeof(SharedInfo) + 7) & ~7;
            gDeviceInfo.sharedArea = create_area("vboxvideo shared info",
                                                 (void **)&gDeviceInfo.sharedInfo, B_ANY_KERNEL_ADDRESS,
                                                 ROUND_TO_PAGE_SIZE(sharedSize), B_FULL_LOCK,
                                                 B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_USER_CLONEABLE_AREA);

            uint16_t width, height, vwidth, bpp, flags;
            VBoxVideoGetModeRegisters(&width, &height, &vwidth, &bpp, &flags);

            gDeviceInfo.sharedInfo->currentMode.space = get_color_space_for_depth(bpp);
            gDeviceInfo.sharedInfo->currentMode.virtual_width = width;
            gDeviceInfo.sharedInfo->currentMode.virtual_height = height;
            gDeviceInfo.sharedInfo->currentMode.h_display_start = 0;
            gDeviceInfo.sharedInfo->currentMode.v_display_start = 0;
            gDeviceInfo.sharedInfo->currentMode.flags = 0;
            gDeviceInfo.sharedInfo->currentMode.timing.h_display = width;
            gDeviceInfo.sharedInfo->currentMode.timing.v_display = height;
            /* Not used, but this makes a reasonable-sounding refresh rate show in screen prefs: */
            gDeviceInfo.sharedInfo->currentMode.timing.h_total = 1000;
            gDeviceInfo.sharedInfo->currentMode.timing.v_total = 1;
            gDeviceInfo.sharedInfo->currentMode.timing.pixel_clock = 850;

            /* Map the PCI memory space */
            uint32 command_reg = gPCI->read_pci_config(gDeviceInfo.pciInfo.bus,
                                                       gDeviceInfo.pciInfo.device, gDeviceInfo.pciInfo.function,  PCI_command, 2);
            command_reg |= PCI_command_io | PCI_command_memory | PCI_command_master;
            gPCI->write_pci_config(gDeviceInfo.pciInfo.bus, gDeviceInfo.pciInfo.device,
                                   gDeviceInfo.pciInfo.function, PCI_command, 2, command_reg);

            gDeviceInfo.sharedInfo->framebufferArea = map_physical_memory("vboxvideo framebuffer",
                                                      (phys_addr_t)gDeviceInfo.pciInfo.u.h0.base_registers[0],
                                                      gDeviceInfo.pciInfo.u.h0.base_register_sizes[0], B_ANY_KERNEL_BLOCK_ADDRESS,
                                                      B_READ_AREA | B_WRITE_AREA, &(gDeviceInfo.sharedInfo->framebuffer));
            vm_set_area_memory_type(gDeviceInfo.sharedInfo->framebufferArea,
                                    (phys_addr_t)gDeviceInfo.pciInfo.u.h0.base_registers[0], B_MTR_WC);
            break;
        }

        pciIndex++;
    }

    return B_OK;
}
开发者ID:MadHacker217,项目名称:VirtualBox-OSE,代码行数:63,代码来源:driver.cpp

示例9: OpenDevice

int OpenDevice( int com_port, int baud_rate, int disable_DTR )
{
	LOG(MAINFUNC,"Arduino::OpenDevice - com port %d, baud_rate %d, disable DTR %d",com_port,baud_rate,disable_DTR);
	init_lock.Lock();
	if (isConnected)
		{
		init_lock.Unlock();
		LOG(ERR,"Arduino::OpenDevice - already connected!");
		return ARDUINO_ALREADY_CONNECTED;
		}

	if (com_port==-1)
		{
		com_port = ARDUINO_DEFAULT_COM_PORT;
		LOG(MAINFUNC,"Arduino::OpenDevice - defaulting to comport %d",com_port);
		}
	if (baud_rate==-1)
		{
		baud_rate = ARDUINO_DEFAULT_BAUD_RATE;
		LOG(MAINFUNC,"Arduino::OpenDevice - defaulting to baud rate %d",baud_rate);
		}
	if (disable_DTR==-1)
		{
		disable_DTR = ARDUINO_DEFAULT_DTR_DISABLED;
		LOG(MAINFUNC,"Arduino::OpenDevice - defaulting to dtr disabled=%d",disable_DTR);
		}
	

	TCHAR COMx[32];
	int n = _stprintf_s(COMx, 32, _T("\\\\.\\COM%d"),com_port);
	long int err;
	BOOL fSuccess;	
	DCB dcb;

	LOG(MAINFUNC,"Arduino::OpenDevice - creating file handle for com port");
	hCommPort = CreateFile(
	COMx,
    GENERIC_READ | GENERIC_WRITE,
    FILE_SHARE_WRITE, // 0,
    NULL,
    OPEN_EXISTING,
    FILE_FLAG_OVERLAPPED,
    NULL
    );

	if (hCommPort == INVALID_HANDLE_VALUE) 
	{
		err=GetLastError();
		if (err==ERROR_ALREADY_EXISTS)
			{
			LOG(ERR,"Arduino::OpenDevice - Already opened by other process!");
			init_lock.Unlock();
			return ARDUINO_IN_USE;
			} 
		else
			{
			LOG(ERR,"Arduino::OpenDevice - CreateFileA failed %d!",err);
			init_lock.Unlock();
			return ARDUINO_OPEN_FAILED;
			}
	}

	LOG(MAINFUNC,"Arduino::OpenDevice - getting comm state");
	fSuccess = GetCommState(hCommPort, &dcb);

	if (!fSuccess) 
	{
		LOG(ERR,"Arduino::OpenDevice - GetCommStateFailed %d", err=GetLastError());
		PrintError(err);
		CloseHandle(hCommPort);
		hCommPort=INVALID_HANDLE_VALUE;
		init_lock.Unlock();
		return ARDUINO_GET_COMMSTATE_FAILED;
	}

	LOG(MAINFUNC,"Arduino::OpenDevice - setting comm state");
	dcb.BaudRate = baud_rate;
	dcb.ByteSize = 8;
	dcb.Parity = NOPARITY;
	dcb.StopBits = ONESTOPBIT;
	dcb.fDtrControl = (disable_DTR==1 ? DTR_CONTROL_DISABLE : DTR_CONTROL_ENABLE);	// to prevent Arduino from reseting when first sending something
		
	fSuccess = SetCommState(hCommPort, &dcb);
	if (!fSuccess) 
	{
		err=GetLastError();
		LOG(ERR,"Arduino::OpenDevice - SetCommStateFailed %d", err);
		CloseHandle(hCommPort);
		hCommPort=INVALID_HANDLE_VALUE;
		PrintError(err);
		init_lock.Unlock();
		return ARDUINO_SET_COMMSTATE_FAILED;
	}


	LOG(MAINFUNC,"Arduino::OpenDevice - enable listening to comm events");
	DWORD      dwStoredFlags;
	// listen only for events regarding errors and receive buffer
	dwStoredFlags = /*EV_BREAK | EV_CTS |*/ EV_DSR | /* EV_ERR | EV_RING | EV_RLSD | */ EV_RXCHAR /* | EV_RXFLAG | EV_TXEMPTY*/ ;
	if (!SetCommMask(hCommPort, dwStoredFlags))
//.........这里部分代码省略.........
开发者ID:miaozhendaoren,项目名称:SardineCAN-Win32,代码行数:101,代码来源:Arduino.cpp

示例10: uninit_driver

void uninit_driver()
{
	TRACE("uninit_driver\n");
	gLock.Delete();
	put_module(VBOXGUEST_MODULE_NAME);
}
开发者ID:LastRitter,项目名称:vbox-haiku,代码行数:6,代码来源:driver.cpp


注:本文中的Benaphore类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。