예제 #1
0
void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
	{
	SSL_CTX *ssl_ctx[2];
	thread_id thread_ctx[MAX_THREAD_NUMBER];
	int i;

	ssl_ctx[0]=s_ctx;
	ssl_ctx[1]=c_ctx;

	for (i=0; i<thread_number; i++)
		{
		thread_ctx[i] = spawn_thread((thread_func)ndoit,
			NULL, B_NORMAL_PRIORITY, (void *)ssl_ctx);
		resume_thread(thread_ctx[i]);
		}

	printf("waiting...\n");
	for (i=0; i<thread_number; i++)
		{
		status_t result;
		wait_for_thread(thread_ctx[i], &result);
		}

	printf("beos threads done (%d,%d)\n",
		s_ctx->references,c_ctx->references);
	}
예제 #2
0
thread_id
BUrlRequest::Run()
{
	// Thread already running
	if (fRunning) {
		PRINT(("BUrlRequest::Run() : Oops, already running ! "
			"[urlProtocol=%p]!\n", this));
		return fThreadId;
	}

	fThreadId = spawn_thread(BUrlRequest::_ThreadEntry, fThreadName,
		B_NORMAL_PRIORITY, this);

	if (fThreadId < B_OK)
		return fThreadId;

	fRunning = true;

	status_t launchErr = resume_thread(fThreadId);
	if (launchErr < B_OK) {
		PRINT(("BUrlRequest::Run() : Failed to resume thread %" B_PRId32 "\n",
			fThreadId));
		return launchErr;
	}

	return fThreadId;
}
예제 #3
0
status_t QueryMenu::SetPredicate(const char *expr, BVolume *volume)
{
	status_t status;

	// Set the volume
	if (volume == NULL)
	{
		BVolume bootVolume;
		BVolumeRoster().GetBootVolume(&bootVolume);

		if ( (status = fQuery->SetVolume(&bootVolume)) != B_OK)
			return status;
	}
	else if ((status = fQuery->SetVolume(volume)) != B_OK)
		return status;
	
	if ((status = fQuery->SetPredicate(expr)) < B_OK)
		return status;

	// Force query thread to exit if still running
	fCancelQuery = true;
	fQueryLock.Lock();

	// Remove all existing menu items (if any... )
	RemoveEntries();
	fQueryLock.Unlock();
	
	// Resolve Query/Build Menu in seperate thread
	thread_id thread;
	thread = spawn_thread(query_thread, "query menu thread", B_NORMAL_PRIORITY, this);

	return resume_thread(thread);
}
예제 #4
0
KeepAlive::KeepAlive(PortTalker *port_talker) {
	_keep_alive_thread_id = -1;
	_port_talker          = port_talker;

	// Spawn listener thread (communication from remote machine)
	resume_thread(_keep_alive_thread_id = spawn_thread(KeepAlive::_SpawnKeepAliveThread, "keep_alive", B_NORMAL_PRIORITY, this));
}
예제 #5
0
status_t
PowerStatusDriverInterface::StartWatching(BHandler* target)
{
	BAutolock autolock(fListLocker);

	status_t status = Monitor::StartWatching(target);
	if (status != B_OK)
		return status;

	if (fThread > 0)
		return B_OK;

	fThread = spawn_thread(&_ThreadWatchPowerFunction, "PowerStatusThread",
		B_LOW_PRIORITY, this);
	if (fThread >= 0) {
		fWaitSem = create_sem(0, "power status wait");

		atomic_set(&fIsWatching, 1);
		status = resume_thread(fThread);
	} else
		return fThread;

	if (status != B_OK && fWatcherList.CountItems() == 0) {
		atomic_set(&fIsWatching, 0);
		delete_sem(fWaitSem);

		fThread = -1;
		fWaitSem = -1;
	}

	return status;
}
예제 #6
0
void
LJEventEditor::GetItem()
{
    thread_id get_event_thread = spawn_thread(get_event, 
                            "EventEditor::GetEvent", B_NORMAL_PRIORITY, this);
    resume_thread(get_event_thread);    
}
예제 #7
0
status_t AmInputQueue::StartPerforming()
{
	BAutolock _l(mLock);
	
	status_t result = B_ERROR;
	
	// Start up record thread.
	if (mPerformLock.Lock()) {
		mPerformAvail = create_sem(0, "AmInputQueue Perform Avail");
		if (mPerformAvail >= B_OK) {
			mPerformThread = spawn_thread(PerformThreadEntry, "AmInputQueue Performer",
										 B_REAL_TIME_PRIORITY, this);
			if (mPerformThread >= B_OK) {
				resume_thread(mPerformThread);
				result = B_OK;
			} else {
				result = mPerformThread;
				delete_sem(mPerformAvail);
				mPerformAvail = B_BAD_SEM_ID;
			}
		} else {
			result = mPerformAvail;
		}
		mPerformLock.Unlock();
	}
	
	return result;
}
예제 #8
0
FractalEngine::FractalEngine(BHandler* parent, BLooper* looper)
	:
	BLooper("FractalEngine"),
	fWidth(0), fHeight(0),
	fRenderBuffer(NULL),
	fRenderBufferLen(0),
	fSubsampling(2),
	fMessenger(parent, looper),
	fIterations(1024),
	fColorset(Colorset_Royal)
{
	fDoSet = &FractalEngine::DoSet_Mandelbrot;

	fRenderSem = create_sem(0, "RenderSem");
	fRenderStoppedSem = create_sem(0, "RenderStopped");

	system_info info;
	get_system_info(&info);
	fThreadCount = info.cpu_count;

	if (fThreadCount > MAX_RENDER_THREADS)
		fThreadCount = MAX_RENDER_THREADS;

	for (uint8 i = 0; i < fThreadCount; i++) {
		fRenderThreads[i] = spawn_thread(&FractalEngine::RenderThread,
			BString().SetToFormat("RenderThread%d", i).String(),
			B_NORMAL_PRIORITY, this);
		resume_thread(fRenderThreads[i]);
	}
}
예제 #9
0
MacScreen::MacScreen(const BeOS_monitor_desc& monitor, const char *name, int mode_bit, status_t *error)
	: BWindowScreen(name, 1 << mode_bit, error), tick_thread(-1)
	, monitor(monitor)
{
	// Set all variables
	frame_backup = NULL;
	palette_changed = false;
	screen_active = false;
	first_time = true;
	quitting = false;

	// Set relative mouse mode
	ADBSetRelMouseMode(true);

	// Create view to get mouse events
	main_view = new BView(Frame(), NULL, B_FOLLOW_NONE, 0);
	AddChild(main_view);

	// Start 60Hz interrupt
	tick_thread_active = true;
	tick_thread = spawn_thread(tick_func, "Polling sucks...", B_DISPLAY_PRIORITY, this);
	resume_thread(tick_thread);

	// Add filter for keyboard and mouse events
	BMessageFilter *filter = new BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, filter_func);
	AddCommonFilter(filter);
}
예제 #10
0
status_t AmInputQueue::StartRecording()
{
	BAutolock _l(mLock);
	
	status_t result = B_ERROR;
	
	// Start up record thread.
	if (mRecordLock.Lock()) {
		mRecordAvail = create_sem(0, "AmInputQueue Record Avail");
		if (mRecordAvail >= B_OK) {
			mRecordThread = spawn_thread(RecordThreadEntry, "AmInputQueue Recorder",
										 B_NORMAL_PRIORITY, this);
			if (mRecordThread >= B_OK) {
				resume_thread(mRecordThread);
				result = B_OK;
			} else {
				result = mRecordThread;
				delete_sem(mRecordAvail);
				mRecordAvail = B_BAD_SEM_ID;
			}
		} else {
			result = mRecordAvail;
		}
		mRecordLock.Unlock();
	}
	
	return result;
}
예제 #11
0
bool
MessageLooper::Run()
{
	BAutolock locker(this);

	fQuitting = false;

	char name[B_OS_NAME_LENGTH];
	_GetLooperName(name, sizeof(name));

	// Spawn our message-monitoring thread
	fThread = spawn_thread(_message_thread, name, B_DISPLAY_PRIORITY, this);
	if (fThread < B_OK) {
		fQuitting = true;
		return false;
	}

	if (resume_thread(fThread) != B_OK) {
		fQuitting = true;
		kill_thread(fThread);
		fThread = -1;
		return false;
	}

	return true;
}
예제 #12
0
void
setup_server()
{
	sockaddr_in address;
	memset(&address, 0, sizeof(address));
	address.sin_len = sizeof(sockaddr_in);
	address.sin_family = AF_INET;
	address.sin_port = htons(1024);
	address.sin_addr.s_addr = INADDR_ANY;

	status_t status = socket_bind(gServerSocket, (struct sockaddr*)&address,
		sizeof(struct sockaddr));
	if (status < B_OK) {
		fprintf(stderr, "tcp_tester: cannot bind server: %s\n", strerror(status));
		exit(1);
	}
	status = socket_listen(gServerSocket, 40);
	if (status < B_OK) {
		fprintf(stderr, "tcp_tester: server cannot listen: %s\n",
			strerror(status));
		exit(1);
	}

	thread_id serverThread = spawn_thread(server_thread, "server",
		B_NORMAL_PRIORITY, NULL);
	if (serverThread < B_OK) {
		fprintf(stderr, "tcp_tester: cannot start server: %s\n",
			strerror(serverThread));
		exit(1);
	}

	resume_thread(serverThread);
}
예제 #13
0
int
main()
{
	status_t s;
	ssize_t size;
	int32 code;
	
	id = create_port(1, "test port");
	printf("created port %ld\n", id);
	
	s = write_port(id, 0x1234, data, 10);
	printf("write port result 0x%08lx (%s)\n", s, strerror(s));

	size = read_port(id, &code, data, sizeof(data)); 
	printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size));

	printf("port_buffer_size should block for 5 seconds now, as port is empty\n");
	
	thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL);
	resume_thread(thread);
	snooze(5000000);

	printf("write port...\n");
	s = write_port(id, 0x5678, data, 20);
	printf("write port result 0x%08lx (%s)\n", s, strerror(s));

	printf("waiting for thread to terminate\n");
	wait_for_thread(thread, &s);
	
	return 0;
}
예제 #14
0
// _InitServerInfoConnectionListener
status_t
NetFSServer::_InitServerInfoConnectionListener()
{
	// spawn the listener thread
	fServerInfoConnectionListener = spawn_thread(
		&_ServerInfoConnectionListenerEntry,
		"server info connection listener", B_NORMAL_PRIORITY, this);
	if (fServerInfoConnectionListener < 0)
		return fServerInfoConnectionListener;
	// create a listener socket
	fServerInfoConnectionListenerSocket = socket(AF_INET, SOCK_STREAM, 0);
	if (fServerInfoConnectionListenerSocket < 0)
		return errno;
	// bind it to the port
	sockaddr_in addr;
	addr.sin_family = AF_INET;
	addr.sin_port = htons(kDefaultServerInfoPort);
	addr.sin_addr.s_addr = INADDR_ANY;
	if (bind(fServerInfoConnectionListenerSocket, (sockaddr*)&addr,
		sizeof(addr)) < 0) {
		return errno;
	}
	// start listening
	if (listen(fServerInfoConnectionListenerSocket, 5) < 0)
		return errno;
	return B_OK;
}
예제 #15
0
sptr<IProcess> BProcess::Spawn(const SString& name, const SValue& env, uint32_t flags)
{
#if BINDER_DEBUG_LIB
    (void)env;
    (void)flags;

    team_id teamid = this_team()+atomic_add(&nextFakeProcessIDDelta,1);
    bout << "spawning pretend team " << teamid << endl;

    SysHandle thid = spawn_thread((thread_entry)pretend_team,"pretend_team",B_NORMAL_PRIORITY,(void *)teamid);
    ErrFatalErrorIf(thid < 0, "could not spawn pretend_team");

    sptr<IProcess> team
        = IProcess::AsInterface(SLooper::GetRootObject(thid, teamid));
    ErrFatalErrorIf(team == NULL, "pretend_team gave us a root object that wasn't an IProcess");
#else
    SString fullName("/binder_team");
    mkdir(fullName.String(), S_IRWXU|S_IRWXG|S_IRWXO);
    fullName += "/";
    if (name != "") fullName += name;
    else fullName += "anonymous";
    symlink("/system/servers/remote_place", fullName.String());

    sptr<IBinder> teamBinder = SpawnFile(fullName, env, flags);
    sptr<IProcess> team = IProcess::AsInterface(teamBinder);
    ErrFatalErrorIf(team == NULL && teamBinder != NULL, "remote_place did not publish an IProcess");
#endif // BINDER_DEBUG_LIB

    return team;
}
예제 #16
0
void
VideoProducer::_HandleStart(bigtime_t performanceTime)
{
	// Start producing frames, even if the output hasn't been connected yet.
	TRACE("_HandleStart(%Ld)\n", performanceTime);

	if (fRunning) {
		TRACE("_HandleStart: Node already started\n");
		return;
	}

	fFrame = 0;
	fFrameBase = 0;
	fPerformanceTimeBase = performanceTime;

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

	fThread = spawn_thread(_FrameGeneratorThreadEntry, "frame generator",
		B_NORMAL_PRIORITY, this);
	if (fThread < B_OK) {
		delete_sem(fFrameSync);
		return;
	}

	resume_thread(fThread);
	fRunning = true;
	return;
}
예제 #17
0
long gwthread_create_real(gwthread_func_t *func, const char *name, void *arg)
{
    int sigtrick = 0;
    sigset_t old_signal_set;
    long thread_id;

    /*
     * We want to make sure that only the main thread handles signals,
     * so that each signal is handled exactly once.  To do this, we
     * make sure that each new thread has all the signals that we
     * handle blocked.  To avoid race conditions, we block them in 
     * the spawning thread first, then create the new thread (which
     * inherits the settings), and then restore the old settings in
     * the spawning thread.  This means that there is a brief period
     * when no signals will be processed, but during that time they
     * should be queued by the operating system.
     */
    if (gwthread_self() == MAIN_THREAD_ID)
	    sigtrick = block_user_signals(&old_signal_set) == 0;

    thread_id = spawn_thread(func, name, arg);

    /*
     * Restore the old signal mask.  The new thread will have
     * inherited the resticted one, but the main thread needs
     * the old one back.
     */
    if (sigtrick)
 	    restore_user_signals(&old_signal_set);
    
    return thread_id;
}
예제 #18
0
int
main()
{
	// Test program to reproduce bug #2562. Is finished quickly and must be run
	// in a loop to reproduce the bug.

	// install signal handler
	if (signal(SIGUSR1, signal_handler) == SIG_ERR) {
		fprintf(stderr, "Error: Failed to install signal handler: %s\n",
			strerror(errno));
		exit(1);
	}

	// start signal thread
	thread_id signalThread = spawn_thread(&signal_pusher, "signal pusher",
		B_NORMAL_PRIORITY, NULL);
	resume_thread(signalThread);

	allocator_thread(0);

	kill_thread(signalThread);
	snooze(1000);

	printf("test successful, handled %lld signals\n", sHandledSignals);

	return 0;
}
예제 #19
0
TFTPClient::TFTPClient()
{
	fAbort = false;
	fControlEndpoint = -1;
	fWaitTime = 60000000;
	fReplyBuff = new TStreamBuff(SB_UNKNOWN_TEXT_TYPE);
	fSemID = -1;
	fReceiverThreadID = -1;
	
	fSemID = create_sem(1, "stream_buff");
	if (fSemID < 0) {
		fStatus = fSemID;
		fStrError.SetTo(strerror(fStatus));
		return;
	}
	
	// 受信スレッド生成
	fReceiverThreadID = spawn_thread(TFTPClient::ReceiverThread,
		"receiver_thread", B_NORMAL_PRIORITY, this);
	if (fReceiverThreadID < 0) {
		fStatus = fReceiverThreadID;
		fStrError.SetTo(strerror(fStatus));
		return;
	}
	
	fStatus = B_OK;
}
예제 #20
0
GX_BDirectWindow::GX_BDirectWindow(BRect window_rect, const char *pTitle)
: BDirectWindow(window_rect, pTitle, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
{
    m_pInstance = this;
	m_bConnected = false;
	m_bDirty = false;

	BView *view = g_pApp->CreateSubview(this);
	if (view)
	{
	   AddChild(view);
	}
	AddShortcut('\n', B_COMMAND_KEY, new BMessage(MSG_SYSAPPLICATION_SWITCHFS));
	AddShortcut('x', B_COMMAND_KEY, new BMessage(MSG_SYSAPPLICATION_CLOSE));

	m_SemID = create_sem(1, "BDirectWindow lock sem");

	m_DrawThread = spawn_thread(RenderThread, "drawing_thread", B_NORMAL_PRIORITY, (void *) this);
	if (m_DrawThread<0)
	{
		printf("Can't spawn drawing thread, bailing out...\n" );
	}
	Center();

	resume_thread(m_DrawThread);
}
QHaikuIntegration *QHaikuIntegration::createHaikuIntegration(const QStringList& parameters, int &argc, char **argv)
{
	thread_id my_thread;
	QString appSignature = QLatin1String("application/x-vnd.qt5-") + QCoreApplication::applicationName();
	haikuApplication = new HQApplication(appSignature.toUtf8());
	be_app = haikuApplication;

	my_thread = spawn_thread(AppThread, "BApplication_thread", B_NORMAL_PRIORITY, (void*)haikuApplication);
	resume_thread(my_thread);
		
	haikuApplication->UnlockLooper();
	
	if(argc==1) {
		for(int i=0;i<100;i++) {
			if(haikuApplication->RefHandled) {
				BPath p(&haikuApplication->Ref);
				argc = 2;
				argv[1]=strdup(p.Path());
				argv[2]=0;
				break;
			}
			snooze(1000);
		}
	}
	
    return new QHaikuIntegration(parameters, argc, argv);
}
예제 #22
0
status_t
Worker::Init()
{
	// check lock
	status_t error = fLock.InitCheck();
	if (error != B_OK)
		return error;

	// init jobs table
	error = fJobs.Init();
	if (error != B_OK)
		return error;

	// create semaphore for the worker
	fWorkToDoSem = create_sem(0, "work to do");
	if (fWorkToDoSem < 0)
		return fWorkToDoSem;

	// spawn worker thread
	fWorkerThread = spawn_thread(_WorkerLoopEntry, "worker", B_NORMAL_PRIORITY,
		this);
	if (fWorkerThread < 0)
		return fWorkerThread;

	resume_thread(fWorkerThread);

	return B_OK;
}
예제 #23
0
void
FinePixProducer::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;
}
예제 #24
0
status_t PoorManServer::Run()
{
	if (chdir(fHttpdServer->cwd) == -1) {
		poorman_log("no web directory, can't start up.\n", false, INADDR_NONE, RED);
		return B_ERROR;
	}
	
	httpd_sockaddr sa4;
	memset(&sa4, 0, sizeof(httpd_sockaddr));
	sa4.sa_in.sin_family = AF_INET;
	sa4.sa_in.sin_port = htons(80);
	sa4.sa_in.sin_addr.s_addr = htonl(INADDR_ANY);
	fHttpdServer->listen4_fd = httpd_initialize_listen_socket(&sa4);
	if (fHttpdServer->listen4_fd == -1)
		return B_ERROR;

	fListenerTid = spawn_thread(
		PoorManServer::_Listener,
		"www listener",
		B_NORMAL_PRIORITY,
		static_cast<void*>(this)
	);
	if (fListenerTid < B_OK) {
		poorman_log("can't create listener thread.\n", false, INADDR_NONE, RED);
		return B_ERROR;
	}
	fIsRunning = true;
	if (resume_thread(fListenerTid) != B_OK) {
		fIsRunning = false;
		return B_ERROR;
	}
	
	//our server is up and running
	return B_OK;
}
예제 #25
0
int32 PoorManServer::_Listener(void* data)
{
	PRINT(("The listener thread is working.\n"));
	int retval;
	thread_id tid;
	httpd_conn* hc;
	PoorManServer* s = static_cast<PoorManServer*>(data);
	
	while (s->fIsRunning) {
		hc = new httpd_conn;
		hc->initialized = 0;
		PRINT(("calling httpd_get_conn()\n"));
		retval = //accept(), blocked here
			httpd_get_conn(s->fHttpdServer, s->fHttpdServer->listen4_fd, hc);
		switch (retval) {
			case GC_OK:
				break;
			case GC_FAIL:
				httpd_destroy_conn(hc);
				delete hc;
				s->fIsRunning = false;
				return -1;
			case GC_NO_MORE:
				//should not happen, since we have a blocking socket
				httpd_destroy_conn(hc);
				continue;
				break;
			default: 
				//shouldn't happen
				continue;
				break;
		}
		
		if (s->fCurConns > s->fMaxConns) {
			httpd_send_err(hc, 503,
				httpd_err503title, (char *)"", httpd_err503form, (char *)"");
			httpd_write_response(hc);
			continue;
		}
		
		tid = spawn_thread(
			PoorManServer::_Worker,
			"www connection",
			B_NORMAL_PRIORITY,
			static_cast<void*>(s)
		);
		if (tid < B_OK) {
			continue;
		}
		/*We don't check the return code here.
		 *As we can't kill a thread that doesn't receive the
		 *httpd_conn, we simply let it die itself.
		 */
		send_data(tid, 512, &hc, sizeof(httpd_conn*));
		atomic_add(&s->fCurConns, 1);
		resume_thread(tid);
	}//while
	return 0;
}
예제 #26
0
MThread::MThread(
	const char *	inThreadName,
	long			inPriority)
	: fLock(inThreadName)
{
	fCanceled = false;
	fThread = spawn_thread((thread_entry) ThreadEntry, inThreadName, inPriority, this);
}
예제 #27
0
void startproxy(void)
{
	tid_proxy=spawn_thread(proxythread,"proxythread",
		B_NORMAL_PRIORITY,NULL);
	if(tid_proxy<B_NO_ERROR)
		fatal(__FILE__,__LINE__,"spawn_thread failed");
	resume_thread(tid_proxy);
}
thread_id StartMouseDragOrPopupWatcher(BView* TargetView)
{
	thread_id MouseWatcherThread = spawn_thread(MouseDragOrPopupWatcher,"MouseDragOrPopupWatcher",
		B_NORMAL_PRIORITY,new BMessenger(TargetView));
	if(MouseWatcherThread != B_NO_MORE_THREADS && MouseWatcherThread != B_NO_MEMORY)
		resume_thread(MouseWatcherThread);
	return MouseWatcherThread;
}
예제 #29
0
파일: VUView.cpp 프로젝트: mmanley/Antares
void
VUView::_Run()
{
	fThreadId = spawn_thread(_RenderLaunch, "VU view", B_NORMAL_PRIORITY, this);
	if (fThreadId < 0)
		return;
	resume_thread(fThreadId);
}
예제 #30
0
void
WPASupplicantApp::ReadyToRun()
{
	fSupplicantThread = spawn_thread(_SupplicantThread,
		"wpa_supplicant thread", B_NORMAL_PRIORITY, this);
	if (fSupplicantThread < 0 || resume_thread(fSupplicantThread))
		PostMessage(B_QUIT_REQUESTED);
}