本文整理汇总了C++中snooze函数的典型用法代码示例。如果您正苦于以下问题:C++ snooze函数的具体用法?C++ snooze怎么用?C++ snooze使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snooze函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: thread_usleep
inline void thread_usleep(unsigned int usec) { snooze(usec); }
开发者ID:Kazunekit,项目名称:OcherBook,代码行数:1,代码来源:Thread.cpp
示例2: RTDECL
RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
{
RT_ASSERT_PREEMPTIBLE();
snooze((bigtime_t)cMillies * 1000);
return VINF_SUCCESS;
}
开发者ID:LastRitter,项目名称:vbox-haiku,代码行数:6,代码来源:thread-r0drv-haiku.c
示例3: Device
Hub::Hub(Object *parent, int8 hubAddress, uint8 hubPort,
usb_device_descriptor &desc, int8 deviceAddress, usb_speed speed,
bool isRootHub)
: Device(parent, hubAddress, hubPort, desc, deviceAddress, speed,
isRootHub),
fInterruptPipe(NULL)
{
TRACE("creating hub\n");
memset(&fHubDescriptor, 0, sizeof(fHubDescriptor));
for (int32 i = 0; i < USB_MAX_PORT_COUNT; i++)
fChildren[i] = NULL;
if (!fInitOK) {
TRACE_ERROR("device failed to initialize\n");
return;
}
// Set to false again for the hub init.
fInitOK = false;
if (fDeviceDescriptor.device_class != 9) {
TRACE_ERROR("wrong class! bailing out\n");
return;
}
TRACE("getting hub descriptor...\n");
size_t actualLength;
status_t status = GetDescriptor(USB_DESCRIPTOR_HUB, 0, 0,
(void *)&fHubDescriptor, sizeof(usb_hub_descriptor), &actualLength);
// we need at least 8 bytes
if (status < B_OK || actualLength < 8) {
TRACE_ERROR("error getting hub descriptor\n");
return;
}
TRACE("hub descriptor (%ld bytes):\n", actualLength);
TRACE("\tlength:..............%d\n", fHubDescriptor.length);
TRACE("\tdescriptor_type:.....0x%02x\n", fHubDescriptor.descriptor_type);
TRACE("\tnum_ports:...........%d\n", fHubDescriptor.num_ports);
TRACE("\tcharacteristics:.....0x%04x\n", fHubDescriptor.characteristics);
TRACE("\tpower_on_to_power_g:.%d\n", fHubDescriptor.power_on_to_power_good);
TRACE("\tdevice_removeable:...0x%02x\n", fHubDescriptor.device_removeable);
TRACE("\tpower_control_mask:..0x%02x\n", fHubDescriptor.power_control_mask);
if (fHubDescriptor.num_ports > USB_MAX_PORT_COUNT) {
TRACE_ALWAYS("hub supports more ports than we do (%d vs. %d)\n",
fHubDescriptor.num_ports, USB_MAX_PORT_COUNT);
fHubDescriptor.num_ports = USB_MAX_PORT_COUNT;
}
usb_interface_list *list = Configuration()->interface;
Object *object = GetStack()->GetObject(list->active->endpoint[0].handle);
if (object && (object->Type() & USB_OBJECT_INTERRUPT_PIPE) != 0) {
fInterruptPipe = (InterruptPipe *)object;
fInterruptPipe->QueueInterrupt(fInterruptStatus,
sizeof(fInterruptStatus), InterruptCallback, this);
} else {
TRACE_ALWAYS("no interrupt pipe found\n");
}
// Wait some time before powering up the ports
if (!isRootHub)
snooze(USB_DELAY_HUB_POWER_UP);
// Enable port power on all ports
for (int32 i = 0; i < fHubDescriptor.num_ports; i++) {
status = DefaultPipe()->SendRequest(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_OUT,
USB_REQUEST_SET_FEATURE, PORT_POWER, i + 1, 0, NULL, 0, NULL);
if (status < B_OK)
TRACE_ERROR("power up failed on port %" B_PRId32 "\n", i);
}
// Wait for power to stabilize
snooze(fHubDescriptor.power_on_to_power_good * 2000);
fInitOK = true;
TRACE("initialised ok\n");
}
开发者ID:ErfanBagheri,项目名称:haiku,代码行数:81,代码来源:Hub.cpp
示例4: MTAKE
static void *sendKeepalives(void *parm)
{
KeepaliveThreadParms *parms = (KeepaliveThreadParms *) parm;
int keepaliveTimer = 0;
int bytesSent;
int backoffTimer = BACKOFF_TIMER_START;
int backoffTimerCount = 0;
unsigned char *buffer;
buffer = MTAKE(TCPCLA_BUFSZ); //To send keepalive bundle
if (buffer == NULL)
{
putErrmsg("No memory for TCP buffer in tcpclo.", NULL);
return NULL;
}
iblock(SIGTERM);
while (*(parms->cloRunning))
{
snooze(1);
keepaliveTimer++;
if (keepaliveTimer < *(parms->keepalivePeriod))
{
continue;
}
// If the negotiated keep alive interval is 0, then
// keep alives will not be sent.
if(*(parms->keepalivePeriod) == 0)
{
continue;
}
/* Time to send a keepalive. Note that the
* interval between keepalive attempts will be
* KEEPALIVE_PERIOD plus (if the remote induct
* is not reachable) the length of time taken
* by TCP to determine that the connection
* attempt will not succeed (e.g., 3 seconds). */
keepaliveTimer = 0;
pthread_mutex_lock(parms->mutex);
bytesSent = sendBundleByTCPCL(parms->socketName,
parms->ductSocket, 0, 0, buffer, parms->keepalivePeriod);
pthread_mutex_unlock(parms->mutex);
/* if the node is unable to establish a TCP connection,
* the connection should be tried only after some delay.
* */
if(bytesSent == 0)
{
while((backoffTimerCount < backoffTimer) && (*(parms->ductSocket) < 0))
{
snooze(1);
backoffTimerCount++;
if(!(*(parms->cloRunning)))
{
break;
}
}
backoffTimerCount = 0;
/* keepaliveTimer keeps track of when the keepalive needs
* to be sent. This value is set to keepalive period.
* That way at the end of backoff period a
* keepalive is sent
* */
keepaliveTimer = *(parms->keepalivePeriod);
if(backoffTimer < BACKOFF_TIMER_LIMIT)
{
backoffTimer *= 2;
}
continue;
}
backoffTimer = BACKOFF_TIMER_START;
if (bytesSent < 0)
{
shutDownClo();
break;
}
}
MRELEASE(buffer);
return NULL;
}
开发者ID:brnrc,项目名称:ion-dtn,代码行数:83,代码来源:tcpclo.c
示例5: Virge_GEReset
static void
Virge_GEReset(const DisplayModeEx& mode)
{
SharedInfo& si = *gInfo.sharedInfo;
if (si.chipType == S3_TRIO_3D)
Virge_NopAllCmdSets();
gInfo.WaitIdleEmpty();
if (si.chipType == S3_TRIO_3D) {
bool ge_was_on = false;
snooze(10000);
for (int r = 1; r < 10; r++) {
uint8 resetidx = 0x66;
VerticalRetraceWait();
uint8 tmp = ReadCrtcReg(resetidx);
VerticalRetraceWait();
IN_SUBSYS_STAT();
// turn off the GE
if (tmp & 0x01) {
WriteCrtcReg(resetidx, tmp);
ge_was_on = true;
snooze(10000);
}
IN_SUBSYS_STAT();
WriteCrtcReg(resetidx, tmp | 0x02);
snooze(10000);
VerticalRetraceWait();
WriteCrtcReg(resetidx, tmp & ~0x02);
snooze(10000);
if (ge_was_on) {
tmp |= 0x01;
WriteCrtcReg(resetidx, tmp);
snooze(10000);
}
VerticalRetraceWait();
Virge_NopAllCmdSets();
gInfo.WaitIdleEmpty();
WriteReg32(DEST_SRC_STR, mode.bytesPerRow << 16 | mode.bytesPerRow);
snooze(10000);
if ((IN_SUBSYS_STAT() & 0x3f802000 & 0x20002000) != 0x20002000) {
TRACE("Restarting S3 graphics engine reset %2d ...%lx\n",
r, IN_SUBSYS_STAT() );
} else
break;
}
} else {
uint8 regIndex = (si.chipType == S3_VIRGE_VX ? 0x63 : 0x66);
uint8 tmp = ReadCrtcReg(regIndex);
snooze(10000);
// try multiple times to avoid lockup of VIRGE/MX
for (int r = 1; r < 10; r++) {
WriteCrtcReg(regIndex, tmp | 0x02);
snooze(10000);
WriteCrtcReg(regIndex, tmp & ~0x02);
snooze(10000);
gInfo.WaitIdleEmpty();
WriteReg32(DEST_SRC_STR, mode.bytesPerRow << 16 | mode.bytesPerRow);
snooze(10000);
if (((IN_SUBSYS_STAT() & 0x3f00) != 0x3000)) {
TRACE("Restarting S3 graphics engine reset %2d ...\n", r);
} else
break;
}
}
gInfo.WaitQueue(2);
WriteReg32(SRC_BASE, 0);
WriteReg32(DEST_BASE, 0);
gInfo.WaitQueue(4);
WriteReg32(CLIP_L_R, ((0) << 16) | mode.timing.h_display);
WriteReg32(CLIP_T_B, ((0) << 16) | mode.timing.v_display);
WriteReg32(MONO_PAT_0, ~0);
WriteReg32(MONO_PAT_1, ~0);
if (si.chipType == S3_TRIO_3D)
Virge_NopAllCmdSets();
}
开发者ID:DonCN,项目名称:haiku,代码行数:96,代码来源:virge_mode.cpp
示例6: floatsleep
//.........这里部分代码省略.........
delay((int)(secs * 1000 + 0.5)); /* delay() uses milliseconds */
Py_END_ALLOW_THREADS
#elif defined(MS_WINDOWS)
{
double millisecs = secs * 1000.0;
unsigned long ul_millis;
if (millisecs > (double)ULONG_MAX) {
PyErr_SetString(PyExc_OverflowError,
"sleep length is too large");
return -1;
}
Py_BEGIN_ALLOW_THREADS
/* Allow sleep(0) to maintain win32 semantics, and as decreed
* by Guido, only the main thread can be interrupted.
*/
ul_millis = (unsigned long)millisecs;
if (ul_millis == 0 ||
main_thread != PyThread_get_thread_ident())
Sleep(ul_millis);
else {
DWORD rc;
ResetEvent(hInterruptEvent);
rc = WaitForSingleObject(hInterruptEvent, ul_millis);
if (rc == WAIT_OBJECT_0) {
/* Yield to make sure real Python signal
* handler called.
*/
Sleep(1);
Py_BLOCK_THREADS
errno = EINTR;
PyErr_SetFromErrno(PyExc_IOError);
return -1;
}
}
Py_END_ALLOW_THREADS
}
#elif defined(PYOS_OS2)
/* This Sleep *IS* Interruptable by Exceptions */
Py_BEGIN_ALLOW_THREADS
if (DosSleep(secs * 1000) != NO_ERROR) {
Py_BLOCK_THREADS
PyErr_SetFromErrno(PyExc_IOError);
return -1;
}
Py_END_ALLOW_THREADS
#elif defined(__BEOS__)
/* This sleep *CAN BE* interrupted. */
{
if( secs <= 0.0 ) {
return;
}
Py_BEGIN_ALLOW_THREADS
/* BeOS snooze() is in microseconds... */
if( snooze( (bigtime_t)( secs * 1000.0 * 1000.0 ) ) == B_INTERRUPTED ) {
Py_BLOCK_THREADS
PyErr_SetFromErrno( PyExc_IOError );
return -1;
}
Py_END_ALLOW_THREADS
}
#elif defined(RISCOS)
if (secs <= 0.0)
return 0;
Py_BEGIN_ALLOW_THREADS
/* This sleep *CAN BE* interrupted. */
if ( riscos_sleep(secs) )
return -1;
Py_END_ALLOW_THREADS
#elif defined(PLAN9)
{
double millisecs = secs * 1000.0;
if (millisecs > (double)LONG_MAX) {
PyErr_SetString(PyExc_OverflowError, "sleep length is too large");
return -1;
}
/* This sleep *CAN BE* interrupted. */
Py_BEGIN_ALLOW_THREADS
if(sleep((long)millisecs) < 0){
Py_BLOCK_THREADS
PyErr_SetFromErrno(PyExc_IOError);
return -1;
}
Py_END_ALLOW_THREADS
}
#elif _AMIGA
/* XXX Can't interrupt this sleep */
Py_BEGIN_ALLOW_THREADS
Delay((long)(secs*50));
Py_END_ALLOW_THREADS
#else /* !_AMIGA */
/* XXX Can't interrupt this sleep */
Py_BEGIN_ALLOW_THREADS
sleep((int)secs);
Py_END_ALLOW_THREADS
#endif /* !_AMIGA */ /* XXX Can't interrupt this sleep */
return 0;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:101,代码来源:timemodule.c
示例7: s
status_t TToolTipView::ToolTipThread(tool_tip *tip)
{
uint32 buttons;
BPoint where;
BScreen s(B_MAIN_SCREEN_ID);
BRect screen = s.Frame();
screen.InsetBy(2, 2);
while (!tip->quit) {
if (tip->tool_tip_window->LockWithTimeout(0) == B_NO_ERROR)
{
if (tip->tool_tip_view->Window())
tip->tool_tip_view->GetMouse(&where, &buttons,false);
/* if (tip->tool_tip_view->Window())
if (tip->tool_tip_view->Window()->CurrentMessage())
{
tip->tool_tip_view->Window()->CurrentMessage()->FindPoint("where", &where);
tip->tool_tip_view->Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
}
*/
tip->tool_tip_view->ConvertToScreen(&where);
tip->stopped = tip->stop;
if (tip->reset) {
if (tip->showing)
tip->tool_tip_window->Hide();
tip->stop = false;
tip->stopped = false;
tip->reset = false;
tip->shown = false;
tip->showing = false;
tip->start_time = system_time() + tip->settings.delay;
}
else if (tip->showing) {
if ((tip->stop) ||
(!tip->settings.enabled) ||
(!tip->app_active) ||
(!tip->bounds.Contains(where)) ||
(tip->expire_time < system_time()) ||
(abs((int)tip->start.x - (int)where.x) > kSLOP) ||
(abs((int)tip->start.y - (int)where.y) > kSLOP) ||
(buttons)) {
tip->tool_tip_window->Hide();
tip->shown = tip->settings.one_time_only;
tip->showing = false;
tip->tip_timed_out = (tip->expire_time < system_time());
tip->start_time = system_time() + tip->settings.delay;
}
}
else if ((tip->settings.enabled) &&
(!tip->stopped) &&
(tip->app_active) &&
(!tip->shown) &&
(!tip->tip_timed_out) &&
(!buttons) &&
(tip->bounds.Contains(where)) &&
(tip->start_time < system_time())) {
tip->start = where;
tip->tool_tip_view->AdjustWindow();
tip->tool_tip_window->Show();
tip->tool_tip_window->Activate(false);
tip->showing = true;
tip->expire_time = system_time() + tip->settings.hold;
tip->start = where;
}
else if ((abs((int)tip->start.x - (int)where.x) > kSLOP) ||
(abs((int)tip->start.y - (int)where.y) > kSLOP)) {
tip->start = where;
tip->start_time = system_time() + tip->settings.delay;
tip->tip_timed_out = false;
}
if (buttons)
tip->start_time = system_time() + tip->settings.delay;
tip->tool_tip_window->Unlock();
}
snooze(50000);
}
return B_NO_ERROR;
}
开发者ID:HaikuArchives,项目名称:Globe,代码行数:80,代码来源:TToolTip.cpp
示例8: main
int main (int argc, char* argv[]) {
// int oldtime, newtime; // bk001204 - unused
int len, i;
char *cmdline;
//jens void Sys_SetDefaultCDPath(const char *path);
thread_id cThread;
cThread = spawn_thread(appthread, "q3appthread", B_LOW_PRIORITY, 0);
resume_thread(cThread);
snooze(100000); //Todo
app_info cInfo;
be_app->GetAppInfo(&cInfo);
BEntry cFile(&cInfo.ref);
BEntry cDir;
cFile.GetParent(&cDir);
BPath cPath;
cDir.GetPath(&cPath);
chdir(cPath.Path());
be_app->HideCursor();
// go back to real user for config loads
//jens saved_euid = geteuid();
//jens seteuid(getuid());
Sys_ParseArgs(argc, argv); // bk010104 - added this for support
Sys_SetDefaultCDPath(argv[0]);
// merge the command line, this is kinda silly
for (len = 1, i = 1; i < argc; i++)
len += strlen(argv[i]) + 1;
cmdline = (char*)malloc(len);
*cmdline = 0;
for (i = 1; i < argc; i++) {
if (i > 1)
strcat(cmdline, " ");
strcat(cmdline, argv[i]);
}
// bk000306 - clear queues
memset(&eventQue[0], 0, MAX_QUED_EVENTS*sizeof(sysEvent_t) );
memset(&sys_packetReceived[0], 0, MAX_MSGLEN*sizeof(byte) );
Com_Init(cmdline);
NET_Init();
Sys_ConsoleInputInit();
// int fd = 0;
// fd = fileno(stdin);
// int on = 1;
// setsockopt(fd, SOL_SOCKET, SO_NONBLOCK, &on, sizeof(int));
// setsockopt(STDIN_FILENO, SOL_SOCKET, SO_NONBLOCK, &on, sizeof(int));
//jensfcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
#ifdef DEDICATED
// init here for dedicated, as we don't have GLimp_Init
//jens InitSig();
#endif
while (1) {
#ifdef __linux__
Sys_ConfigureFPU();
#endif
Com_Frame ();
}
}
开发者ID:kallisti5,项目名称:quake3,代码行数:69,代码来源:beos_main.cpp
示例9: yahoo_io_thread
int32
yahoo_io_thread( void * _data )
{
YahooConnection * conn = (YahooConnection*)_data;
register_callbacks();
conn->fID = yahoo_init_with_attributes(conn->fYahooID, conn->fPassword,
"local_host", "95.252.70.62",
"pager_port", 5050, NULL);
LOG("yahoo_io_thread: id: %s, pass: %s\n", conn->fYahooID, conn->fPassword );
gYahooConnections[conn->fID] = conn;
yahoo_login(conn->fID, YAHOO_STATUS_AVAILABLE);
int lfd = 0;
fd_set inp, outp;
struct timeval tv;
while (conn->IsAlive()) {
snooze(10000);
FD_ZERO(&inp);
FD_ZERO(&outp);
tv.tv_sec=3;
tv.tv_usec=1E4;
lfd=0;
int i;
for(i = 0; i < conn->CountConnections(); i++) {
struct conn_handler *c = conn->ConnectionAt(i);
if(c->remove) {
conn->RemoveConnection(c);
c->remove = 0;
free(c);
} else {
if(c->cond & YAHOO_INPUT_READ)
FD_SET(c->con->fd, &inp);
if(c->cond & YAHOO_INPUT_WRITE)
FD_SET(c->con->fd, &outp);
if(lfd < c->con->fd)
lfd = c->con->fd;
}
}
select(lfd + 1, &inp, &outp, NULL, &tv);
time(&curTime);
for(i = 0; i < conn->CountConnections(); i++) {
struct conn_handler *c = conn->ConnectionAt(i);
if(c->con->remove) {
free(c->con);
c->con = NULL;
break;
}
if(c->remove)
continue;
if(FD_ISSET(c->con->fd, &inp))
yahoo_callback(c, YAHOO_INPUT_READ);
if(FD_ISSET(c->con->fd, &outp))
yahoo_callback(c, YAHOO_INPUT_WRITE);
}
if(expired(pingTimer))
yahoo_ping_timeout_callback(conn->fID);
// if(expired(webcamTimer)) yahoo_webcam_timeout_callback(webcam_id);
}
LOG("Exited loop");
for(int i = 0; i < conn->CountConnections(); i++) {
struct conn_handler *c = conn->ConnectionAt(i);
free(c);
conn->RemoveConnection(c);
}
return 0;
}
开发者ID:Barrett17,项目名称:Caya,代码行数:78,代码来源:YahooCallbacks.cpp
示例10: ltpclock
int ltpclock(int a1, int a2, int a3, int a4, int a5,
int a6, int a7, int a8, int a9, int a10)
{
#else
int main(int argc, char *argv[])
{
#endif
Sdr sdr;
LtpDB *ltpConstants;
int state = 1;
time_t currentTime;
if (ltpInit(0, 0) < 0)
{
putErrmsg("ltpclock can't initialize LTP.", NULL);
return 1;
}
sdr = getIonsdr();
ltpConstants = getLtpConstants();
isignal(SIGTERM, shutDown);
/* Main loop: wait for event occurrence time, then
* execute applicable events. */
oK(_running(&state));
writeMemo("[i] ltpclock is running.");
while (_running(NULL))
{
/* Sleep for 1 second, then dispatch all events
* whose executions times have now been reached. */
snooze(1);
currentTime = getUTCTime();
/* Infer link state changes from rate changes
* noted in the shared ION database. */
if (manageLinks(sdr, currentTime) < 0)
{
putErrmsg("Can't manage links.", NULL);
state = 0; /* Terminate loop. */
oK(_running(&state));
continue;
}
/* Then dispatch retransmission events, as
* constrained by the new link state. */
if (dispatchEvents(sdr, ltpConstants->timeline, currentTime)
< 0)
{
putErrmsg("Can't dispatch events.", NULL);
state = 0; /* Terminate loop. */
oK(_running(&state));
continue;
}
}
writeErrmsgMemos();
writeMemo("[i] ltpclock has ended.");
ionDetach();
return 0;
}
开发者ID:b,项目名称:ION,代码行数:64,代码来源:ltpclock.c
示例11: usb_disk_device_added
//.........这里部分代码省略.........
mutex_init(&device->lock, "usb_disk device lock");
status_t result = device->notify =
create_sem(0, "usb_disk callback notify");
if (result < B_OK) {
mutex_destroy(&device->lock);
free(device);
return result;
}
result = device->interruptLock = create_sem(0, "usb_disk interrupt lock");
if (result < B_OK) {
mutex_destroy(&device->lock);
free(device);
return result;
}
// TODO: handle more than 1 unit
device->lun_count = 1;
device->luns = (device_lun **)malloc(device->lun_count
* sizeof(device_lun *));
for (uint8 i = 0; i < device->lun_count; i++)
device->luns[i] = NULL;
result = B_OK;
TRACE_ALWAYS("device reports a lun count of %d\n", device->lun_count);
for (uint8 i = 0; i < device->lun_count; i++) {
// create the individual luns present on this device
device_lun *lun = (device_lun *)malloc(sizeof(device_lun));
if (lun == NULL) {
result = B_NO_MEMORY;
break;
}
device->luns[i] = lun;
lun->device = device;
lun->logical_unit_number = i;
lun->should_sync = false;
lun->media_present = true;
lun->media_changed = true;
usb_disk_reset_capacity(lun);
// initialize this lun
result = usb_disk_inquiry(lun);
// Reset the device
// If we don't do it all the other commands except inquiry and send
// diagnostics will be stalled.
result = usb_disk_send_diagnostic(lun);
for (uint32 tries = 0; tries < 3; tries++) {
status_t ready = usb_disk_test_unit_ready(lun);
if (ready == B_OK || ready == B_DEV_NO_MEDIA) {
if (ready == B_OK) {
if (lun->device_type == B_CD)
lun->write_protected = true;
// TODO: check for write protection; disabled since
// some devices lock up when getting the mode sense
else if (/*usb_disk_mode_sense(lun) != B_OK*/true)
lun->write_protected = false;
}
break;
}
snooze(10000);
}
if (result != B_OK)
break;
}
if (result != B_OK) {
TRACE_ALWAYS("failed to initialize logical units\n");
usb_disk_free_device_and_luns(device);
return result;
}
mutex_lock(&gDeviceListLock);
device->device_number = 0;
disk_device *other = gDeviceList;
while (other != NULL) {
if (other->device_number >= device->device_number)
device->device_number = other->device_number + 1;
other = (disk_device *)other->link;
}
device->link = (void *)gDeviceList;
gDeviceList = device;
gLunCount += device->lun_count;
for (uint8 i = 0; i < device->lun_count; i++)
sprintf(device->luns[i]->name, DEVICE_NAME, device->device_number, i);
mutex_unlock(&gDeviceListLock);
TRACE("new device: 0x%08lx\n", (uint32)device);
*cookie = (void *)device;
return B_OK;
}
开发者ID:Karvjorm,项目名称:haiku,代码行数:101,代码来源:usb_disk.cpp
示例12: main
int main(int argc, char *argv[])
{
ALuint freq;
ALenum format;
ALvoid *data;
ALsizei i, size;
thread_id thread1, thread2;
status_t status;
/* listener parameters */
ALfloat listenerOrientation[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f };
ALfloat listenerPosition[] = { 0.0f, 0.0f, 0.0f };
ALfloat listenerVelocity[] = { 0.0f, 0.0f, 0.0f };
/* source parameters */
ALfloat sourcePosition[] = { 0.0f, 0.0f, 1.0f };
ALfloat sourceVelocity[] = { 0.0f, 0.0f, 0.0f };
ALfloat sourcePitch = 1.0f;
ALfloat sourceGain = 1.0f;
/* initialize */
print("Main: initialize");
alInit((ALint *) &argc, (ALubyte **) argv);
/* create context */
print("Main: create context");
context = alcCreateContext(22050, AL_FORMAT_STEREO16, 2048);
/* lock the context */
print("Main: make current");
alcMakeCurrent(context);
/* create buffers and sources */
if (alGenBuffers(kNumBuffers, buffer) != kNumBuffers)
quit("Can't create buffers");
if (alGenSources(kNumSources, source) != kNumSources)
quit("Can't create sources");
/* load buffers with data */
alutLoadWAV(kWaveFileName, &format, &data, &size, &freq);
for (i = 0; i < kNumBuffers; i++) {
alBufferData(buffer[i], format, data, size, freq);
}
free(data);
/* initialize listener */
alListenerfv(AL_POSITION, listenerPosition);
alListenerfv(AL_VELOCITY, listenerVelocity);
alListenerfv(AL_ORIENTATION, listenerOrientation);
/* initialize sources */
for (i = 0; i < kNumSources; i++) {
alSourcefv(source[i], AL_POSITION, sourcePosition);
alSourcefv(source[i], AL_VELOCITY, sourceVelocity);
alSourcef(source[i], AL_PITCH, sourcePitch);
alSourcef(source[i], AL_GAIN, sourceGain);
alSourcei(source[i], AL_BUFFER, buffer[i % kNumBuffers]);
alSourcei(source[i], AL_LOOPING, AL_TRUE);
}
/* start the sources */
print("Main: play");
for (i = 0; i < kNumSources; i++)
alSourcePlay(source[i]);
/* release the context */
print("Main: release current");
alcMakeCurrent(NULL);
/* spawn two threads */
print("Main: spawn thread 1");
thread1 = spawn_thread(threadFunc1, "thread 1", B_NORMAL_PRIORITY, NULL);
print("Main: spawn thread 2");
thread2 = spawn_thread(threadFunc2, "thread 2", B_NORMAL_PRIORITY, NULL);
/* resume the threads */
print("Main: resume thread 1");
resume_thread(thread1);
print("Main: resume thread 2");
resume_thread(thread2);
/* acquire context, snooze and release context */
print("Main: make current");
alcMakeCurrent(context);
print("Main: snooze...");
snooze(500000);
print("Main: release current");
alcMakeCurrent(NULL);
//.........这里部分代码省略.........
开发者ID:Aye1,项目名称:RVProject,代码行数:101,代码来源:testctx1.c
示例13: Window
void PatternMenuButton::MouseDown (BPoint point)
{
// BMenuItem *selected;
// point = BPoint (0, 0);
// ConvertToScreen (&point);
// BRect openRect = BRect (point.x - OPEN_RAD, point.y - OPEN_RAD,
// point.x + OPEN_RAD, point.y + OPEN_RAD);
// menu->Show();
// if ((selected = menu->Track (true, &openRect)) != NULL)
// {
// index = menu->IndexOf (selected);
// menu->Mark (index);
// menu->InvalidateWindow();
// }
// menu->Hide();
// Invalidate();
Window()->Lock();
uint32 buttons = Window()->CurrentMessage()->FindInt32 ("buttons");
// uint32 clicks = Window()->CurrentMessage()->FindInt32 ("clicks");
BMenuItem *mselected;
point = BPoint (0, 0);
ConvertToScreen (&point);
if (click != 2 && buttons & B_PRIMARY_MOUSE_BUTTON && !(modifiers() & B_CONTROL_KEY))
{
BPoint bp, pbp;
uint32 bt;
GetMouse (&pbp, &bt, true);
bigtime_t start = system_time();
while (system_time() - start < dcspeed)
{
snooze (20000);
GetMouse (&bp, &bt, true);
if (!bt && click != 2)
{
click = 0;
}
if (bt && !click)
{
click = 2;
}
if (bp != pbp)
break;
}
if (click != 2)
{
BRect openRect = BRect (point.x - OPEN_RAD, point.y - OPEN_RAD,
point.x + OPEN_RAD, point.y + OPEN_RAD);
menu->Show();
if ((mselected = menu->Track (true, &openRect)) != NULL)
{
index = menu->IndexOf (mselected);
menu->Mark (index);
if (MenuWinOnScreen)
menu->InvalidateWindow();
}
menu->Hide();
if (editorshowing)
{
// rgb_color c = color();
// BMessage *msg = new BMessage ('SetC');
// msg->AddInt32 ("color", c.red);
// msg->AddInt32 ("color", c.green);
// msg->AddInt32 ("color", c.blue);
// editor->PostMessage (msg);
// delete msg;
}
click = 1;
}
}
if (click == 2 || buttons & B_SECONDARY_MOUSE_BUTTON || modifiers() & B_CONTROL_KEY)
{
click = 1;
if (editorshowing)
{
// rgb_color c = color();
// BMessage *msg = new BMessage ('SetC');
// msg->AddInt32 ("color", c.red);
// msg->AddInt32 ("color", c.green);
// msg->AddInt32 ("color", c.blue);
// editor->PostMessage (msg);
// delete msg;
}
else
{
ShowEditor();
}
}
Invalidate();
Window()->Unlock();
}
开发者ID:gedrin,项目名称:Becasso,代码行数:90,代码来源:PatternMenuButton.cpp
示例14: Window
void CMassView::MouseDown(BPoint where) // reacts to mouse clicks
{
long whichButtons = 1; // used for tracking which buttons are down
Window()->CurrentMessage()->FindInt32("buttons", &whichButtons); // find out which buttons are down
if (inGLMode && (whichButtons & B_SECONDARY_MOUSE_BUTTON)) // if we are in GL mode, and button 2 is down
{
float frameWidth = Frame().Width(), frameHeight = Frame().Height(); // find the width & height
dragMode = dragBall; // drag the arcball to rotate
HVect vNow; // vector type for passing to ball functions
vNow.x = (2.0 * where.x - frameWidth)/frameWidth; // set the vector
vNow.y = -(2.0 * where.y - frameHeight)/frameHeight; // in both dimensions
Ball_Mouse(&ball, vNow); // and pass it to the Ball functions
Ball_BeginDrag(&ball); // start dragging
while (whichButtons) // loop until drop the mouse
{
snooze(20 * 1000); // snooze for 20 µs
GetMouse(&where, (ulong *)&whichButtons, true); // get the mouse location, &c.
vNow.x = (2.0 * where.x - frameWidth)/frameWidth; // set the vector
vNow.y = -(2.0 * where.y - frameHeight)/frameHeight; // in both dimensions
Ball_Mouse(&ball, vNow); // and pass it to the Ball functions
Draw(Frame()); // redraw the entire frame
} // end of while (whichButtons)
Ball_EndDrag(&ball); // stop dragging
} // end of case where dragging
else if (acceptClicks) // if we have "accept" switched on
{
long row, col; // the board coordinates of the click
if (!inGLMode) // if it's the regular board
{
row = where.y / CELL_SIZE; // calculate which row to look in
col = where.x / CELL_SIZE; // and which column
} // end of normal mode
else
{
GLubyte theColour[4]; // array for retrieving "colour"
LockGL(); // lock in preparation for drawing
GLfloat mNow[16]; // local matrix for ball routines
Ball_Update(&ball); // update the data for the ball
Ball_Value(&ball, mNow); // retrieve the ball's position as a matrix
glDisable(GL_LIGHTING); // disable lighting
glShadeModel(GL_FLAT); // switch to flat shading
glMatrixMode(GL_MODELVIEW); // make sure that we are set to the model matrix
glClearColor(0.0, 0.0, 0.0, 1.0); // and set the "clear" colour to black
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the window to black
glPushMatrix(); // push the GL stack to get a new matrix
glLoadIdentity(); // load the identity matrix
glTranslatef(0, 0, -600.0); // translate the model matrix
glMultMatrixf(mNow); // multiply by this matrix
glCallList(torusPickListID); // and call the display list
glReadPixels(where.x, Frame().Height() - where.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, theColour);
// read a single pixel at the mouse location
glPopMatrix(); // pop the matrix back off the stack
glEnable(GL_LIGHTING); // re-enable lighting
glShadeModel(GL_SMOOTH); // and smoothness
UnlockGL(); // unlock GL
Draw(Frame()); // redraw the entire picture
row = theColour[1] - 128; col = theColour[0] - 128; // retrieve the row & column
// (background is black & returns -128)
// printf("%d %d\n", row, col); return;
} // end of GL mode code
if (row < 0) return; // make sure it is a legal cell
else if (row >= theBoard.getHeight()) return; // i.e. not off top or bottom
if (col < 0) return; // same with left & right
else if (col >= theBoard.getWidth()) return;
BMessage *theMessage = new BMessage(CM_MSG_MOVE_CHOSEN); // create a message for it
acceptClicks = false; // turn off "accept clicks"
theMessage->AddInt32("row", row); theMessage->AddInt32("column", col); // add the coordinates to the message
be_app->PostMessage(theMessage); // send the message off
delete theMessage; // get rid of the message when done
} // end of case where we accept clicks
} // end of MouseDown()
开发者ID:pulkomandy,项目名称:critical-mass,代码行数:74,代码来源:CMassView.cpp
示例15: usb_disk_device_added
//.........这里部分代码省略.........
if (hasIn && hasOut)
break;
}
if (!(hasIn && hasOut))
continue;
device->interface = interface->descr->interface_number;
break;
}
}
if (device->interface == 0xff) {
TRACE_ALWAYS("no valid bulk-only interface found\n");
free(device);
return B_ERROR;
}
mutex_init(&device->lock, "usb_disk device lock");
device->notify = create_sem(0, "usb_disk callback notify");
if (device->notify < B_OK) {
mutex_destroy(&device->lock);
free(device);
return device->notify;
}
device->lun_count = usb_disk_get_max_lun(device) + 1;
device->luns = (device_lun **)malloc(device->lun_count
* sizeof(device_lun *));
for (uint8 i = 0; i < device->lun_count; i++)
device->luns[i] = NULL;
status_t result = B_OK;
TRACE_ALWAYS("device reports a lun count of %d\n", device->lun_count);
for (uint8 i = 0; i < device->lun_count; i++) {
// create the individual luns present on this device
device_lun *lun = (device_lun *)malloc(sizeof(device_lun));
if (lun == NULL) {
result = B_NO_MEMORY;
break;
}
device->luns[i] = lun;
lun->device = device;
lun->logical_unit_number = i;
lun->should_sync = false;
lun->media_present = true;
lun->media_changed = true;
usb_disk_reset_capacity(lun);
// initialize this lun
result = usb_disk_inquiry(lun);
for (uint32 tries = 0; tries < 3; tries++) {
status_t ready = usb_disk_test_unit_ready(lun);
if (ready == B_OK || ready == B_DEV_NO_MEDIA) {
if (ready == B_OK) {
// TODO: check for write protection
//if (usb_disk_mode_sense(lun) != B_OK)
lun->write_protected = false;
}
break;
}
snooze(10000);
}
if (result != B_OK)
break;
}
if (result != B_OK) {
TRACE_ALWAYS("failed to initialize logical units\n");
usb_disk_free_device_and_luns(device);
return result;
}
mutex_lock(&gDeviceListLock);
device->device_number = 0;
disk_device *other = gDeviceList;
while (other != NULL) {
if (other->device_number >= device->device_number)
device->device_number = other->device_number + 1;
other = (disk_device *)other->link;
}
device->link = (void *)gDeviceList;
gDeviceList = device;
gLunCount += device->lun_count;
for (uint8 i = 0; i < device->lun_count; i++)
sprintf(device->luns[i]->name, DEVICE_NAME, device->device_number, i);
mutex_unlock(&gDeviceListLock);
TRACE("new device: 0x%08lx\n", (uint32)device);
*cookie = (void *)device;
return B_OK;
}
开发者ID:earl-colby-pottinger,项目名称:CRAM,代码行数:101,代码来源:usb_disk.cpp
示例16: Virge_WriteMode
static void
Virge_WriteMode(const DisplayModeEx& mode, VirgeRegRec& regRec)
{
// This function writes out all of the standard VGA and extended S3 registers
// needed to setup a video mode.
TRACE("Virge_WriteMode()\n");
SharedInfo& si = *gInfo.sharedInfo;
// First reset GE to make sure nothing is going on.
if (ReadCrtcReg(si.chipType == S3_VIRGE_VX ? 0x63 : 0x66) & 0x01)
Virge_GEReset(mode);
// As per databook, always disable STREAMS before changing modes.
if ((ReadCrtcReg(0x67) & 0x0c) == 0x0c) {
// STREAMS running, disable it
VerticalRetraceWait();
WriteReg32(FIFO_CONTROL_REG, 0xC000);
WriteCrtcReg(0x67, 0x00, 0x0c); // disable STREAMS processor
}
// Restore S3 extended regs.
WriteCrtcReg(0x63, regRec.CR63);
WriteCrtcReg(0x66, regRec.CR66);
WriteCrtcReg(0x3a, regRec.CR3A);
WriteCrtcReg(0x31, regRec.CR31);
WriteCrtcReg(0x58, regRec.CR58);
// Extended mode timings registers.
WriteCrtcReg(0x53, regRec.CR53);
WriteCrtcReg(0x5d, regRec.CR5D);
WriteCrtcReg(0x5e, regRec.CR5E);
WriteCrtcReg(0x3b, regRec.CR3B);
WriteCrtcReg(0x3c, regRec.CR3C);
WriteCrtcReg(0x43, regRec.CR43);
WriteCrtcReg(0x65, regRec.CR65);
WriteCrtcReg(0x6d, regRec.CR6D);
// Restore the desired video mode with CR67.
WriteCrtcReg(0x67, 0x50, 0xf0); // possible hardware bug on VX?
snooze(10000);
WriteCrtcReg(0x67, regRec.CR67 & ~0x0c); // Don't enable STREAMS
// Other mode timing and extended regs.
WriteCrtcReg(0x34, regRec.CR34);
if (si.chipType != S3_TRIO_3D && si.chipType != S3_VIRGE_MX) {
WriteCrtcReg(0x40, regRec.CR40);
}
if (S3_VIRGE_MX_SERIES(si.chipType)) {
WriteCrtcReg(0x41, regRec.CR41);
}
WriteCrtcReg(0x42, regRec.CR42);
WriteCrtcReg(0x45, regRec.CR45);
WriteCrtcReg(0x51, regRec.CR51);
WriteCrtcReg(0x54, regRec.CR54);
// Memory timings.
WriteCrtcReg(0x68, regRec.CR68);
WriteCrtcReg(0x69, regRec.CR69);
WriteCrtcReg(0x33, regRec.CR33);
if (si.chipType == S3_TRIO_3D_2X || S3_VIRGE_GX2_SERIES(si.chipType)
/* MXTESTME */ || S3_VIRGE_MX_SERIES(si.chipType) ) {
WriteCrtcReg(0x85, regRec.CR85);
}
if (si.chipType == S3_VIRGE_DXGX) {
WriteCrtcReg(0x86, regRec.CR86);
}
if ( (si.chipType == S3_VIRGE_GX2) || S3_VIRGE_MX_SERIES(si.chipType) ) {
WriteCrtcReg(0x7b, regRec.CR7B);
WriteCrtcReg(0x7d, regRec.CR7D);
WriteCrtcReg(0x87, regRec.CR87);
WriteCrtcReg(0x92, regRec.CR92);
WriteCrtcReg(0x93, regRec.CR93);
}
if (si.chipType == S3_VIRGE_DXGX || S3_VIRGE_GX2_SERIES(si.chipType) ||
S3_VIRGE_MX_SERIES(si.chipType) || si.chipType == S3_TRIO_3D) {
WriteCrtcReg(0x90, regRec.CR90);
WriteCrtcReg(0x91, regRec.CR91);
}
WriteSeqReg(0x08, 0x06); // unlock extended sequencer regs
// Restore extended sequencer regs for DCLK.
WriteSeqReg(0x12, regRec.SR12);
WriteSeqReg(0x13, regRec.SR13);
if (S3_VIRGE_GX2_SERIES(si.chipType) || S3_VIRGE_MX_SERIES(si.chipType)) {
//.........这里部分代码省略.........
开发者ID:DonCN,项目名称:haiku,代码行数:101,代码来源:virge_mode.cpp
示例17: FUNCTION
void
TVideoPreviewView::DisplayThread()
{
FUNCTION("TVideoPreviewView::DisplayThread\n");
bigtime_t timeout = 5000;
bigtime_t realTimeNow = 0;
bigtime_t perfTimeNow = 0;
bigtime_t halfPeriod = (bigtime_t) (500000./29.97);
bool timeSourceRunning = false;
while (!mDisplayQuit) {
if (acquire_sem(mServiceLock) == B_NO_ERROR) {
timeSourceRunning = TimeSource()->IsRunning();
realTimeNow = BTimeSource::RealTime();
perfTimeNow = TimeSource()->Now();
release_sem(mServiceLock);
}
snooze(timeout);
if (timeSourceRunning) {
// if we received a Stop, deal with it
if (mStopping) {
PROGRESS("VidConsumer::DisplayThread - STOP\n");
if (perfTimeNow >= mStopTime) {
mRunning = false;
mStopping = false;
// deal with any pending Seek
if (mSeeking)
mSeeking = false;
//if (mConnected)
// SendDataStatus(B_DATA_NOT_AVAILABLE, mConnections[0], mStopTime);
continue;
}
}
// if we received a Seek, deal with it
if (mSeeking) {
PROGRESS("VidConsumer::DisplayThread - SEEK\n");
if (perfTimeNow >= mSeekTime) {
PROGRESS("VidConsumer::DisplayThread - DO SEEK\n");
mSeeking = false;
mDeltaTime = mMediaTime;
continue;
}
}
// if we received a Start, deal with it
if (mStarting) {
PROGRESS("BBt848Controllable::CaptureRun mStartTime = %.4f TimeNow = %.4f\n", (double)mStartTime/M1, (double)perfTimeNow/M1);
if (perfTimeNow >= mStartTime) {
mRunning = true;
mStarting = false;
mDeltaTime = mStartTime;
//if (mConnected)
// SendDataStatus(B_DATA_AVAILABLE, mConnections[0], mStartTime);
continue;
}
}
if (mRunning) {
// check for buffer available.
status_t err = acquire_sem_etc(mBufferAvailable, 1, B_TIMEOUT, halfPeriod * 2);
if (err == B_TIMED_OUT || !mConnected) {
ERROR("VidConsumer::DisplayThread - Error from acquire_sem_etc: 0x%lx\n", err);
continue;
}
BBuffer* buffer = mBufferQueue->PopFirstBuffer(0);
LOOP("Popped buffer %08x, Start time: %.4f, system time: %.4f diff: %.4f\n",
buffer,
(double) buffer->Header()->start_time/M1,
(double) perfTimeNow/M1,
(double) (buffer->Header()->start_time - perfTimeNow)/M1);
// Display frame if we're in B_OFFLINE mode or
// within +/- a half frame time of start time
if ( (mRunMode == B_OFFLINE) ||
((perfTimeNow > (buffer->Header()->start_time - halfPeriod)) &&
(perfTimeNow < (buffer->Header()->start_time + halfPeriod))) ) {
uint32 bpp = (mColorspace == B_RGB32 ? 4 : 2);
memcpy(m_Bitmap->Bits(), buffer->Data(), mRowBytes * mYSize * bpp);
buffer->Header()->start_time = system_time();
buffer->Recycle();
bigtime_t t1 = system_time();
// Update view
if (LockLooper()) {
DrawBitmap(m_Bitmap, Bounds());
UnlockLooper();
//.........这里部分代码省略.........
开发者ID:Barrett17,项目名称:UltraDV,代码行数:101,代码来源:TVideoPreviewView.cpp
示例18: TRACE_ALWAYS
status_t
AX88772Device::_SetupAX88772()
{
size_t actualLength = 0;
// enable GPIO2 - magic from FreeBSD's if_axe
uint16 GPIOs = GPIO_OO_2EN | GPIO_IO_2 | GPIO
|
请发表评论