static void deferred_renderer_use_material(material* mat, shader_program* PROG) { /* Set material parameters */ int tex_counter = 0; for(int i = 0; i < mat->keys->num_items; i++) { char* key = list_get(mat->keys, i); int* type = dictionary_get(mat->types, key); void* property = dictionary_get(mat->properties, key); GLint loc = glGetUniformLocation(shader_program_handle(PROG), key); GLint world_matrix_u = glGetUniformLocation(shader_program_handle(PROG), "world_matrix"); glUniformMatrix4fv(world_matrix_u, 1, 0, WORLD_MATRIX); GLint proj_matrix_u = glGetUniformLocation(shader_program_handle(PROG), "proj_matrix"); glUniformMatrix4fv(proj_matrix_u, 1, 0, PROJ_MATRIX); GLint view_matrix_u = glGetUniformLocation(shader_program_handle(PROG), "view_matrix"); glUniformMatrix4fv(view_matrix_u, 1, 0, VIEW_MATRIX); if (*type == mat_type_texture) { glUniform1i(loc, tex_counter); glActiveTexture(GL_TEXTURE0 + tex_counter); glBindTexture(GL_TEXTURE_2D, texture_handle(property)); tex_counter++; } else if (*type == mat_type_int) { glUniform1i(loc, *((int*)property)); } else if (*type == mat_type_float) { glUniform1f(loc, *((float*)property)); } else if (*type == mat_type_vector2) { vector2 v = *((vector2*)property); glUniform2f(loc, v.x, v.y); } else if (*type == mat_type_vector3) { vector3 v = *((vector3*)property); glUniform3f(loc, v.x, v.y, v.z); } else if (*type == mat_type_vector4) { vector4 v = *((vector4*)property); glUniform4f(loc, v.w, v.x, v.y, v.z); } else { /* Do nothing */ } } }
void eu_decode(char *operation_code) { if((Instruccion = dictionary_get(SetInstruccionesDeUsuario,operation_code)) == NULL) if(!Registros.K || (Instruccion = dictionary_get(SetInstruccionesProtegidas,operation_code)) == NULL) { puts("ERROR: Instrucción inválida."); exit(EXIT_FAILURE); } Parametros = list_create(); }
int ansisop_wait (int socket_local, int pid_local){ int* tamanioNombreWS = recibirCpu(socket_local,sizeof(int),pid_local); char* nombreSemaforo = recibirCpu(socket_local,*tamanioNombreWS,pid_local); pcb_t* pcb_elegido = recibirPCBdeCPU(socket_local,pid_local); int retorno=0; t_datos_samaforos* datos_sem; t_sock_mje* socketConsola; int esEl_Pid(pcb_t* pcb_compara) { return (*pcb_compara->PID==pid_local); } datos_sem = dictionary_get(reg_config.dic_semaforos,nombreSemaforo); pthread_mutex_lock(&datos_sem->semsem); if (datos_sem->valor > 0 && list_is_empty(datos_sem->cola_procesos)){ (datos_sem->valor)-- ; retorno=0; } else if (datos_sem->valor <= 0) { // Bloqueo el proceso pthread_mutex_lock(&sem_l_Exec); list_remove_by_condition(proc_Exec, (void*) esEl_Pid); log_debug(logger, "PCB con PID %d sacado de EXEC x bloqueo de Semaforo",pid_local); pthread_mutex_unlock(&sem_l_Exec); pthread_mutex_lock(&sem_pid_consola); socketConsola = dictionary_get(dict_pid_consola,&pid_local); pthread_mutex_unlock(&sem_pid_consola); if (socketConsola->proc_status==0){ t_pcb_bloqueado* elem_block = malloc(sizeof(t_pcb_bloqueado)); elem_block->pcb_bloqueado = pcb_elegido; elem_block->tipo_de_bloqueo = 2; elem_block->dispositivo = nombreSemaforo; elem_block->unidades = 0; pthread_mutex_lock(&sem_l_Block); // se bloquea list_add(proc_Block, elem_block); log_debug(logger, "PCB con PID %d pasado a cola BLOCK",pid_local); pthread_mutex_unlock(&sem_l_Block); sem_post(&sem_BLOCK_dispo); } else{ pthread_mutex_lock(&sem_l_Reject); list_add(proc_Reject, pcb_elegido); log_debug(logger, "PCB con PID %d pasado a REJECT xfin de consola",pid_local); pthread_mutex_unlock(&sem_l_Reject); sem_post(&sem_REJECT_dispo); } retorno = 1; // retorna 1 si se bloquea el proceso para que cambie de PCB } pthread_mutex_unlock(&datos_sem->semsem); return retorno; }
//********************************************************************************************* void *administrar_cola_Block(){ log_debug(log_procesador_Block, "administrar_cola_Block esta corriendo"); t_sock_mje* socketConsola; t_pcb_bloqueado* elem_block; t_datos_dicIO* datos_io; t_datos_samaforos* datos_sem; int pid_local = 0; while (1){ sem_wait(&sem_BLOCK_dispo); // espero que haya un proceso en BLOCK disponible log_debug(log_procesador_Block, "Se empezo a procesar un PCB de BLOCK"); pthread_mutex_lock(&sem_l_Block); elem_block=list_remove(proc_Block, 0); pid_local=*(elem_block->pcb_bloqueado->PID); log_debug(logger, "PCB con PID %d sacado de cola BLOCK",pid_local); pthread_mutex_unlock(&sem_l_Block); pthread_mutex_lock(&sem_pid_consola); socketConsola = dictionary_get(dict_pid_consola,&pid_local); pthread_mutex_unlock(&sem_pid_consola); if (socketConsola->proc_status==0){ switch((elem_block->tipo_de_bloqueo)){ case 1: // bloqueo por IO pthread_mutex_lock(&sem_reg_config); datos_io=dictionary_get(reg_config.dic_IO,elem_block->dispositivo); list_add(datos_io->cola_procesos,elem_block); sem_post(&(datos_io->sem_dispositivo)); // ver si hay que usar el & //dictionary_put(reg_config.dic_IO,elem_block->dispositivo,datos_io); //verr No hace falta hacer un put ya q cuando lo modificas //se guarda igual por ser puntero pthread_mutex_unlock(&sem_reg_config); log_debug(logger, "PCB con PID %d pasado a cola de dispositivo",pid_local); break; case 2: // bloqueo por wait datos_sem=dictionary_get(reg_config.dic_semaforos,elem_block->dispositivo); pthread_mutex_lock(&datos_sem->semsem); list_add(datos_sem->cola_procesos,elem_block); sem_post(&datos_sem->sem_semaforos); pthread_mutex_unlock(&datos_sem->semsem); log_debug(logger, "PCB con PID %d pasado a cola de semaforos",pid_local); break; } } else{ pthread_mutex_lock(&sem_l_Reject); list_add(proc_Reject, elem_block->pcb_bloqueado); log_debug(logger, "PCB con PID %d pasado a REJECT xfin de consola",pid_local); pthread_mutex_unlock(&sem_l_Reject); sem_post(&sem_REJECT_dispo); } } }
ui_elem* ui_elem_get_as_type_id(char* name, int type_id) { if ( !ui_elem_exists(name) ) { error("UI element %s does not exist!", name); } int* ui_elem_type = dictionary_get(ui_elem_types, name); if (*ui_elem_type != type_id) { error("UI element %s was created/added as a %s, but you requested it as a %s!", name, type_id_name(*ui_elem_type), type_id_name(type_id)); } return dictionary_get(ui_elems, name); }
bool ui_elem_exists(char* name) { if (dictionary_get(ui_elems, name)) { return true; } else { return false; } }
// this function is needed to change the name of a PERSON_URL REGISTRY_PERSON_URL *registry_person_url_reallocate(REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name, size_t namelen, time_t when, REGISTRY_PERSON_URL *pu) { debug(D_REGISTRY, "registry_person_url_reallocate('%s', '%s', '%s'): allocating %zu bytes", p->guid, m->guid, u->url, sizeof(REGISTRY_PERSON_URL) + namelen); // keep a backup REGISTRY_PERSON_URL pu2 = { .first_t = pu->first_t, .last_t = pu->last_t, .usages = pu->usages, .flags = pu->flags, .machine = pu->machine, .machine_name = "" }; // remove the existing one from the index registry_person_url_free(p, pu); pu = &pu2; // allocate a new one REGISTRY_PERSON_URL *tpu = registry_person_url_allocate(p, m, u, name, namelen, when); tpu->first_t = pu->first_t; tpu->last_t = pu->last_t; tpu->usages = pu->usages; tpu->flags = pu->flags; return tpu; } // ---------------------------------------------------------------------------- // PERSON REGISTRY_PERSON *registry_person_find(const char *person_guid) { debug(D_REGISTRY, "Registry: registry_person_find('%s')", person_guid); return dictionary_get(registry.persons, person_guid); }
void thread_job_function(void* param){ int fd_filesystem; extern pthread_mutex_t pedido_filesystem; t_msjcxd* mensaje_recv; t_msjcxd* mensaje_send; t_arg_thread_job* arg; arg = (t_arg_thread_job*) param; fd_filesystem = arg->fd_filesystem; mensaje_recv = recvMsj(arg->fd_job); if( strcmp(mensaje_recv->action, "conexion_cerrada") != 0 ){ // tenemos mensaje de job if( strcmp(mensaje_recv->action, "inicio_pedido") != 0 ){ pthread_mutex_lock( &pedido_filesystem ); mensaje_send = iniciarMsj("info_archivo"); agregarInfo(mensaje_send, "arch_name", dictionary_get(mensaje_recv->properties, "arch_name")); sendMsj(mensaje_send, fd_filesystem); /* Recivir info de FS */ pthread_mutex_unlock( &pedido_filesystem ); /* (...) */ } }else{ // conexión cerrada por el job // ... /*pthread_mutex_lock( &pantalla ); printf("Conexion cerrada (thread_id: %ld).\n", pthread_self()); pthread_mutex_unlock( &pantalla );*/ close(arg->fd_job); } }
REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_MACHINE *m, REGISTRY_URL *u, time_t when) { debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): searching for URL in machine", m->guid, u->url); REGISTRY_MACHINE_URL *mu = dictionary_get(m->machine_urls, u->url); if(!mu) { debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): not found", m->guid, u->url); mu = registry_machine_url_allocate(m, u, when); registry.machines_urls_count++; } else { debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): found", m->guid, u->url); mu->usages++; if(likely(mu->last_t < (uint32_t)when)) mu->last_t = (uint32_t)when; } m->usages++; if(likely(m->last_t < (uint32_t)when)) m->last_t = (uint32_t)when; if(mu->flags & REGISTRY_URL_FLAGS_EXPIRED) { debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): accessing an expired URL.", m->guid, u->url); mu->flags &= ~REGISTRY_URL_FLAGS_EXPIRED; } return mu; }
REGISTRY_PERSON *registry_person_allocate(const char *person_guid, time_t when) { debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): allocating new person, sizeof(PERSON)=%zu", (person_guid)?person_guid:"", sizeof(REGISTRY_PERSON)); REGISTRY_PERSON *p = mallocz(sizeof(REGISTRY_PERSON)); if(!person_guid) { for(;;) { uuid_t uuid; uuid_generate(uuid); uuid_unparse_lower(uuid, p->guid); debug(D_REGISTRY, "Registry: Checking if the generated person guid '%s' is unique", p->guid); if (!dictionary_get(registry.persons, p->guid)) { debug(D_REGISTRY, "Registry: generated person guid '%s' is unique", p->guid); break; } else info("Registry: generated person guid '%s' found in the registry. Retrying...", p->guid); } } else strncpyz(p->guid, person_guid, GUID_LEN); debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): creating dictionary of urls", p->guid); avl_init(&p->person_urls, person_url_compare); p->first_t = p->last_t = (uint32_t)when; p->usages = 0; registry.persons_memory += sizeof(REGISTRY_PERSON); registry.persons_count++; dictionary_set(registry.persons, p->guid, p, sizeof(REGISTRY_PERSON)); return p; }
char* obtenerDatoLimpioDelDiccionario(t_dictionary* diccionario, char* dato) { char* datoProvisorio; char* datoLimpio; datoProvisorio = dictionary_get(diccionario, dato); datoLimpio = string_substring_until(datoProvisorio,(string_length(datoProvisorio) - 1)); return datoLimpio; }
/*--------------------------------------------------------------------------*/ char * iniparser_getstring(dictionary * d, char * key, char * def) { char lc_key[ASCIILINESZ+1]; if (d==NULL || key==NULL) return def ; return dictionary_get(d, strlwc(key, lc_key), def); }
void signalRequest(t_nodo_proceso_ejecutando* procesoEjecutando, struct pollfd** socketsCPU, int* cantSocketsCpu, t_datosEnviar* paquete) { t_semaforo* semaforo = dictionary_get(dictionarySemaphores, paquete->data); debugTrackPCP("Process sent a signal request on semaphore %s .", (char*) paquete->data); semaforo_signal(semaforo); }
void ui_render() { for(int i = 0; i < ui_elem_names->num_items; i++) { char* name = list_get(ui_elem_names, i); int* type_id = dictionary_get(ui_elem_types, name); ui_elem_render(name); } }
ui_elem* ui_elem_get(char* name) { if ( !ui_elem_exists(name) ) { error("UI element %s does not exist!", name); } return dictionary_get(ui_elems, name); }
/*--------------------------------------------------------------------------*/ char dictionary_getchar(dictionary * d, char * key, char def) { char * v ; if ((v=dictionary_get(d,key,DICT_INVALID_KEY))==DICT_INVALID_KEY) { return def ; } else { return v[0] ; } }
/*--------------------------------------------------------------------------*/ int dictionary_getint(dictionary * d, char * key, int def) { char * v ; if ((v=dictionary_get(d,key,DICT_INVALID_KEY))==DICT_INVALID_KEY) { return def ; } else { return atoi(v); } }
/*--------------------------------------------------------------------------*/ double dictionary_getdouble(dictionary * d, char * key, double def) { char * v ; if ((v=dictionary_get(d,key,DICT_INVALID_KEY))==DICT_INVALID_KEY) { return def ; } else { return atof(v); } }
/*--------------------------------------------------------------------------*/ const char * iniparser_getstring(const dictionary * d, const char *section, const char * key, const char * def) { const char * sval ; if (d==NULL || key==NULL) return def ; sval = dictionary_get(d, section, key, def); return sval ; }
int com_dict_attack(char* arg) { // Not much point if we don't have any keys if (!dictionary_get()) { printf("Dictionary is empty!\n"); return -1; } mf_dictionary_attack(¤t_auth); return 0; }
void ansisop_obtenerValorCompartida(int socket_local,int pid_local){ //se recibe parametros para obtener valor int* long_char = recibirCpu(socket_local,sizeof(int),pid_local); char* variable_comp = recibirCpu(socket_local, *long_char,pid_local); int * valor_comp; pthread_mutex_lock(&varsGlobals); valor_comp = dictionary_get(reg_config.dic_variables,variable_comp); pthread_mutex_unlock(&varsGlobals); enviarCPU(socket_local,sizeof(int),valor_comp,pid_local); }
/*--------------------------------------------------------------------------*/ char * iniparser_getstring(dictionary * d, const char * key, char * def) { char * lc_key; char * sval; if (d == NULL || key == NULL) return def; lc_key = strlwc(key); sval = dictionary_get(d, lc_key, def); return sval; }
/*--------------------------------------------------------------------------*/ char * iniparser_getstrdup(const dictionary * d, const char *section, const char * key, const char * def) { const char * sval ; if (d==NULL || key==NULL) return NULL; if ((sval = dictionary_get(d, section, key, def))) return strdup(sval); return NULL; }
void ansisop_signal(int socket_local, int pid_local){ int* tamanioNombre = recibirCpu(socket_local,sizeof(int),pid_local); char* nombreSemaforo = recibirCpu(socket_local,*tamanioNombre,pid_local); t_datos_samaforos* datos_sem; datos_sem = dictionary_get(reg_config.dic_semaforos,nombreSemaforo); pthread_mutex_lock(&datos_sem->semsem); if(!list_is_empty(datos_sem->cola_procesos)) sem_post(&datos_sem->sem_valor); (datos_sem->valor)++; pthread_mutex_unlock(&datos_sem->semsem); }
void sharedVariableRequest(t_nodo_proceso_ejecutando* procesoEjecutando, struct pollfd** socketsCPU, int* cantSocketsCpu, t_datosEnviar* paquete) { t_varCompartida* varBuscada = dictionary_get(dictionarySharedVariables, (char*) paquete->data); t_datosEnviar* mensaje = pedirPaquete(&varBuscada->valor, PCP_CPU_OK, sizeof(uint32_t)); debugTrackPCP(" Request of the shared variable: %s .", mensaje->data); common_send(procesoEjecutando->cpu.socket, mensaje, NULL ); destruirPaquete(mensaje); }
/******************************************************************************* * @author : Rohan Jyoti * @name : printDir * @param : Directory to print, Keys assoc with directory * @return : void * @purpose : Print given Directory ******************************************************************************/ void printDir(dictionary_t *incomingD, queue_t *tKeys) { printf("==========DIRECTORY==========\n"); unsigned int i; for(i=0; i<queue_size(tKeys); i++) { char *currKey = (char *)queue_at(tKeys, i); queue_t *currQ = (queue_t *)dictionary_get(incomingD, currKey); printf("=====KEY: %s\n", currKey); printChunksQueue(currQ); } }
/*--------------------------------------------------------------------------*/ const char * iniparser_getstring(const dictionary * d, const char * key, const char * def) { const char * lc_key ; const char * sval ; char tmp_str[ASCIILINESZ+1]; if (d==NULL || key==NULL) return def ; lc_key = strlwc(key, tmp_str, sizeof(tmp_str)); sval = dictionary_get(d, lc_key, def); return sval ; }
void doInOut(t_nodo_proceso_ejecutando* procesoEjecutando, t_io* datos) { t_nodo_proceso_bloqueadoIO* nuevo = malloc(sizeof *nuevo); t_nodo_hiloIO* dispositivoIO = dictionary_get(dictionaryIO, datos->nombre); nuevo->espera = datos->tiempo; nuevo->proceso = copyProcessNode(&(procesoEjecutando->proceso)); debugTrackPCP("[I/O HANDLER] Blocking Process on device %s .", datos->nombre); log_debug(log_kernel, "[I/O HANDLER] Blocking Process on device %s .", datos->nombre); blockProcessIO(dispositivoIO, nuevo); }
/** * * key の値が存在していれば削除 * * @param self * @param key */ void dictionary_remove(hash *self, char *key) { hash_item *pair = dictionary_get(self, key); if (!pair) return; pair->prev ? (pair->prev->next = pair->next) : (self->head = pair->next); pair->next ? (pair->next->prev = pair->prev) : (self->tail = pair->prev); if (self->free) self->free(pair->key, pair->val); free(pair); }
int main(int argc, char* argv[]) { dictionary* d ; char* val ; int i ; char cval[90] ; /* Allocate dictionary */ printf("allocating...\n"); d = dictionary_new(0); /* Set values in dictionary */ printf("setting %d values...\n", NVALS); for (i=0 ; i<NVALS ; i++) { sprintf(cval, "%04d", i); dictionary_set(d, cval, "salut"); } printf("getting %d values...\n", NVALS); for (i=0 ; i<NVALS ; i++) { sprintf(cval, "%04d", i); val = dictionary_get(d, cval, DICT_INVALID_KEY); if (val==DICT_INVALID_KEY) { printf("cannot get value for key [%s]\n", cval); } } printf("unsetting %d values...\n", NVALS); for (i=0 ; i<NVALS ; i++) { sprintf(cval, "%04d", i); dictionary_unset(d, cval); } if (d->n != 0) { printf("error deleting values\n"); } printf("deallocating...\n"); dictionary_del(d); return 0 ; }