Example #1
0
status_t
device_close(void *data)
{
	struct sis_info *info;

	if (checkDeviceInfo(info = data) != B_OK)
		return EINVAL;

	info->cookieMagic = SiS_FREE_COOKIE_MAGIC;

	// cancel timer
	cancel_timer(&info->timer);

	// remove & disable interrupt
	sis900_disableInterrupts(info);
	remove_io_interrupt_handler(info->pciInfo->u.h0.interrupt_line, sis900_interrupt, info);

	// disable the transmitter's and receiver's state machine
	write32(info->registers + SiS900_MAC_COMMAND,
		SiS900_MAC_CMD_Rx_DISABLE | SiS900_MAC_CMD_Tx_DISABLE);

	delete_sem(info->rxSem);
	delete_sem(info->txSem);

#ifdef EXCESSIVE_DEBUG
	delete_sem(gIOLock);
#endif

	return B_OK;
}
Example #2
0
static apr_status_t _thread_rw_cleanup(void * data)
{
    apr_thread_rwlock_t *mutex = (apr_thread_rwlock_t*)data;

    if (mutex->ReadCount != 0) {
    	while (atomic_add(&mutex->ReadCount , -1) > 1){
            release_sem (mutex->Read);
    	}
    }
    if (mutex->WriteCount != 0) {
    	while (atomic_add(&mutex->WriteCount , -1) > 1){
            release_sem (mutex->Write);
    	}
    }
    if (mutex->LockCount != 0) {
    	while (atomic_add(&mutex->LockCount , -1) > 1){
            release_sem (mutex->Lock);
    	}
    }
    
    delete_sem(mutex->Read);
    delete_sem(mutex->Write);
    delete_sem(mutex->Lock);
    return APR_SUCCESS;
}    
Example #3
0
void
MediaView::Reset()
{
	delete_sem(fPlaySem);
	fPlaySem = B_ERROR;

	delete_sem(fScrubSem);
	fScrubSem = B_ERROR;

	status_t result = B_NO_ERROR;
	wait_for_thread(fPlayerThread, &result);
	fPlayerThread = B_ERROR;

	fVideoTrack = NULL;

	fAudioTrack = NULL;

	delete (fAudioOutput);
	fAudioOutput = NULL;

	delete (fBitmap);
	fBitmap = NULL;

	delete (fMediaFile);
	fMediaFile = NULL;

	free(fAudioDumpingBuffer);
	fAudioDumpingBuffer = NULL;
}
Example #4
0
void
BDirectWindow::_DisposeData()
{
	// wait until the connection terminates: we can't destroy
	// the object until the client receives the B_DIRECT_STOP
	// notification, or bad things will happen
	while (fConnectionEnable)
		snooze(50000);

	_LockDirect();

	if (fInitStatus & DW_STATUS_THREAD_STARTED) {
		fDaemonKiller = true;
		// delete this sem, otherwise the Direct daemon thread
		// will wait forever on it
		delete_sem(fDisableSem);
		status_t retVal;
		wait_for_thread(fDirectDaemonId, &retVal);
	}

#if DW_NEEDS_LOCKING
	if (fInitStatus & DW_STATUS_SEM_CREATED)
		delete_sem(fDirectSem);
#endif

	if (fInitStatus & DW_STATUS_AREA_CLONED)
		delete_area(fClonedClippingArea);
}
Example #5
0
// destructor
NetFSServer::~NetFSServer()
{
	fTerminating = true;
	// stop the connection listener
	if (fConnectionListener)
		fConnectionListener->StopListening();
	if (fConnectionListenerThread >= 0) {
		int32 result;
		wait_for_thread(fConnectionListenerThread, &result);
	}
	delete fConnectionListener;

	// delete the broadcaster semaphore
	if (fBroadcasterSemaphore >= 0)
		delete_sem(fBroadcasterSemaphore);

	// terminate the broadcaster
	if (fBroadcaster >= 0) {
		safe_closesocket(fBroadcastingSocket);

		// interrupt the thread in case it is currently snoozing
		suspend_thread(fBroadcaster);
		int32 result;
		wait_for_thread(fBroadcaster, &result);
	}

	// terminate the server info connection listener
	_ExitServerInfoConnectionListener();

	// terminate the connection deleter
	if (fClosedConnectionsSemaphore >= 0)
		delete_sem(fClosedConnectionsSemaphore);
	if (fConnectionDeleter >= 0) {
		int32 result;
		wait_for_thread(fConnectionDeleter, &result);
	}

	// blow away all remaining connections
	AutoLocker<Locker> _(fLock);
	// open connections
	for (int32 i = 0;
		 ClientConnection* connection
		 	= (ClientConnection*)fClientConnections.ItemAt(i);
		 i++) {
		connection->Close();
		delete connection;
	}

	// closed connections
	for (int32 i = 0;
		 ClientConnection* connection
		 	= (ClientConnection*)fClosedConnections.ItemAt(i);
		 i++) {
		delete connection;
	}
	VolumeManager::DeleteDefault();
	FDManager::DeleteDefault();
	delete fSecurityContext;
}
Example #6
0
// destructor
RWLocker::~RWLocker()
{
	fLock.Lock();
	delete_sem(fMutex.semaphore);
	delete_sem(fQueue.semaphore);
	for (int32 i = 0; ReadLockInfo* info = _ReadLockInfoAt(i); i++)
		delete info;
}
Example #7
0
void
LegacyAudioConsumer::HandleStart( bigtime_t performance_time )
{
	if ( mRunning ) {
		return;
	}

	mPerformanceTimeBase = performance_time;

	//allocate buffer available semaphore
	mBuffer_avail = create_sem( 0, "legacy audio out buffer avail" );

	if ( mBuffer_avail < B_OK ) {
		goto init_err1;
	}

	//allocate buffer free semaphore
	mBuffer_free = create_sem( 1, "legacy audio out buffer free" );
	
	if ( mBuffer_free < B_OK ) {
		goto init_err2;
	}

	//allocate output completion semaphore
	mBuffer_waitIO = create_sem( 1, "legacy audio out waitIO" );

	if ( mBuffer_waitIO < B_OK ) {
		goto init_err3;
	}

	//tell the driver about the playback completion semaphore
	DRIVER_SET_PLAYBACK_COMPLETION_SEM( &mBuffer_waitIO, 0 );

	mThread = spawn_thread( _run_thread_, "legacy audio output", B_REAL_TIME_PRIORITY, this );

	if ( mThread < B_OK ) {
		goto init_err4;
	}

	io_buf = io_buf1;

	resume_thread( mThread );

	mRunning = true;
	return;

init_err4:
	delete_sem( mBuffer_waitIO );

init_err3:
	delete_sem( mBuffer_free );

init_err2:
	delete_sem( mBuffer_avail );

init_err1:
	return;
}
Example #8
0
DirectWindowInfo::~DirectWindowInfo()
{
	// this should make the client die in case it's still running
	fBufferInfo->bits = NULL;
	fBufferInfo->bytes_per_row = 0;

	delete_area(fBufferArea);
	delete_sem(fSem);
	delete_sem(fAcknowledgeSem);
}
Example #9
0
void closeManagedData(bt_managed_data *data)
{
	data->readCount = data->writeCount = 0;

	delete_sem(data->writer);
	delete_sem(data->reader);
	delete_sem(data->readerQueue);
	delete_sem(data->writeCountSem);
	delete_sem(data->readCountSem);
}
Example #10
0
WorkQueue::~WorkQueue()
{
	release_sem(fThreadCancel);

	status_t result;
	wait_for_thread(fThread, &result);

	mutex_destroy(&fQueueLock);
	delete_sem(fThreadCancel);
	delete_sem(fQueueSemaphore);
}
Example #11
0
void
usb_disk_free_device_and_luns(disk_device *device)
{
	mutex_lock(&device->lock);
	mutex_destroy(&device->lock);
	delete_sem(device->notify);
	delete_sem(device->interruptLock);
	for (uint8 i = 0; i < device->lun_count; i++)
		free(device->luns[i]);
	free(device->luns);
	free(device);
}
Example #12
0
SerialDevice::~SerialDevice()
{
	Removed();

	if (fDoneRead >= 0)
		delete_sem(fDoneRead);
	if (fDoneWrite >= 0)
		delete_sem(fDoneWrite);

	if (fBufferArea >= 0)
		delete_area(fBufferArea);
}
Example #13
0
status_t
hpet_open(const char* name, uint32 flags, void** cookie)
{
	*cookie = NULL;

	if (sHPETRegs == NULL)
		return B_NO_INIT;

	if (atomic_add(&sOpenCount, 1) != 0) {
		atomic_add(&sOpenCount, -1);
		return B_BUSY;
	}

	int timerNumber = 2;
		// TODO

	char semName[B_OS_NAME_LENGTH];
	snprintf(semName, B_OS_NAME_LENGTH, "hpet_timer %d sem", timerNumber);
	sem_id sem = create_sem(0, semName);
	if (sem < 0) {
		atomic_add(&sOpenCount, -1);
		return sem;
	}

	hpet_timer_cookie* hpetCookie = (hpet_timer_cookie*)malloc(sizeof(hpet_timer_cookie));
	if (hpetCookie == NULL) {
		delete_sem(sem);
		atomic_add(&sOpenCount, -1);
		return B_NO_MEMORY;
	}

	hpetCookie->number = timerNumber;
	hpetCookie->timer = &sHPETRegs->timer[timerNumber];
	hpetCookie->sem = sem;
	set_sem_owner(hpetCookie->sem, B_SYSTEM_TEAM);

	hpet_set_enabled(false);

	status_t status = hpet_init_timer(hpetCookie);
	if (status != B_OK)
		dprintf("hpet_open: initializing timer failed: %s\n", strerror(status));

	hpet_set_enabled(true);

	*cookie = hpetCookie;

	if (status != B_OK) {
		delete_sem(sem);
		free(hpetCookie);
		atomic_add(&sOpenCount, -1);
	}
	return status;
}
Example #14
0
DavicomDevice::~DavicomDevice()
{
	if (fNotifyReadSem >= B_OK)
		delete_sem(fNotifyReadSem);
	if (fNotifyWriteSem >= B_OK)
		delete_sem(fNotifyWriteSem);
	
	if (!fRemoved) //???
		gUSBModule->cancel_queued_transfers(fNotifyEndpoint);

	if(fNotifyBuffer)
		free(fNotifyBuffer);
}
Example #15
0
    PR_DestroyCondVar (PRCondVar *cvar)
{
    status_t result = delete_sem( cvar->sem );
    PR_ASSERT( result == B_NO_ERROR );
    
    result = delete_sem( cvar->handshakeSem );
    PR_ASSERT( result == B_NO_ERROR );

    result = delete_sem( cvar->signalSem );
    PR_ASSERT( result == B_NO_ERROR );

    PR_DELETE( cvar );
}
Example #16
0
void
remove_device(pegasus_dev *device)
{
	ASSERT(device != NULL);

	delete_sem(device->rx_sem);
	delete_sem(device->tx_sem);
	delete_sem(device->rx_sem_cb);
	delete_sem(device->tx_sem_cb);

	delete_sem(device->sem_lock);

	free(device);
}
Example #17
0
void
LegacyAudioConsumer::HandleStop()
{
	if ( ! mRunning ) {
		return;
	}

	delete_sem( mBuffer_avail );
	delete_sem( mBuffer_free );
	delete_sem( mBuffer_waitIO );
	wait_for_thread( mThread, &mThread );

	mRunning = false;
}
Example #18
0
SerialDevice::~SerialDevice()
{
	Removed();

	if (fDoneRead >= B_OK)
		delete_sem(fDoneRead);
	if (fDoneWrite >= B_OK)
		delete_sem(fDoneWrite);

	if (fBufferArea >= B_OK)
		delete_area(fBufferArea);

	mutex_destroy(&fReadLock);
	mutex_destroy(&fWriteLock);
}
Example #19
0
extern "C" int be_mouse_init(void)
{
   sem_id mouse_started;
   int32  num_buttons;

   mouse_started = create_sem(0, "starting mouse driver...");

   if (mouse_started < 0) {
      goto cleanup;
   }

   mouse_thread_id = spawn_thread(mouse_thread, MOUSE_THREAD_NAME,
                        MOUSE_THREAD_PRIORITY, &mouse_started); 

   if (mouse_thread_id < 0) {
      goto cleanup;
   }

   mouse_thread_running = true;
   resume_thread(mouse_thread_id);
   acquire_sem(mouse_started);
   delete_sem(mouse_started);

   be_mickey_x = 0;
   be_mickey_y = 0;

   be_mouse_x = 0;
   be_mouse_y = 0;
   be_mouse_b = 0;

   limit_up     = 0;
   limit_down   = 0;
   limit_left   = 0;
   limit_right  = 0;

   get_mouse_type(&num_buttons);

   return num_buttons;

   cleanup: {
      if (mouse_started > 0) {
         delete_sem(mouse_started);
      }

      be_mouse_exit();
      return 0;
   }
}
Example #20
0
CreateParamsPanel::~CreateParamsPanel()
{
	RemoveCommonFilter(fEscapeFilter);
	delete fEscapeFilter;

	delete_sem(fExitSemaphore);
}
Example #21
0
// _HandleStart
void
VideoProducer::_HandleStart(bigtime_t performance_time)
{
	// Start producing frames, even if the output hasn't been connected yet.
	PRINTF(1, ("_HandleStart(%Ld)\n", performance_time));

	if (fRunning) {
		PRINTF(-1, ("_HandleStart: Node already started\n"));
		return;
	}

	fFrame = 0;
	fFrameBase = 0;
	fPerformanceTimeBase = performance_time;

	fFrameSync = create_sem(0, "frame synchronization");
	if (fFrameSync < B_OK)
		goto err1;

	fThread = spawn_thread(_frame_generator_, "frame generator",
			B_NORMAL_PRIORITY, this);
	if (fThread < B_OK)
		goto err2;

	resume_thread(fThread);

	fRunning = true;
	return;

err2:
	delete_sem(fFrameSync);
err1:
	return;
}
Example #22
0
static status_t
std_ops(int32 op, ...)
{
	if (op == B_MODULE_INIT) {
		sRequestSem = create_sem(0, "run_on_exit_request");
		if (sRequestSem < B_OK)
			return sRequestSem;

		thread_id thread = spawn_kernel_thread(&run_on_exit_loop,
			"run_on_exit_loop", B_NORMAL_PRIORITY, NULL);
		if (thread < B_OK)
			return thread;

		send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE);

		add_debugger_command_etc("on_exit", &add_run_on_exit_command,
			"Adds a command to be run when leaving the kernel debugger",
			"<command> [<arguments>]\n"
			"Adds a command to be run when leaving the kernel debugger.\n", 0);

		return B_OK;
	} else if (op == B_MODULE_UNINIT) {
		remove_debugger_command("on_exit", &add_run_on_exit_command);
		// deleting the sem will also cause the thread to exit
		delete_sem(sRequestSem);
		sRequestSem = -1;
		return B_OK;
	}

	return B_BAD_VALUE;
}
Example #23
0
QueueActions::~QueueActions(){
	if(Lock()){
		suspend_thread(fID);
		exit_thread(fID);
		delete_sem(fLock);
	}
}
Example #24
0
static status_t
createSemaphores(struct sis_info *info)
{
	if ((info->rxSem = create_sem(0, "sis900 receive")) < B_OK)
		return info->rxSem;

	set_sem_owner(info->rxSem, B_SYSTEM_TEAM);

	if ((info->txSem = create_sem(NUM_Tx_DESCR, "sis900 transmit")) < B_OK)
	{
		delete_sem(info->rxSem);
		return info->txSem;
	}
	set_sem_owner(info->txSem, B_SYSTEM_TEAM);

#ifdef EXCESSIVE_DEBUG
	if ((gIOLock = create_sem(1, "sis900 debug i/o lock")) < B_OK)
		return gIOLock;
	set_sem_owner(gIOLock, B_SYSTEM_TEAM);
#endif

	info->rxLock = info->txLock = 0;
	
	return B_OK;
}
Example #25
0
/* be_time_init:
 */
