Пример #1
0
void EMBeMediaTimer::SeekToFrame(int64 p_vNewFrame)
{
	Lock();
	
	//if(m_vIsStarted)
	//	Notify(EM_MESSAGE_PAUSE);
		
	status_t vAcquireResult = acquire_sem(m_vTimeProtectionSemaphore);
	if(vAcquireResult != B_NO_ERROR)
		EMDebugger("ERROR! EMBeMediaTimer could not acquire semaphore for timer protection!");

	if(p_vNewFrame < 0) 
		p_vNewFrame = 0;
	
	m_vNow = p_vNewFrame;
	m_vAudioThen = p_vNewFrame;
	m_vVideoThen = p_vNewFrame;
	release_sem(m_vTimeProtectionSemaphore);
	//Notify(EM_MESSAGE_TIME_SEEKED);

	//if(m_vIsStarted)
	//	Notify(EM_MESSAGE_RESUME);

	Unlock();
}
Пример #2
0
DisplayDevice_Haiku::DisplayDevice_Haiku(MilkyView* milkyView,
	pp_int32 scaleFactor)
	:
	PPDisplayDeviceBase(milkyView->Bounds().IntegerWidth(),
		milkyView->Bounds().IntegerHeight(), scaleFactor),
	fMilkyView(milkyView),
	fDirtyRegion(milkyView->DirtyRegion()),
	fBitmapRect(milkyView->Bitmap()->Bounds()),
	fBitmapLock(milkyView->BitmapLock()),
	fWaitWindow(NULL)
{
	// In general, the Tracker will hold the lock to the display buffer since
	// it could draw there anytime -- except when we block it, which we do in
	// the DisplayDevice_Haiku::update() method
	acquire_sem(fBitmapLock);

	PPGraphics_32bpp_generic* graphics = new PPGraphics_32bpp_generic(
		fMilkyView->Bounds().IntegerWidth(),
		fMilkyView->Bounds().IntegerHeight(),
		fMilkyView->Bitmap()->BytesPerRow(),
		fMilkyView->Bitmap()->Bits());
	graphics->setComponentBitpositions(16, 8, 0);

	currentGraphics = graphics;

	currentGraphics->lock = true;
}
Пример #3
0
void
DisplayDevice_Haiku::update()
{
	fDirtyRegion->Include(fBitmapRect);
	release_sem(fBitmapLock);
	acquire_sem(fBitmapLock);
}
Пример #4
0
bt_usb_dev*
fetch_device(bt_usb_dev* dev, hci_id hid)
{
	int i;

//	TRACE("%s: (%p) or %d\n", __func__, dev, hid);

	acquire_sem(dev_table_sem);
	if (dev != NULL) {
		for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) {
			if (bt_usb_devices[i] == dev) {
				release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE);
				return bt_usb_devices[i];
			}
		}
	} else {
		for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) {
			if (bt_usb_devices[i] != NULL && bt_usb_devices[i]->hdev == hid) {
				release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE);
				return bt_usb_devices[i];
			}
		}
	}

	release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE);

	return NULL;
}
Пример #5
0
//*****************************************************
void IndexView::Draw(BRect rect)
{
	LockLooper();

	BRect r = Bounds();
	if (Pool.update_index && !m_resized)
		CalculateCache(Bounds());

	if (m_resized)
	{
		acquire_sem(indexSem);
		// allocate offscreen bitmap here
		if (OffScreen)	{ delete OffScreen; OffScreen = NULL; }
		OffScreen = new BBitmap(r, B_RGB32);
		release_sem(indexSem);

		// recalculate caches for resized screen
		if (CalculateCache(r))
			m_resized = false;
	}

	DrawBitmapAsync( OffScreen, rect, rect);

	if (Pool.sample_type != NONE)
	{
		float x = Pool.last_pointer * Bounds().Width() / Pool.size;
		SetDrawingMode(B_OP_INVERT);
		StrokeLine( BPoint( x, 0), BPoint( x, r.bottom-1));//, B_MIXED_COLORS);
		SetDrawingMode(B_OP_COPY);
	}
	UnlockLooper();
}
Пример #6
0
/*
  Lock a mutex.
  A return value of 0 indicates success
*/
TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
{
	TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex locked thread: %ld", tsrm_thread_id()));
#ifdef TSRM_WIN32
	EnterCriticalSection(mutexp);
	return 0;
#elif defined(GNUPTH)
	if (pth_mutex_acquire(mutexp, 0, NULL)) {
		return 0;
	}
	return -1;
#elif defined(PTHREADS)
	return pthread_mutex_lock(mutexp);
#elif defined(NSAPI)
	crit_enter(mutexp);
	return 0;
#elif defined(PI3WEB)
	return PISync_lock(mutexp);
#elif defined(TSRM_ST)
	return st_mutex_lock(mutexp);
#elif defined(BETHREADS)
	if (atomic_add(&mutexp->ben, 1) != 0)
		return acquire_sem(mutexp->sem);
	return 0;
#endif
}
Пример #7
0
/* static */
status_t SerialApp::PollSerial(void*)
{
	SerialApp* application = (SerialApp*)be_app;
	char buffer[256];

	for(;;)
	{
		ssize_t bytesRead;

		bytesRead = application->fSerialPort.Read(buffer, sizeof(buffer));
		if (bytesRead == B_FILE_ERROR)
		{
			// Port is not open - wait for it and start over
			acquire_sem(application->fSerialLock);
		} else if (bytesRead > 0) {
			// We read something, forward it to the app for handling
			BMessage* serialData = new BMessage(kMsgDataRead);
			serialData->AddData("data", B_RAW_TYPE, buffer, bytesRead);
			be_app_messenger.SendMessage(serialData);
		}
	}
	
	// Should not reach this line anyway...
	return B_OK;
}
Пример #8
0
status_t
pc_serial_insert_device(SerialDevice *device)
{
	status_t status = B_OK;

	//XXX fix leaks!
	acquire_sem(gDriverLock);
	for (int32 i = 0; i < DEVICES_COUNT; i++) {
		if (gSerialDevices[i] != NULL)
			continue;

		status = device->Init();
		if (status < B_OK) {
			delete device;
			//return status;
			break;
		}

		gSerialDevices[i] = device;

		release_sem(gDriverLock);
		TRACE_ALWAYS("%s added\n", device->Description());
		return B_OK;
	}

	release_sem(gDriverLock);
	return B_ERROR;
}
Пример #9
0
void 
StatusWindow::WaitForClose()
{
	fCloseSem = create_sem(0, "close_sem");
	
	Lock();
		Report* r = Report::Instance();
		char b[80];
		sprintf(b, "%d Infos, %d Warnings, %d Errors", r->Count(kInfo),
			r->Count(kWarning), r->Count(kError)); 
		fPageLabel->SetText(b);
		fCancel->SetLabel("Close");
		fCancel->SetEnabled(true);
		UpdateReport();
		
		bool hasErrors = r->Count(kError);
		bool hasErrorsOrWarnings = hasErrors || r->Count(kWarning);
		bool hasErrorsWarningsOrInfo = hasErrorsOrWarnings || r->Count(kInfo);
		
		if (fCloseOption == kAlways
			|| (fCloseOption == kNoErrors && !hasErrors)
			|| (fCloseOption == kNoErrorsOrWarnings && !hasErrorsOrWarnings)
			|| (fCloseOption == kNoErrorsWarningsOrInfo 
			&& !hasErrorsWarningsOrInfo)) {
			PostMessage(kCancelMsg);
		}
	Unlock();
	
	acquire_sem(fCloseSem);
	delete_sem(fCloseSem);
}
Пример #10
0
bool BeOS_monitor_desc::video_open() {
	// Create semaphore
	mac_os_lock = create_sem(0, "MacOS Frame Buffer Lock");

	const video_mode &mode = get_current_mode();

	// Open display
	switch (display_type) {
		case DISPLAY_WINDOW:
			the_window = new MacWindow(BRect(0, 0, mode.x-1, mode.y-1), *this);
			break;
		case DISPLAY_SCREEN: {
			status_t screen_error;
			the_screen = new MacScreen(*this, GetString(STR_WINDOW_TITLE), scr_mode_bit & 0x1f, &screen_error);
			if (screen_error != B_NO_ERROR) {
				the_screen->PostMessage(B_QUIT_REQUESTED);
				while (the_screen)
					snooze(200000);
				ErrorAlert(STR_OPEN_SCREEN_ERR);
				return false;
			} else {
				the_screen->Show();
				acquire_sem(mac_os_lock);
			}
			break;
		}
	}
	return true;
}
Пример #11
0
void stub_source_exit(je_source_plugin *cookie)
{
	source_private *data = (source_private *)cookie->data;
	data->exit = true;
	// block
	acquire_sem(data->exitSem);
}
Пример #12
0
bool
RingBuffer::Lock()
{
	//status_t status = acquire_sem_etc(fLock, 1, B_CAN_INTERRUPT, 0);
	status_t status = acquire_sem(fLock);
	return status == B_OK;
}
Пример #13
0
void
beos_before_backend_startup(void)
{
	/* Just before forking, acquire the semaphore */
	if (acquire_sem(beos_shm_sem) != B_OK)
		exit(1);				/* Fatal error, exiting with error */
}
Пример #14
0
status_t
usb_serial_device_removed(void *cookie)
{
	TRACE_FUNCALLS("> usb_serial_device_removed(0x%08x)\n", cookie);

	acquire_sem(gDriverLock);

	SerialDevice *device = (SerialDevice *)cookie;
	for (int32 i = 0; i < DEVICES_COUNT; i++) {
		if (gSerialDevices[i] == device) {
			if (device->IsOpen()) {
				// the device will be deleted upon being freed
				device->Removed();
			} else {
				delete device;
				gSerialDevices[i] = NULL;
			}
			break;
		}
	}

	release_sem(gDriverLock);
	TRACE_FUNCRET("< usb_serial_device_removed() returns\n");
	return B_OK;
}
Пример #15
0
int
start_thr(void (*fn)(void *), void *data, unsigned char *name)
{
	struct active_thread *thrd;
	int tid;

	if (!thr_sem_init) {
		thr_sem = create_sem(0, "thread_sem");
		if (thr_sem < B_NO_ERROR) return -1;
		thr_sem_init = 1;
	} else if (acquire_sem(thr_sem) < B_NO_ERROR) return -1;

	thrd = malloc(sizeof(*thrd));
	if (!thrd) goto rel;
	thrd->fn = fn;
	thrd->data = data;
	thrd->tid = spawn_thread(started_thr, name, B_NORMAL_PRIORITY, thrd);
	tid = thrd->tid;

	if (tid < B_NO_ERROR) {
		free(thrd);

rel:
		release_sem(thr_sem);
		return -1;
	}

	resume_thread(thrd->tid);
	add_to_list(active_threads, thrd);
	release_sem(thr_sem);

	return tid;
}
Пример #16
0
void Events::wait_for_coming() {
  acquire_sem(wait_);
  waiting_thread_ = find_thread(NULL);
  suspend_thread(waiting_thread_);
  waiting_thread_ = -1;
  release_sem(wait_);
}
Пример #17
0
AppRunner::AppRunner()
{
    if (be_app)
	return;

    sem_id initsem = create_sem(0, "Cairo BApplication init");
    if (initsem < B_OK) {
	fprintf (stderr, "Error creating BeOS initialization semaphore\n");
	return;
    }

    thread_id tid = spawn_thread(nsBeOSApp::Main, "Cairo/BeOS test", B_NORMAL_PRIORITY, (void *)initsem);
    if (tid < B_OK || B_OK != resume_thread(tid)) {
	fprintf (stderr, "Error spawning thread\n");
	return;
    }

    if (B_OK != acquire_sem(initsem)) {
	fprintf (stderr, "Error acquiring semaphore\n");
	return;
    }

    delete_sem(initsem);
    return;
}
Пример #18
0
static status_t usb_vision_open (const char *name, uint32 flags, void** cookie)
{
  int i;
  status_t status = ENODEV;
  TRACE_FUNCALLS("usb_vision_open:%s flags:%d cookie:%08x\n", name, flags, cookie);
  
  for(i = 0; i < DEVICES_COUNT; i++)
    TRACE("%08x\n", usb_vision_devices[i]);
  
  *cookie = NULL;
  i = strtol(name + BASENAME_LEN, NULL, 10);
  if(i >= 0 && i < DEVICES_COUNT){
    acquire_sem(usb_vision_lock);
    if(usb_vision_devices[i]){
      if(atomic_add(&usb_vision_devices[i]->open_count, 1) == 0){
        *cookie = usb_vision_devices[i];
        TRACE("cookie in open:%08x\n", *cookie);
        status = B_OK;
      }else{
        atomic_add(&usb_vision_devices[i]->open_count, -1);
        status = B_BUSY;
      }
    }
    release_sem(usb_vision_lock);
  }

  TRACE_FUNCRET("usb_vision_open returns:%08x\n", status);
  return status;
}
Пример #19
0
int mm_core_lock(const void *core, mm_lock_mode mode)
{
    mem_core *mc;
    int rc = 0;
    int fdsem;

    if (core == NULL)
        return FALSE;
    mc = (mem_core *)((char *)core-SIZEOF_mem_core);
#if !defined(MM_SEMT_FLOCK)
    fdsem = mc->mc_fdsem;
#endif
#if defined(MM_SEMT_FLOCK)
    fdsem = mm_core_getfdsem(mc);
#endif

#if defined(MM_SEMT_FCNTL)
    if (mode == MM_LOCK_RD)
        while (((rc = fcntl(fdsem, F_SETLKW, &mm_core_dolock_rd)) < 0) && (errno == EINTR)) ;
    else
        while (((rc = fcntl(fdsem, F_SETLKW, &mm_core_dolock_rw)) < 0) && (errno == EINTR)) ;
#endif
#if defined(MM_SEMT_FLOCK)
    if (mode == MM_LOCK_RD)
        while (((rc = flock(fdsem, LOCK_SH)) < 0) && (errno == EINTR)) ;
    else
        while (((rc = flock(fdsem, LOCK_EX)) < 0) && (errno == EINTR)) ;
#endif
#if defined(MM_SEMT_IPCSEM)
    if (mode == MM_LOCK_RD) {
        while (((rc = semop(mc->mc_fdsem_rd, mm_core_dolock, 2)) < 0) && (errno == EINTR)) ;
        mc->mc_readers++;
        if (mc->mc_readers == 1)
            while (((rc = semop(fdsem, mm_core_dolock, 2)) < 0) && (errno == EINTR)) ;
        while (((rc = semop(mc->mc_fdsem_rd, mm_core_dounlock, 1)) < 0) && (errno == EINTR)) ;
    }
    else {
        while (((rc = semop(fdsem, mm_core_dolock, 2)) < 0) && (errno == EINTR)) ;
    }
    mc->mc_lockmode = mode;
#endif
#if defined(MM_SEMT_BEOS)
    rc = 0;
    if (atomic_add(&mc->mc_ben, 1) > 0) {
        /* someone already in lock... acquire sem and wait */
        if (acquire_sem(mc->mc_semid) != B_NO_ERROR) {
            atomic_add(&mc->mc_ben, -1);
            rc = -1;
        }
    }
#endif

    if (rc < 0) {
        ERR(MM_ERR_CORE|MM_ERR_SYSTEM, "Failed to lock");
        rc = FALSE;
    }
    else
        rc = TRUE;
    return rc;
}
Пример #20
0
// 受信スレッド関数
int32 TFTPClient::ReceiverThread(void *self)
{
	TFTPClient *Self = (TFTPClient *)self;
	int32 recvSize;
	char recvBuff[1024];
	
	while(!Self->fAbort) {
		recvSize = read(Self->fControlEndpoint, recvBuff, sizeof(recvBuff));
		if (recvSize < 0) {
			// 受信データが無い or エラー
			int e = errno;
			if (e != EAGAIN) {
				// エラー
				Self->fStrError.SetTo(strerror(e));
				Self->fStatus = EPIPE;
			}
		} else if (recvSize == 0) {
			// 切断された
			Self->fStrError.SetTo("Disconnected by remote host.");
			Self->fStatus = EPIPE;
		} else {
			// 受信あり
			acquire_sem(Self->fSemID);
			Self->fReplyBuff->AddStream(recvBuff, recvSize);
			release_sem(Self->fSemID);
		}
		snooze(10000);
	}
	return 0;
}
Пример #21
0
bool 
Resource::Lock() {
	if (fResourceAvailable > 0) {
		return acquire_sem(fResourceAvailable) == B_NO_ERROR;
	}
	return true;
}
Пример #22
0
void
InstallerWindow::_QuitCopyEngine(bool askUser)
{
	if (fCopyEngineCancelSemaphore < 0)
		return;

	// First of all block the copy engine, so that it doesn't continue
	// while the alert is showing, which would be irritating.
	acquire_sem(fCopyEngineCancelSemaphore);
	
	bool quit = true;
	if (askUser) {
		quit = (new BAlert("cancel",
			TR("Are you sure you want to to stop the installation?"),
			TR_CMT("Continue", "In alert after pressing Stop"),
			TR_CMT("Stop", "In alert after pressing Stop"), 0,
			B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0;
	}

	if (quit) {
		// Make it quit by having it's lock fail...
		_SetCopyEngineCancelSemaphore(-1, true);
	} else
		release_sem(fCopyEngineCancelSemaphore);
}
Пример #23
0
void nsFilePanelBeOS::WaitForSelection()
{
	if (wait_sem > 0) {
		acquire_sem(wait_sem);
		release_sem(wait_sem);
	}
}
Пример #24
0
static status_t
b57_read(void *cookie,off_t pos,void *data,size_t *numBytes)
{
	struct be_b57_dev *pUmDevice = (struct be_b57_dev *)cookie;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	PLM_PACKET pPacket;
	struct B_UM_PACKET *pUmPacket;
	cpu_status cpu;

	if (pUmDevice->block)
		acquire_sem(pUmDevice->packet_release_sem);
	else {
		/* Decrement the receive sem anyway, but don't block
		   this is a horrible hack, but it works. */
		acquire_sem_etc(pUmDevice->packet_release_sem, 1, B_RELATIVE_TIMEOUT, 0);
	}

	cpu = disable_interrupts();
	acquire_spinlock(&pUmDevice->lock);

	pPacket = (PLM_PACKET)
		QQ_PopHead(&pUmDevice->RxPacketReadQ.Container);

	release_spinlock(&pUmDevice->lock);
	restore_interrupts(cpu);

	if (pPacket == 0) {
		*numBytes = -1;
		return B_ERROR;
	}

	pUmPacket = (struct B_UM_PACKET *) pPacket;
	if (pPacket->PacketStatus != LM_STATUS_SUCCESS
		|| pPacket->PacketSize > 1518) {
		cpu = disable_interrupts();
		acquire_spinlock(&pUmDevice->lock);

		QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);

		release_spinlock(&pUmDevice->lock);
		restore_interrupts(cpu);
		*numBytes = -1;
		return B_ERROR;
	}

	if ((pPacket->PacketSize) < *numBytes)
		*numBytes = pPacket->PacketSize;

	memcpy(data,pUmPacket->data,*numBytes);
	cpu = disable_interrupts();
	acquire_spinlock(&pUmDevice->lock);

	QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);

	release_spinlock(&pUmDevice->lock);
	restore_interrupts(cpu);

	return B_OK;
}
Пример #25
0
/*	===== tls_entry_exit_mutex_p ===================================================
	PRIVATE. Take the mutex.
	================================================================================	*/
