AudioOutput::AudioOutput(BMediaTrack *new_track, const char *name) {
	media_format	format;

	lock_count = 0;
	lock_sem = create_sem(0, "audio_output ben");
	track = new_track;
	isPlaying = false;
	perfTime = -1;
	perfTime = -1;
	trackTime = 0;
	
	track->DecodedFormat(&format);
	switch (format.u.raw_audio.format) {
	case media_raw_audio_format::B_AUDIO_UCHAR :
		default_data = 0x80;
		frame_size = 1;
		break;
	case media_raw_audio_format::B_AUDIO_SHORT :
		default_data = 0;
		frame_size = 2;
		break;
	case media_raw_audio_format::B_AUDIO_INT :
		default_data = 0;
		frame_size = 4;
		break;
	case media_raw_audio_format::B_AUDIO_FLOAT :
		default_data = 0;
		frame_size = 4;
		break;
	default :
		player = NULL;
		return;
	}
	channelCount = format.u.raw_audio.channel_count;
	frame_size *= channelCount;
	buffer_size = format.u.raw_audio.buffer_size;
	frame_rate = format.u.raw_audio.frame_rate;

	player = new BSoundPlayer(&format.u.raw_audio, name, AudioPlay);
	if (player->InitCheck() != B_OK) {
		delete player;
		player = NULL;
	} else {
		player->SetCookie(this);
		player->Start();
		player->SetHasData(true);
	}
}
Example #2
0
static status_t
keyboard_open(const char *name, uint32 flags, void **_cookie)
{
	status_t status;

	TRACE("ps2: keyboard_open %s\n", name);

	if (atomic_or(&sKeyboardOpenMask, 1) != 0)
		return B_BUSY;

	status = probe_keyboard();
	if (status != B_OK) {
		INFO("ps2: keyboard probing failed\n");
		ps2_service_notify_device_removed(&ps2_device[PS2_DEVICE_KEYB]);
		goto err1;
	}

	INFO("ps2: keyboard found\n");

	sKeyboardSem = create_sem(0, "keyboard_sem");
	if (sKeyboardSem < 0) {
		status = sKeyboardSem;
		goto err1;
	}

	sKeyBuffer = create_packet_buffer(KEY_BUFFER_SIZE * sizeof(at_kbd_io));
	if (sKeyBuffer == NULL) {
		status = B_NO_MEMORY;
		goto err2;
	}

	*_cookie = NULL;
	ps2_device[PS2_DEVICE_KEYB].disconnect = &ps2_keyboard_disconnect;
	ps2_device[PS2_DEVICE_KEYB].handle_int = &keyboard_handle_int;

	atomic_or(&ps2_device[PS2_DEVICE_KEYB].flags, PS2_FLAG_ENABLED);

	TRACE("ps2: keyboard_open %s success\n", name);
	return B_OK;

err2:
	delete_sem(sKeyboardSem);
err1:
	atomic_and(&sKeyboardOpenMask, 0);

	TRACE("ps2: keyboard_open %s failed\n", name);
	return status;
}
Example #3
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 #4
0
static status_t
mutex_lock(pthread_mutex_t *mutex, bigtime_t timeout)
{
	thread_id thisThread = find_thread(NULL);
	status_t status = B_OK;

	if (mutex == NULL)
		return B_BAD_VALUE;

	// If statically initialized, we need to create the semaphore, now.
	if (mutex->sem == -42) {
		sem_id sem = create_sem(0, "pthread_mutex");
		if (sem < 0)
			return EAGAIN;

		if (atomic_test_and_set((vint32*)&mutex->sem, sem, -42) != -42)
			delete_sem(sem);
	}

	if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_ERRORCHECK
		&& mutex->owner == thisThread) {
		// we detect this kind of deadlock and return an error
		return EDEADLK;
	}

	if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_RECURSIVE
		&& mutex->owner == thisThread) {
		// if we already hold the mutex, we don't need to grab it again
		mutex->owner_count++;
		return B_OK;
	}

	if (atomic_add((vint32*)&mutex->count, 1) > 0) {
		// this mutex is already locked by someone else, so we need
		// to wait
		status = acquire_sem_etc(mutex->sem, 1,
			timeout == B_INFINITE_TIMEOUT ? 0 : B_ABSOLUTE_REAL_TIME_TIMEOUT,
			timeout);
	}

	if (status == B_OK) {
		// we have locked the mutex for the first time
		mutex->owner = thisThread;
		mutex->owner_count = 1;
	}

	return status;
}
void
_MediaSlider_::MouseDown(
	BPoint	where)
{
	fOwner->fScrubTime = PointToTime(where);
	fOwner->fScrubSem = create_sem(1, "MediaView::fScrubSem");

	if (!fOwner->fPlaying) {
		release_sem(fOwner->fPlaySem);
		acquire_sem(fOwner->fPlaySem);
	}

	SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);

	fMouseDown = true;
}
Example #6
0
void
ActivityView::AttachedToWindow()
{
	if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0)
		_LoadBackgroundInfo(true);

	Looper()->AddHandler(fSystemInfoHandler);
	fSystemInfoHandler->StartWatching();

	fRefreshSem = create_sem(0, "refresh sem");
	fRefreshThread = spawn_thread(&_RefreshThread, "source refresh",
		B_URGENT_DISPLAY_PRIORITY, this);
	resume_thread(fRefreshThread);

	FrameResized(Bounds().Width(), Bounds().Height());
}
Example #7
0
void
setup_context(struct context& context, bool server)
{
	list_init(&context.list);
	context.route.interface = &gInterface;
	context.route.gateway = (sockaddr *)&context;
		// backpointer to the context
	context.route.mtu = 1500;
	context.server = server;
	context.wait_sem = create_sem(0, "receive wait");

	context.thread = spawn_thread(receiving_thread,
		server ? "server receiver" : "client receiver", B_NORMAL_PRIORITY,
		&context);
	resume_thread(context.thread);
}
status_t
CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener)
{
	fTeam = team;
	fListener = listener;

	status_t error = _RegisterCommands();
	if (error != B_OK)
		return error;

	fShowSemaphore = create_sem(0, "show CLI");
	if (fShowSemaphore < 0)
		return fShowSemaphore;

	return B_OK;
}
Example #9
0
AuthenticationPanel::AuthenticationPanel(BRect parentFrame)
	: BWindow(BRect(-1000, -1000, -900, -900), "Authentication Required",
	    B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
	    B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE
	        | B_CLOSE_ON_ESCAPE | B_AUTO_UPDATE_SIZE_LIMITS)
	, m_parentWindowFrame(parentFrame)
	, m_usernameTextControl(new BTextControl("user", "Username:", "", NULL))
	, m_passwordTextControl(new BTextControl("pass", "Password:", "", NULL))
	, m_hidePasswordCheckBox(new BCheckBox("hide", "Hide password text", new BMessage(kHidePassword)))
	, m_rememberCredentialsCheckBox(new BCheckBox("remember", "Remember username and password for this site", NULL))
	, m_okButton(new BButton("ok", "OK", new BMessage(kMsgPanelOK)))
	, m_cancelButton(new BButton("cancel", "Cancel", new BMessage(B_QUIT_REQUESTED)))
	, m_cancelled(false)
	, m_exitSemaphore(create_sem(0, "Authentication Panel"))
{
}
Example #10
0
MultiLocker::MultiLocker(const char* semaphoreBaseName)
	:	fInit(B_NO_INIT),
		fReadCount(0),
		fReadSem(-1),
		fWriteCount(0),
		fWriteSem(-1),
		fLockCount(0),
		fWriterLock(-1),
		fWriterNest(0),
		fWriterThread(-1),
		fWriterStackBase(0),
		fDebugArray(NULL),
		fMaxThreads(0)
{
	//build the semaphores
	if (semaphoreBaseName) {
		char name[128];
		sprintf(name, "%s-%s", semaphoreBaseName, "ReadSem");
		fReadSem = create_sem(0, name);
		sprintf(name, "%s-%s", semaphoreBaseName, "WriteSem");
		fWriteSem = create_sem(0, name);
		sprintf(name, "%s-%s", semaphoreBaseName, "WriterLock");
		fWriterLock = create_sem(0, name);
	} else {
		fReadSem = create_sem(0, "MultiLocker_ReadSem");
		fWriteSem = create_sem(0, "MultiLocker_WriteSem");
		fWriterLock = create_sem(0, "MultiLocker_WriterLock");
	}

	if (fReadSem >= 0 && fWriteSem >=0 && fWriterLock >= 0)
		fInit = B_OK;
		
	#if DEBUG
		//we are in debug mode!
		//create the reader tracking list
		//the array needs to be large enough to hold all possible threads
		system_info sys;
		get_system_info(&sys);
		fMaxThreads = sys.max_threads;
		fDebugArray = (int32 *) malloc(fMaxThreads * sizeof(int32));
		for (int32 i = 0; i < fMaxThreads; i++) {
			fDebugArray[i] = 0;
		}
		
	#endif
	#if TIMING
		//initialize the counter variables
		rl_count = ru_count = wl_count = wu_count = islock_count = 0;
		rl_time = ru_time = wl_time = wu_time = islock_time = 0;
		#if DEBUG
			reg_count = unreg_count = 0;
			reg_time = unreg_time = 0;
		#endif
	#endif
}
Example #11
0
status_t
RemoteDrawingEngine::_AddCallback()
{
	if (fCallbackAdded)
		return B_OK;

	if (fResultNotify < 0)
		fResultNotify = create_sem(0, "drawing engine result");
	if (fResultNotify < 0)
		return fResultNotify;

	status_t result = fHWInterface->AddCallback(fToken, &_DrawingEngineResult,
		this);

	fCallbackAdded = result == B_OK;
	return result;
}
Example #12
0
/* Create a counting semaphore */
SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
{
	SDL_sem *sem;

	sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
	if ( sem ) {
		sem->id = create_sem(initial_value, "SDL semaphore");
		if ( sem->id < B_NO_ERROR ) {
			SDL_SetError("create_sem() failed");
			SDL_free(sem);
			sem = NULL;
		}
	} else {
		SDL_OutOfMemory();
	}
	return(sem);
}
Example #13
0
status_t
DebugReportGenerator::Init()
{
	fTeamDataSem = create_sem(0, "debug_controller_data_wait");
	if (fTeamDataSem < B_OK)
		return fTeamDataSem;

	fNodeManager = new(std::nothrow) ValueNodeManager();
	if (fNodeManager == NULL)
		return B_NO_MEMORY;

	fNodeManager->AddListener(this);

	Run();

	return B_OK;
}
Example #14
0
int main()
{
	void *shm_area;
	struct region *rptr;
	int fd;

	/* Create shared memory object and set its size */
	fd = shm_open("./myshm", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
	if (fd == -1)
	    printf("\n Failed to open shared memory object\n");


	if (ftruncate(fd,  MAX_LEN) == -1)
	    printf("\n Failed to set the size of the shared memory object\n");

	/* Map shared memory object */
	shm_area = mmap(NULL,  MAX_LEN,PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (rptr == MAP_FAILED)
	    printf("\n Failed to map the shared memory\n");
	getchar();
	create_sem();	
	getchar();		
	if (sem_wait (mysem))
	{
            printf("\n Failed to Lock Semaphore\n");
	    exit(1);
        }	// Entering critical section 
		rptr = (struct region *)shm_area;	
		strcpy(rptr->buf,"Message One");
		rptr->len=strlen("Message One");
		rptr++;
		strcpy(rptr->buf,"Message Two");
		rptr->len=strlen("Message Two");
		getchar();
		rptr++;
		strcpy(rptr->buf,"Message Three");
		rptr->len=strlen("Message Three");
	sem_post (mysem);
        // Leaving critical section 
	if (munmap (shm_area, MAX_LEN))
       	    printf("\n Failed to map the shared memory\n");
	printf("\n %d \n",sem_close (mysem));
	close(fd);

}
Example #15
0
int32
BAlert::Go()
{
	fAlertSem = create_sem(0, "AlertSem");
	if (fAlertSem < B_OK) {
		Quit();
		return -1;
	}

	// Get the originating window, if it exists
	BWindow* window =
		dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL)));

	Show();

	// Heavily modified from TextEntryAlert code; the original didn't let the
	// blocked window ever draw.
	if (window) {
		status_t err;
		for (;;) {
			do {
				err = acquire_sem_etc(fAlertSem, 1, B_RELATIVE_TIMEOUT,
									  kSemTimeOut);
				// We've (probably) had our time slice taken away from us
			} while (err == B_INTERRUPTED);

			if (err == B_BAD_SEM_ID) {
				// Semaphore was finally nuked in MessageReceived
				break;
			}
			window->UpdateIfNeeded();
		}
	} else {
		// No window to update, so just hang out until we're done.
		while (acquire_sem(fAlertSem) == B_INTERRUPTED) {
		}
	}

	// Have to cache the value since we delete on Quit()
	int32 value = fAlertValue;
	if (Lock())
		Quit();

	return value;
}
Example #16
0
int main()
{
	int sem_id = create_sem(1);
	init_sem(sem_id, 0, 1);

	pid_t id = fork();
	if(id < 0)
	{
		perror("fork");
		return -1;
	}
	else if(id == 0)
	{//child
		while(1)
		{
			sem_P(sem_id);

			printf("A");
			fflush(stdout);
			usleep(20000);
			usleep(23456);
			printf("A");

			sem_V(sem_id);
		}
	}
	else
	{//father
		while(1)
		{
			sem_P(sem_id);

			printf("B");
			fflush(stdout);
			usleep(29633);
			usleep(23456);
			printf("B");

			sem_V(sem_id);
		}
	}

	destroy_sem(sem_id);
	return 0;
}
Example #17
0
tr_lock*
tr_lockNew( void )
{
    tr_lock *           l = tr_new0( tr_lock, 1 );

#ifdef __BEOS__
    l->lock = create_sem( 1, "" );
#elif defined( WIN32 )
    InitializeCriticalSection( &l->lock ); /* supports recursion */
#else
    pthread_mutexattr_t attr;
    pthread_mutexattr_init( &attr );
    pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
    pthread_mutex_init( &l->lock, &attr );
#endif

    return l;
}
Example #18
0
CreateParamsPanel::CreateParamsPanel(BWindow* window, BPartition* partition,
	off_t offset, off_t size)
	: BWindow(BRect(300.0, 200.0, 600.0, 300.0), 0, B_MODAL_WINDOW_LOOK,
		B_MODAL_SUBSET_WINDOW_FEEL,
		B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
	fEscapeFilter(new EscapeFilter(this)),
	fExitSemaphore(create_sem(0, "CreateParamsPanel exit")),
	fWindow(window),
	fReturnValue(GO_CANCELED)
{
	AddCommonFilter(fEscapeFilter);

	// Scale offset, and size from bytes to megabytes (2^20)
	// so that we do not run over a signed int32.
	offset /= kMegaByte;
	size /= kMegaByte;
	_CreateViewControls(partition, offset, size);
}
Example #19
0
int32 TextEntryAlert::Go(BmString& text_entry_buffer)
{
	int32 button_pressed = -1;
	m_text_entry_buffer = &text_entry_buffer;
	m_button_pressed = &button_pressed;
	sem_id done_mutex = create_sem(0,"text_entry_alert_done");
	m_done_mutex = done_mutex;
	if(done_mutex < B_NO_ERROR)
	{
		Quit();
		return -1;
	}
	m_text_entry_view->MakeFocus(true);
	Show();
	acquire_sem(done_mutex);
	delete_sem(done_mutex);
	return button_pressed;
}
Example #20
0
status_t
TVideoPreviewView::Connected(
	const media_source & producer,
	const media_destination & where,
	const media_format & with_format,
	media_input* out_input)
{
	FUNCTION("TVideoPreviewView::Connected()\n");

	out_input->node = Node();
	out_input->source = mProducer = producer;
	out_input->destination = mDestination;
	out_input->format = with_format;
	sprintf(out_input->name, "TVideoPreviewView");

	mXSize          = with_format.u.raw_video.display.line_width;
	mYSize          = with_format.u.raw_video.display.line_count;
	mRowBytes       = with_format.u.raw_video.display.bytes_per_row;
	mColorspace = with_format.u.raw_video.display.format;

	mBufferAvailable = create_sem (0, "Video buffer available");
	if (mBufferAvailable < B_NO_ERROR) {
		ERROR("TVideoPreviewView: couldn't create semaphore\n");
		return B_ERROR;
	}

	mBufferQueue = new BTimedBufferQueue();

	//	Create offscreen
	if (m_Bitmap == NULL) {
		m_Bitmap = new BBitmap(BRect(0, 0, (mXSize-1), (mYSize - 1)), mColorspace, false, false);
	}

	if (vThread == 0) {
		mDisplayQuit = false;
		int drawPrio = suggest_thread_priority(B_VIDEO_PLAYBACK, 30, 1000, 5000);
		PROGRESS("Suggested draw thread priority: %d\n", drawPrio);
		vThread = spawn_thread(vRun, "TVideoPreviewView:draw", drawPrio, this);
		resume_thread(vThread);
	}

	mConnected = true;
	return B_OK;
}
Example #21
0
void
MixerSettings::StartDeferredSave()
{
	fLocker->Lock();

	// if we don't have a settings file, don't save the settings
	if (!fSettingsFile) {
		fLocker->Unlock();
		return;
	}

	fSettingsDirty = true;
	fSettingsLastChange = system_time();

	if (fSaveThreadRunning) {
		fLocker->Unlock();
		return;
	}

	StopDeferredSave();

	ASSERT(fSaveThreadWaitSem < 0);
	fSaveThreadWaitSem = create_sem(0, "save thread wait");
	if (fSaveThreadWaitSem < B_OK) {
		ERROR("MixerSettings: can't create semaphore\n");
		Save();
		fLocker->Unlock();
		return;
	}
	ASSERT(fSaveThread < 0);
	fSaveThread = spawn_thread(_save_thread_, "Attack of the Killer Tomatoes", 7, this);
	if (fSaveThread < B_OK) {
		ERROR("MixerSettings: can't spawn thread\n");
		delete_sem(fSaveThreadWaitSem);
		fSaveThreadWaitSem = -1;
		Save();
		fLocker->Unlock();
		return;
	}
	resume_thread(fSaveThread);

	fSaveThreadRunning = true;
	fLocker->Unlock();
}
static void
InitInterruptHandler(DeviceInfo& di)
{
	SharedInfo& si = *(di.sharedInfo);

	TRACE("enter InitInterruptHandler()\n");

	DisableVBI();					// disable & clear any pending interrupts
	si.bInterruptAssigned = false;	// indicate interrupt not assigned yet

	// Create a semaphore for vertical blank management.
	si.vertBlankSem = create_sem(0, di.name);
	if (si.vertBlankSem < 0)
		return;

	// Change the owner of the semaphores to the calling team (usually the
	// app_server).  This is required because apps can't aquire kernel
	// semaphores.

	thread_id threadID = find_thread(NULL);
	thread_info threadInfo;
	status_t status = get_thread_info(threadID, &threadInfo);
	if (status == B_OK)
		status = set_sem_owner(si.vertBlankSem, threadInfo.team);

	// If there is a valid interrupt assigned, set up interrupts.

	if (status == B_OK && di.pciInfo.u.h0.interrupt_pin != 0x00
		&& di.pciInfo.u.h0.interrupt_line != 0xff) {
		// We have a interrupt line to use.

		status = install_io_interrupt_handler(di.pciInfo.u.h0.interrupt_line,
			InterruptHandler, (void*)(&di), 0);

		if (status == B_OK)
			si.bInterruptAssigned = true;	// we can use interrupt related functions
	}

	if (status != B_OK) {
		// Interrupt does not exist; thus delete semaphore as it won't be used.
		delete_sem(si.vertBlankSem);
		si.vertBlankSem = -1;
	}
}
Example #23
0
status_t
CliContext::Init(Team* team, UserInterfaceListener* listener)
{
	fTeam = team;
	fListener = listener;

	fTeam->AddListener(this);

	status_t error = fLock.InitCheck();
	if (error != B_OK)
		return error;

	fBlockingSemaphore = create_sem(0, "CliContext block");
	if (fBlockingSemaphore < 0)
		return fBlockingSemaphore;

	fEditLine = el_init("Debugger", stdin, stdout, stderr);
	if (fEditLine == NULL)
		return B_ERROR;

	fHistory = history_init();
	if (fHistory == NULL)
		return B_ERROR;

	HistEvent historyEvent;
	history(fHistory, &historyEvent, H_SETSIZE, 100);

	el_set(fEditLine, EL_HIST, &history, fHistory);
	el_set(fEditLine, EL_EDITOR, "emacs");
	el_set(fEditLine, EL_PROMPT, &_GetPrompt);

	fNodeManager = new(std::nothrow) ValueNodeManager();
	if (fNodeManager == NULL)
		return B_NO_MEMORY;
	fNodeManager->AddListener(this);

	fExpressionInfo = new(std::nothrow) ExpressionInfo();
	if (fExpressionInfo == NULL)
		return B_NO_MEMORY;
	fExpressionInfo->AddListener(this);

	return B_OK;
}
Example #24
0
status_t
start_wlan(device_t device)
{
	int i;
	struct ifnet* ifp = get_ifnet(device, i);
	if (ifp == NULL)
		return B_BAD_VALUE;

// TODO: review this and find a cleaner solution!
	// This ensures that the cloned device gets
	// the same index assigned as the base device
	// Resulting in the same device name
	// e.g.: /dev/net/atheros/0 instead of
	//       /dev/net/atheros/1
	gDevices[i] = NULL;

	struct ieee80211com* ic = (ieee80211com*)ifp->if_l2com;

	struct ieee80211vap* vap = ic->ic_vap_create(ic, "wlan",
		device_get_unit(device),
		IEEE80211_M_STA,		// mode
		0,						// flags
		NULL,					// BSSID
		IF_LLADDR(ifp));		// MAC address

	if (vap == NULL) {
		gDevices[i] = ifp;
		return B_ERROR;
	}

	// ic_vap_create() established that gDevices[i] links to vap->iv_ifp now
	KASSERT(gDevices[i] == vap->iv_ifp,
		("start_wlan: gDevices[i] != vap->iv_ifp"));

	vap->iv_ifp->scan_done_sem = create_sem(0, "wlan scan done");

	// We aren't connected to a WLAN, yet.
	if_link_state_change(vap->iv_ifp, LINK_STATE_DOWN);

	dprintf("%s: wlan started.\n", __func__);

	return B_OK;
}
Example #25
0
static status_t
ethernet_std_ops(int32 op, ...)
{
	switch (op) {
		case B_MODULE_INIT:
		{
			status_t status = get_module(NET_STACK_MODULE_NAME,
				(module_info **)&sStackModule);
			if (status < B_OK)
				return status;

			new (&sCheckList) DoublyLinkedList<ethernet_device>;
				// static C++ objects are not initialized in the module startup

			sLinkCheckerThread = -1;

			sLinkChangeSemaphore = create_sem(0, "ethernet link change");
			if (sLinkChangeSemaphore < B_OK) {
				put_module(NET_STACK_MODULE_NAME);
				return sLinkChangeSemaphore;
			}

			mutex_init(&sListLock, "ethernet devices");

			return B_OK;
		}

		case B_MODULE_UNINIT:
		{
			delete_sem(sLinkChangeSemaphore);

			status_t status;
			wait_for_thread(sLinkCheckerThread, &status);

			mutex_destroy(&sListLock);
			put_module(NET_STACK_MODULE_NAME);
			return B_OK;
		}

		default:
			return B_ERROR;
	}
}
Example #26
0
status_t
CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener)
{
	status_t error = fContext.Init(team, listener);
	if (error != B_OK)
		return error;

	error = _RegisterCommands();
	if (error != B_OK)
		return error;

	fShowSemaphore = create_sem(0, "show CLI");
	if (fShowSemaphore < 0)
		return fShowSemaphore;

	team->AddListener(this);

	return B_OK;
}
Example #27
0
// Implementation of Filter
Filter::Filter(BBitmap* image, BMessenger listener, uint32 what)
	: fListener(listener)
	, fWhat(what)
	, fStarted(false)
	, fN(0)
	, fNumberOfThreads(0)
	, fIsRunning(false)
	, fSrcImage(image)
	, fDestImageInitialized(false)
	, fDestImage(NULL)
{
	fCPUCount = NumberOfActiveCPUs();

	fWaitForThreads = create_sem(0, "wait_for_threads");

	#if TIME_FILTER
	fStopWatch = NULL;
	#endif
}
ListChooseWindow::ListChooseWindow(list<string>* strL, string title, 
	string text1, string text2, string str) : 
	BWindow(BRect(200, 200, 415, 400), title.c_str(),
	B_FLOATING_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, 
	B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_CLOSABLE)
{
	BRect rect(200, 200, 415, 400);
	rect.OffsetTo(0, 0);
	BView* backview = new BView(rect, "ListChooseBackView", 0, B_WILL_DRAW);
	backview->SetViewColor(222, 222, 222);
	AddChild(backview);
	
	BStringView* sv = new BStringView(BRect(15, 5, 185, 20),
		"ListChooseSV", text1.c_str());
	backview->AddChild(sv);
	sv = new BStringView(BRect(15, 20, 185, 33),
		"ListChooseSV", text2.c_str());
	backview->AddChild(sv);

	lv = new BListView(BRect(15, 40, 185, 153), "ListChooseLV");
	backview->AddChild(new BScrollView("scrollregister", lv,
		B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true));

	BStringItem* si;
	for (list<string>::iterator iter = strL->begin(); iter !=
		strL->end(); iter++)
	{
		si = new BStringItem((*iter).c_str());
		lv->AddItem(si);
		if (*iter == str)
			si->SetEnabled(false);
	}
	
	BButton* button = new BButton(BRect(15, 165, 95, 185), "okB",
		"OK", new BMessage(ListChooseOKMSG));
	backview->AddChild(button);
	button->MakeDefault(true);
	button = new BButton(BRect(105, 165, 200, 185), "cancelB",
		"Cancel", new BMessage(ListChooseCancelMSG));
	backview->AddChild(button);
	
	clickWait = create_sem(0, "clickWait");
}
Example #29
0
status_t
initialize_timer(void)
{
	sTimerCount = 0;
	sTimerNextId = 1;
	B_INITIALIZE_SPINLOCK(&sTimerSpinlock);
	
	sTimerThread = spawn_kernel_thread(timer_thread, "firewire timer", 80, 0);
	sTimerSem = create_sem(0, "firewire timer");
	set_sem_owner(sTimerSem, B_SYSTEM_TEAM);
	
	if (sTimerSem < 0 || sTimerThread < 0) {
		delete_sem(sTimerSem);
		kill_thread(sTimerThread);
		return B_ERROR;
	}
	
	resume_thread(sTimerThread);
	return B_OK;
}
Example #30
0
RTDECL(int)  RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
{
    AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
    AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER);

    PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAllocZ(sizeof(*pThis));
    if (RT_UNLIKELY(!pThis))
        return VERR_NO_MEMORY;

    pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
    pThis->BenId = 0;
    pThis->SemId = create_sem(0, "IPRT Fast Mutex Semaphore");
    if (pThis->SemId >= B_OK)
    {
        *phFastMtx = pThis;
        return VINF_SUCCESS;
    }
    RTMemFree(pThis);
    return VERR_TOO_MANY_SEMAPHORES;     /** @todo r=ramshankar: use RTErrConvertFromHaikuKernReturn */
}