extern "C" int be_time_init(void)
{
   sem_id timer_started;

   timer_started = create_sem(0, "starting timer driver...");

   if(timer_started < 0) {
      goto cleanup;
   }

   timer_thread_id = spawn_thread(timer_thread, "timer driver",
                        TIMER_THREAD_PRIORITY, &timer_started);

   if(timer_thread_id < 0) {
      goto cleanup;
   }

   timer_thread_running = true;
   resume_thread(timer_thread_id);

   return 0;

   cleanup: {
      if (timer_started > 0) {
         delete_sem(timer_started);
      }

      be_time_exit();
      return 1;
   }
}
Example #26
0
void
BAlert::MessageReceived(BMessage* msg)
{
	if (msg->what != kAlertButtonMsg)
		return BWindow::MessageReceived(msg);

	int32 which;
	if (msg->FindInt32("which", &which) == B_OK) {
		if (fAlertSem < B_OK) {
			// Semaphore hasn't been created; we're running asynchronous
			if (fInvoker) {
				BMessage* out = fInvoker->Message();
				if (out && (out->ReplaceInt32("which", which) == B_OK
							|| out->AddInt32("which", which) == B_OK))
					fInvoker->Invoke();
			}
			PostMessage(B_QUIT_REQUESTED);
		} else {
			// Created semaphore means were running synchronously
			fAlertValue = which;

			// TextAlertVar does release_sem() below, and then sets the
			// member var.  That doesn't make much sense to me, since we
			// want to be able to clean up at some point.  Better to just
			// nuke the semaphore now; we don't need it any more and this
			// lets synchronous Go() continue just as well.
			delete_sem(fAlertSem);
			fAlertSem = -1;
		}
	}
}
Example #27
0
/* Free a mutex */
TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
{
	if (mutexp) {
#ifdef TSRM_WIN32
		DeleteCriticalSection(mutexp);
		free(mutexp);
#elif defined(GNUPTH)
		free(mutexp);
#elif defined(PTHREADS)
		pthread_mutex_destroy(mutexp);
		free(mutexp);
#elif defined(NSAPI)
		crit_terminate(mutexp);
#elif defined(PI3WEB)
		PISync_delete(mutexp);
#elif defined(TSRM_ST)
		st_mutex_destroy(mutexp);
#elif defined(BETHREADS)
		delete_sem(mutexp->sem);
		free(mutexp);  
#endif
	}
#ifdef THR_DEBUG
	printf("Mutex freed thread: %d\n",mythreadid());
#endif
}
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;
}
Example #29
0
status_t
init_driver(void)
{
	int i = 0, j = 0, is_detected;
	pci_info dev_info;

	//debug_fd = open("/tmp/broadcom_traffic_log",O_RDWR | B_CREATE_FILE);

	if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci) != B_OK)
		return B_ERROR;

	while (pci->get_nth_pci_info(i++, &dev_info) == 0) {
		is_detected = 0;
		if ((dev_info.class_base == PCI_network) && (dev_info.class_sub == PCI_ethernet)) {
			for (j = 0; bcm5700_pci_tbl[j].vendor != 0; j++) {
				if ((dev_info.vendor_id == bcm5700_pci_tbl[j].vendor) && (dev_info.device_id == bcm5700_pci_tbl[j].device)) {
					is_detected = 1;
					break;
				}
			}
		}

		if (!is_detected)
			continue;

		if (cards_found >= 10)
			break;

		dev_list[cards_found] = (char *)malloc(16 /* net/bcm570x/xx */);
		sprintf(dev_list[cards_found],"net/bcm570x/%d",cards_found);
		be_b57_dev_cards[cards_found].pci_data = dev_info;
		be_b57_dev_cards[cards_found].packet_release_sem = create_sem(0,dev_list[cards_found]);
		be_b57_dev_cards[cards_found].mem_list_num = 0;
		be_b57_dev_cards[cards_found].lockmem_list_num = 0;
		be_b57_dev_cards[cards_found].opened = 0;
		be_b57_dev_cards[cards_found].block = 1;
		be_b57_dev_cards[cards_found].lock = 0;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
		be_b57_dev_cards[cards_found].linkChangeSem = -1;
#endif

		if (LM_GetAdapterInfo(&be_b57_dev_cards[cards_found].lm_dev) != LM_STATUS_SUCCESS) {
			for (j = 0; j < cards_found; j++) {
				free(dev_list[j]);
				delete_sem(be_b57_dev_cards[j].packet_release_sem);
			}
			put_module(B_PCI_MODULE_NAME);
			return ENODEV;
		}

		QQ_InitQueue(&be_b57_dev_cards[cards_found].RxPacketReadQ.Container,MAX_RX_PACKET_DESC_COUNT);

		cards_found++;
	}

 	mempool_init((MAX_RX_PACKET_DESC_COUNT+MAX_TX_PACKET_DESC_COUNT) * cards_found);
 	dev_list[cards_found] = NULL;

	return B_OK;
}
Example #30
0
void TVideoPreviewView::Disconnected( const media_source &producer, const media_destination &where)
{
	FUNCTION("TVideoPreviewView::Disconnect()\n");

	mConnected = false;

	status_t status;
	mDisplayQuit = true;
	if (vThread != 0)
		wait_for_thread(vThread, &status);
	vThread = 0;

	if (m_Bitmap != NULL) {
		delete m_Bitmap;
		m_Bitmap = NULL;
	}

	if (mBufferAvailable != 0)
		delete_sem(mBufferAvailable);
	mBufferAvailable = 0;

	while (mBufferQueue->HasBuffers()) {
		mBufferQueue->PopFirstBuffer(0)->Recycle();
	}
	delete mBufferQueue;
	mBufferQueue = 0;
}