status_t tls_entry_exit_mutex_p () 
	{
	int32 previous = atomic_add (&gm_mutex_entry_exit_val, 1); 
	if (previous >= 1) 
		return acquire_sem (gm_mutex_entry_exit) ;
	else
		return B_NO_ERROR ;
	}
Пример #26
0
static apr_status_t do_wait(apr_thread_cond_t *cond, apr_thread_mutex_t *mutex,
                            apr_interval_time_t timeout)
{
    struct waiter_t *wait;
    thread_id cth = find_thread(NULL);
    apr_status_t rv;
    int flags = B_RELATIVE_TIMEOUT;
    
    /* We must be the owner of the mutex or we can't do this... */    
    if (mutex->owner != cth) {
        /* What should we return??? */
        return APR_EINVAL;
    }

    acquire_sem(cond->lock);
    wait = APR_RING_FIRST(&cond->flist);
    if (wait)
        APR_RING_REMOVE(wait, link);
    else
        wait = make_waiter(cond->pool);   
    APR_RING_INSERT_TAIL(&cond->alist, wait, waiter_t, link);
    cond->condlock = mutex;
    release_sem(cond->lock);
       
    apr_thread_mutex_unlock(cond->condlock);

    if (timeout == 0)
        flags = 0;
        
    rv = acquire_sem_etc(wait->sem, 1, flags, timeout);

    apr_thread_mutex_lock(cond->condlock);
    
    if (rv != B_OK) {
        if (rv == B_TIMED_OUT)
            return APR_TIMEUP;
        return rv;       
    }

    acquire_sem(cond->lock);
    APR_RING_REMOVE(wait, link);
    APR_RING_INSERT_TAIL(&cond->flist, wait, waiter_t, link);
    release_sem(cond->lock);
    
    return APR_SUCCESS;
}
Пример #27
0
bool	
QueueActions::Lock(){ 
	status_t value = acquire_sem(fLock) ;
	if(value==B_NO_ERROR){
		fLocked = true;
	}
	return (value == B_NO_ERROR);
}
Пример #28
0
    PR_WaitSem (PRSemaphore *sem)
{
	PR_ASSERT(sem != NULL);
	if (acquire_sem(sem->sem) == B_NO_ERROR)
		return PR_SUCCESS;
	else
		return PR_FAILURE;
}
Пример #29
0
static status_t
buffer_exchange(device_t* device, multi_buffer_info* buffer_info)
{
	//dprintf("null_audio: %s\n" , __func__ );
	static int debug_buffers_exchanged = 0;
	cpu_status status;
	status_t result;

	// On first call, we start our fake hardware.
	// Usually one would jump into his interrupt handler now
	if (!device->running)
		null_start_hardware(device);

	result = acquire_sem(device->playback_stream.buffer_ready_sem);
	if (result != B_OK) {
		dprintf("null_audio: %s, Could not get playback buffer\n", __func__);
		return result;
	}

	result = acquire_sem(device->record_stream.buffer_ready_sem);
	if (result != B_OK) {
		dprintf("null_audio: %s, Could not get record buffer\n", __func__);
		return result;
	}

	status = disable_interrupts();
	acquire_spinlock(&device->playback_stream.lock);

	buffer_info->playback_buffer_cycle = device->playback_stream.buffer_cycle;
	buffer_info->played_real_time = device->playback_stream.real_time;
	buffer_info->played_frames_count = device->playback_stream.frames_count;

	buffer_info->record_buffer_cycle = device->record_stream.buffer_cycle;
	buffer_info->recorded_real_time = device->record_stream.real_time;
	buffer_info->recorded_frames_count = device->record_stream.frames_count;

	release_spinlock(&device->playback_stream.lock);
	restore_interrupts(status);

	debug_buffers_exchanged++;
	if (((debug_buffers_exchanged % 5000) == 0) ) { //&& debug_buffers_exchanged < 1111) {
		dprintf("null_audio: %s: %d buffers processed\n", __func__, debug_buffers_exchanged);
	}

	return B_OK;
}
Пример #30
0
WRes Event_Wait(CEvent *p) {
  acquire_sem(p->_sem);
  while (p->_state == FALSE)
  {
    thread_id sender; 
    p->_waiting[p->_index_waiting++] = find_thread(NULL);
    release_sem(p->_sem);
    /* int msg = */ receive_data(&sender, NULL, 0);
    acquire_sem(p->_sem);
  }
  if (p->_manual_reset == FALSE)
  {
     p->_state = FALSE;
  }
  release_sem(p->_sem);
  return 0;
}