示例#1
0
// Runs into main thread
static int particles_new(lua_State *L)
{
	const char *name_def = luaL_checkstring(L, 1);
	const char *args = luaL_checkstring(L, 2);
	// float zoom = luaL_checknumber(L, 3);
	int density = luaL_checknumber(L, 4);
	GLuint *texture = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 5);
	shader_type *s = NULL;
	if (lua_isuserdata(L, 6)) s = (shader_type*)lua_touserdata(L, 6);
	bool fboalter = lua_toboolean(L, 7);

	particles_type *ps = (particles_type*)lua_newuserdata(L, sizeof(particles_type));
	auxiliar_setclass(L, "core{particles}", -1);

	ps->lock = SDL_CreateMutex();
	ps->name_def = strdup(name_def);
	ps->args = strdup(args);
	ps->density = density;
	ps->alive = TRUE;
	ps->i_want_to_die = FALSE;
	ps->l = NULL;
	ps->texcoords = NULL;
	ps->vertices = NULL;
	ps->colors = NULL;
	ps->particles = NULL;
	ps->init = FALSE;
	ps->texture = *texture;
	ps->shader = s;
	ps->fboalter = fboalter;
	ps->sub = NULL;

	thread_add(ps);
	return 1;
}
示例#2
0
文件: thread.c 项目: Jarlene/ADBI-1
thread_t * thread_create(process_t * process, pid_t pid) {
    thread_t * thread = adbi_malloc(sizeof(struct thread_t));
    
    thread->pid = pid;
    thread->process = process;
    
    /* set default state -- it may need to be adjusted */
    thread->state.setoptions = true;
    thread->state.running = false;
    thread->state.execed = false;
    thread->state.stopme = false;
    thread->state.slavemode = false;
    thread->state.dead = false;
    
    thread->notified = true;

    thread->state.signo = 0;
    
    /* there are two references: one on the thread list and one on the process thread list */
    thread->references = 1;
    
    process_dup(process);   /* the thread holds a pointer to the process, protect it */
    thread_add(thread);
    
    debug("Created thread %s.", str_thread(thread));
    return thread;
}
示例#3
0
static const char *
rdv_peel_pow(void) {
	const char	*response = NULL;
	unsigned int	pc = rdv_attempts2percent();

	if (l_pow_thread_started == 0) {
		/* Start the POW thread */
		if (thread_add("RendezvousPOW", rdv_pow_worker, NULL)) {
			l_pow_thread_started = 1;
			response = rdv_make_pow_response(pc,
				"OK the Proof-Of-Work has commenced");
		} else {
			response = rdv_make_peel_response("",
				"Creating the Proof-Of-Work failed :-(");
		}

	} else {
		/*
		 * Monitor the progress of the thread;
		 * or do the current <--> inner switch
		 */
		if (l_pow_thread_finished == 0) {
			response = rdv_make_pow_response(pc,
				   "Working away...");
		} else {
			if (l_pow_inner_onion == NULL) {
				response = rdv_make_peel_response("",
					"Proof of work FAILED?!?");
			} else {
				response = rdv_make_pow_response(100,
					"Your Proof-Of-Work has "
					"finished successfully!");

				/* Free the old onion */
				free_onion(l_current_onion);

				/* This is the new one */
				l_current_onion = l_pow_inner_onion;

				l_pow_inner_onion = NULL;
				rdv_pow_reset();
			}
		}
	}

	return (response);
}
示例#4
0
/**
 * The function creates the IMAP thread. It doesn't start the thread
 * if it is already started.
 *
 * @return whether the thread has been started.
 */
static int imap_start_thread(void)
{
	if (imap_thread) return 1;
	imap_thread = thread_add(IMAP_THREAD_NAME, THREAD_FUNCTION(&imap_thread_entry),NULL);
	return !!imap_thread;
}