void
SDL_SYS_SetupThread(const char *name)
{
#if !defined(__ANDROID__) && !defined(__NACL__)
    int i;
    sigset_t mask;
#endif /* !__ANDROID__ && !__NACL__ */

    if (name != NULL) {
        #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
        SDL_assert(checked_setname);
        if (ppthread_setname_np != NULL) {
            #if defined(__MACOSX__) || defined(__IPHONEOS__)
            ppthread_setname_np(name);
            #elif defined(__LINUX__)
            ppthread_setname_np(pthread_self(), name);
            #endif
        }
        #elif HAVE_PTHREAD_SETNAME_NP
            #if defined(__NETBSD__)
            pthread_setname_np(pthread_self(), "%s", name);
            #else
            pthread_setname_np(pthread_self(), name);
            #endif
        #elif HAVE_PTHREAD_SET_NAME_NP
            pthread_set_name_np(pthread_self(), name);
        #elif defined(__HAIKU__)
            /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
            char namebuf[B_OS_NAME_LENGTH];
            SDL_snprintf(namebuf, sizeof (namebuf), "%s", name);
            namebuf[sizeof (namebuf) - 1] = '\0';
            rename_thread(find_thread(NULL), namebuf);
        #endif
    }

   /* NativeClient does not yet support signals.*/
#if !defined(__ANDROID__) && !defined(__NACL__)
    /* Mask asynchronous signals for this thread */
    sigemptyset(&mask);
    for (i = 0; sig_list[i]; ++i) {
        sigaddset(&mask, sig_list[i]);
    }
    pthread_sigmask(SIG_BLOCK, &mask, 0);
#endif /* !__ANDROID__ && !__NACL__ */


#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
    /* Allow ourselves to be asynchronously cancelled */
    {
        int oldstate;
        pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
    }
#endif
}
예제 #2
0
extern "C" Display* XOpenDisplay(const char *name) {
  Display* display = new _XDisplay;
  memset(display, 0, sizeof(Display));
  main_thread = find_thread(NULL);
  thread_info info;
  get_thread_info(main_thread, &info);
  rename_thread(main_thread, "X Server"); 
  server_thread = spawn_thread(xmain, info.name, B_NORMAL_PRIORITY, 0);
  resume_thread(server_thread);
  suspend_thread(main_thread);
  init_font();
  set_display(display);
  return display;
}
예제 #3
0
/*!	\brief Creates and runs the registrar application.

	The main thread is renamed.

	\return 0.
*/
int
main()
{
	FUNCTION_START();
	// rename the main thread
	rename_thread(find_thread(NULL), kRosterThreadName);
	// create and run the registrar application
	Registrar *app = new Registrar();
PRINT(("app->Run()...\n"));
	app->Run();
PRINT(("delete app...\n"));
	delete app;
	FUNCTION_END();
	return 0;
}
예제 #4
0
void BubbleHelper::Helper()
{
    // Wait until the BApplication becomes valid, in case
    // someone creates this as a global variable.
    while(!be_app_messenger.IsValid())
        snooze(200000);
    // wait a little longer, until the BApplication is really up to speed
    while(be_app->IsLaunching())
        snooze(200000);

    textwin=new BWindow(BRect(-100,-100,-50,-50),"",B_BORDERED_WINDOW_LOOK, B_FLOATING_ALL_WINDOW_FEEL,
                B_NOT_MOVABLE|B_AVOID_FOCUS);

    textview=new BTextView(BRect(0,0,50,50),"",BRect(1,1,49,49),B_FOLLOW_ALL_SIDES,B_WILL_DRAW);
    textview->MakeEditable(false);
    textview->MakeSelectable(false);
    textview->SetWordWrap(false);
    textview->SetLowColor(255,255,190);
    textview->SetViewColor(255,255,190);
    textview->SetHighColor(0,0,0);
    textwin->AddChild(textview);
    textwin->Run();
    textwin->Lock();
    textwin->Activate(false);
    rename_thread(textwin->Thread(),"bubble");
    textwin->Unlock();

    ulong delaycounter=0;
    BPoint lastwhere;

    while(be_app_messenger.IsValid())
    {
        BPoint where;
        ulong buttons;
        if(enabled)
        {
            if(textwin->Lock())
            {
                textview->GetMouse(&where,&buttons);
                textview->ConvertToScreen(&where);
                if(lastwhere!=where || buttons)
                {
                    delaycounter=0;
                }
                else
                {
                    // mouse didn't move
                    if(delaycounter++>5)
                    {
                        delaycounter=0;
                        // mouse didn't move for a while
                        BView *view=FindView(where);
                        char *text=NULL;
                        while(view && (text=GetHelp(view))==NULL)
                            view=view->Parent();
                        if(text)
                        {
                            DisplayHelp(text,where);
                            // wait until mouse moves out of view, or wait
                            // for timeout
                            long displaycounter=0;
                            BPoint where2;
                            long displaytime=max_c(20,strlen(text));
                            do
                            {
                                textwin->Unlock();
                                snooze(100000);
                                if(!textwin->Lock())
                                    goto end; //window is apparently gone
                                textview->GetMouse(&where2,&buttons);
                                textview->ConvertToScreen(&where2);
                            } while(!buttons && where2==where && (displaycounter++<displaytime));
                        
                            HideBubble();
                            do
                            {
                                textwin->Unlock();
                                snooze(100000);
                                if(!textwin->Lock())
                                    goto end; //window is apparently gone
                                textview->GetMouse(&where2,&buttons);
                                textview->ConvertToScreen(&where2);
                            } while(where2==where);
                        }
                    }
                }
                lastwhere=where;
                textwin->Unlock();
            }
        }
end:
        snooze(100000);
    }
    // (this thread normally gets killed by the destructor before arriving here)
}
예제 #5
0
void
AppServer::RunLooper()
{
	rename_thread(find_thread(NULL), "picasso");
	_message_thread((void*)this);
}
예제 #6
0
status_t	
GenericThread::Rename(char* name)
{
	return rename_thread(fThreadId, name);
}
예제 #7
0
const char* VersionControl::GetToolVersion(const char* path)
{
	thread_id thread;
	int in, out, err;
	const char** argv;
	int argc = 0;
	const char* threadname = "Helios:GetToolVersion()";
	char buffer[1000];
	size_t bytesread;
	BString version = "";

	buffer[0] = 0;
	argv = (const char**)malloc(sizeof(char*) * (5));
	argv[argc++] = strdup(path);
	argv[argc++] = strdup("--version");
	argv[argc] = NULL;

	thread = pipe_command(argc, argv, in, out, err);
	rename_thread(thread, threadname);
	resume_thread(thread);

	while ((bytesread = read(err, (void*)buffer, 1000)) > 0) {
		buffer[bytesread] = 0;
		version.Append(buffer);
		// printf("%s: %s\n",path, buffer);
		snooze(10000);
	}
	while ((bytesread = read(out, (void*)buffer, 1000)) > 0) {
		buffer[bytesread] = 0;
		version.Append(buffer);
		// printf("%s: %s\n",path, buffer);
		snooze(10000);
	}

	free(argv);
	close(in);
	close(out);
	close(err);

	char str[1024];
	int32 length = 1024;
	int32 state = 0;
	int32 srclen = version.Length();
	convert_to_utf8(B_ISO1_CONVERSION, version.String(), &srclen, str, &length, &state);

	str[length] = 0;
	version = str;

	// --version option not supported?
	if (version.FindFirst("--version") != B_ERROR) {
		version = path;
		version << ": "
				<< _T("(could not get version info)"); // "STR:(could not get version info)"
	} else {
		version.RemoveAll("\n");
		version.RemoveAll("\t");
		// for case-insensitivity replace instead of remove...
		version.IReplaceAll("Copyright ", "");
		version.IReplaceAll("(c) ", B_UTF8_COPYRIGHT);
		version.IReplaceAll("(c)", B_UTF8_COPYRIGHT);
	}
	return strdup(version.String());
}