Example #1
0
void* SkTLS::Get(CreateProc createProc, DeleteProc deleteProc) {
    if (nullptr == createProc) {
        return nullptr;
    }

    void* ptr = SkTLS::PlatformGetSpecific(true);

    if (ptr) {
        const SkTLSRec* rec = (const SkTLSRec*)ptr;
        do {
            if (rec->fCreateProc == createProc) {
                SkASSERT(rec->fDeleteProc == deleteProc);
                return rec->fData;
            }
        } while ((rec = rec->fNext) != nullptr);
        // not found, so create a new one
    }

    // add a new head of our change
    SkTLSRec* rec = new SkTLSRec;
    rec->fNext = (SkTLSRec*)ptr;

    SkTLS::PlatformSetSpecific(rec);

    rec->fData = createProc();
    rec->fCreateProc = createProc;
    rec->fDeleteProc = deleteProc;
    return rec->fData;
}
Example #2
0
File: pstree.c Project: dima74/akos
void add(const char *path)
{
	char stat_path[256];
	strcpy(stat_path, path);
	strcat(stat_path, "/stat");
	FILE* stat = fopen(stat_path, "r");
	struct proc curr = createProc(stat);
	//printf("%d %s %c %d\n", curr.pid, curr.name, curr.state, curr.ppid);
	fclose(stat);
}
int main(int argc, char * argv[]){
 	ARGS args;
	pid_t *pid;
	int i = 0;
	char buf[4096];

	parseArgs(argc, argv, &args);
	validateArgs(&args);

	init(args.n_proc);

	pid = (pid_t*)malloc(sizeof(pid_t) * args.n_proc); 	
	createProc(args.n_proc, pid);

	//KILLOVANIE deti
	sigset_t set;
	int sig_num;

	sigemptyset(&set);
	sigaddset(&set, SIGINT);
	CHECK(sigprocmask(/*SIG_BLOCK*/ SIG_SETMASK, &set, NULL) == 0);
	CHECK(sigwait(&set, &sig_num) == 0);

	for(i = 0; i < args.n_proc; i++){
		CHECK(kill(pid[i], SIGUSR1) == 0 );
	}

	for(i = 0; i < args.n_proc; i++){
		CHECK(wait(NULL) != -1);	
	}

	read_((char*)&buf);
	fprintf(stderr, "%s\n", buf);
	
	teardown();
	free(pid);
	printf("detske procesy ukoncene\n");
	return EXIT_SUCCESS;
}