Exemplo n.º 1
0
Arquivo: main.cpp Projeto: lhmouse/MCF
int __stdcall dlltest(int a, int b) noexcept {
	auto f = [](Utf8String s){
		std::printf("thread %u: tls = %s\n", (unsigned)::GetCurrentThreadId(), GetString().GetStr());
		GetString() = std::move(s);
		std::printf("thread %u: tls = %s\n", (unsigned)::GetCurrentThreadId(), GetString().GetStr());
	};

	Thread t;
	t.Create(Bind(f, "world"_u8s), false);
	f("hello"_u8s);
	t.Join();

	return a + b;
}
Exemplo n.º 2
0
void Thread::Startup() {
    threads.init();
    threads.setMax(MAX_THREADS);

    Thread* main = (Thread*)malloc(
            sizeof(Thread)*1);
    main->main = &env->methods[manifest.entryMethod];
    main->Create("Main");
#ifdef WIN32_
    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
    SetPriorityClass(GetCurrentThread(), HIGH_PRIORITY_CLASS);
#endif
    setupSigHandler();
}
Exemplo n.º 3
0
int APIENTRY WinMain(HINSTANCE hInstance, 
					 HINSTANCE hPrevInstance,
		 			 LPSTR lpszCmdLine, 
					 int cmdShow)
{
    HANDLE runOnceMutex = NULL;
    bool   allowMultipleInst = false;

    g_hinst = hInstance;

    // should we allow FreeAmp to run?
    struct stat st;
    char path[MAX_PATH];
    char arg0[MAX_PATH];

    getcwd(path, sizeof(path));

    strcpy(arg0, __argv[0]);
    char* slash = strrchr(arg0, '\\');

    if(slash)
    {
        *slash = 0x00;

        if(strcasecmp(path, arg0))
        {
            chdir(arg0);
            strcpy(path, arg0);
        }
    }

    strcat(path, "\\NeedToRebootForUpdate");
    if(!stat(path, &st))
    {
        MessageBox(NULL, kReboot, "You Need To Reboot...", 
                            MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND);
        return 0;
    }

    FAContext *context = new FAContext;
    context->prefs = new Win32Prefs();
    context->prefs->GetPrefBoolean(kAllowMultipleInstancesPref, &allowMultipleInst);
    context->hInstance = hInstance;

	if (!allowMultipleInst)
    {
	   if(SendCommandLineToRealJukebox())
	   {
           return 0;
	   }

       runOnceMutex = CreateMutex(	NULL,
	    						    TRUE,
		    					    The_BRANDING" Should Only Run One Time!");

       if(GetLastError() == ERROR_ALREADY_EXISTS)
	   { 
           SendCommandLineToHiddenWindow();
        
           CloseHandle(runOnceMutex);
           return 0;
	   }
	}
    // This causes a dynamic link error on some non NT systems, and
    // it didn't seem to help on multiprocessor NT systems, so I'm
    // commenting it.
    //if(IsWinNT() && IsMultiProcessor())
    //    SetProcessAffinityMask(GetCurrentProcess(), 0);

    WSADATA sGawdIHateMicrosoft;
    WSAStartup(0x0002,  &sGawdIHateMicrosoft);


    context->log = new LogFile("freeamp.log");

    // find all the plug-ins we use
    Registrar* registrar;
    Registry* lmc;
    Registry* pmi;
    Registry* pmo;
    Registry*  ui;

    registrar = new Registrar;

    registrar->SetSubDir("plugins");
    registrar->SetSearchString("*.lmc");
    lmc = new Registry;
    registrar->InitializeRegistry(lmc, context->prefs);

    registrar->SetSearchString("*.pmi");
    pmi = new Registry;
    registrar->InitializeRegistry(pmi, context->prefs);

    registrar->SetSearchString("*.pmo");
    pmo = new Registry;
    registrar->InitializeRegistry(pmo, context->prefs);

    registrar->SetSearchString("*.ui");
    ui = new Registry;
    registrar->InitializeRegistry(ui, context->prefs);

    delete registrar;

    bool reclaimFileTypes, askBeforeReclaiming;
    uint32 length = sizeof(path);
    context->prefs->GetPrefBoolean(kReclaimFiletypesPref, &reclaimFileTypes);
    context->prefs->GetPrefBoolean(kAskToReclaimFiletypesPref, &askBeforeReclaiming);
    context->prefs->GetPrefString(kInstallDirPref, path, &length);
    strcat(path, "\\freeamp.exe");

    if(reclaimFileTypes)
        ReclaimFileTypes(path, askBeforeReclaiming);

    // create the player
	Player *player = Player::GetPlayer(context);

    // we are the first instance so create our hidden window
    Thread* thread = Thread::CreateThread();

    thread->Create(CreateHiddenWindow, context);

    // need a way to signal main thread to quit...
    Semaphore *termination = new Semaphore();
    
    // register items... we give up ownership here
    player->SetTerminationSemaphore(termination);
    player->RegisterLMCs(lmc);
    player->RegisterPMIs(pmi);
    player->RegisterPMOs(pmo);
    player->RegisterUIs(ui);

    // Let the player know if there are special requests from the user
    // __argc and __argv are magical variables provided for us
    // in MS's STDLIB.H file. 
    player->SetArgs(__argc, __argv);

    // kick things off... player is now in charge!
    player->Run();

    // sit around and twiddle our thumbs
    termination->Wait();

    // clean up our act
    delete player;
	delete context;
    delete thread;

	if (!allowMultipleInst)
       CloseHandle(runOnceMutex);

	WSACleanup();

	return 0;
}
Exemplo n.º 4
0
void* Thread::Create(void* arg)
{
	Thread* th = static_cast<Thread*>(arg);
	th->Create();
        return 0;
}