Пример #1
0
/*
 * The first time nsdispatch is called (during a process's lifetime,
 * or after nsswitch.conf has been updated), nss_configure will
 * prepare global data needed by NSS.
 */
static int
nss_configure(void)
{
    static pthread_mutex_t conf_lock = PTHREAD_MUTEX_INITIALIZER;
    static time_t	 confmod;
    struct stat	 statbuf;
    int		 result, isthreaded;
    const char	*path;
#ifdef NS_CACHING
    void		*handle;
#endif

    result = 0;
    isthreaded = __isthreaded;
#if defined(_NSS_DEBUG) && defined(_NSS_SHOOT_FOOT)
    /* NOTE WELL:  THIS IS A SECURITY HOLE. This must only be built
     * for debugging purposes and MUST NEVER be used in production.
     */
    path = getenv("NSSWITCH_CONF");
    if (path == NULL)
#endif
        path = _PATH_NS_CONF;
    if (stat(path, &statbuf) != 0)
        return (0);
    if (statbuf.st_mtime <= confmod)
        return (0);
    if (isthreaded) {
        result = _pthread_mutex_trylock(&conf_lock);
        if (result != 0)
            return (0);
        (void)_pthread_rwlock_unlock(&nss_lock);
        result = _pthread_rwlock_wrlock(&nss_lock);
        if (result != 0)
            goto fin2;
    }
    _nsyyin = fopen(path, "re");
    if (_nsyyin == NULL)
        goto fin;
    VECTOR_FREE(_nsmap, &_nsmapsize, sizeof(*_nsmap),
                (vector_free_elem)ns_dbt_free);
    VECTOR_FREE(_nsmod, &_nsmodsize, sizeof(*_nsmod),
                (vector_free_elem)ns_mod_free);
    nss_load_builtin_modules();
    _nsyyparse();
    (void)fclose(_nsyyin);
    vector_sort(_nsmap, _nsmapsize, sizeof(*_nsmap), string_compare);
    if (confmod == 0)
        (void)atexit(nss_atexit);
    confmod = statbuf.st_mtime;

#ifdef NS_CACHING
    handle = libc_dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
    if (handle != NULL) {
        nss_cache_cycle_prevention_func = dlsym(handle,
                                                "_nss_cache_cycle_prevention_function");
        dlclose(handle);
    }
#endif
fin:
    if (isthreaded) {
        (void)_pthread_rwlock_unlock(&nss_lock);
        if (result == 0)
            result = _pthread_rwlock_rdlock(&nss_lock);
    }
fin2:
    if (isthreaded)
        (void)_pthread_mutex_unlock(&conf_lock);
    return (result);
}
Пример #2
0
void ecl_rft_node_inplace_sort_cells( ecl_rft_node_type * rft_node ) {
  vector_sort( rft_node->cells , ecl_rft_cell_cmp__ );
  rft_node->sort_perm_in_sync = false;  // The permutation is no longer sorted; however the vector itself is sorted ....
}
Пример #3
0
size_t
sen_render_flush(int clear_buff)
{
//  gl_check_error();
  //_logfi("1");
  blend_group_t* bg;
  khint_t i,k,j;
  size_t total = 0;
  khash_t(hmsp)*  tgs;
  camera_t* cam = sen_camera();
  tex_group_t* tg;
  khash_t(hmsp)* sgs;
  shader_group_t* sg;

  vector_clear(zsorter);
  for (k = kh_begin(g_bgs); k != kh_end(g_bgs); ++k)
  {
    if (!kh_exist(g_bgs,k)) continue;
    bg = kh_val(g_bgs, k);

    if (bg->num == 0) {
      kh_del(hmip,g_bgs,k);
      continue;
    }
    tgs = bg->tgs;

   // set_blending( (blend_func) (kh_key(g_bgs, k))  );

    for (i = kh_begin(tgs); i != kh_end(tgs); ++i)
    {
      if (!kh_exist(tgs,i)) continue;
      tg = kh_val(tgs, i);
      if (tg->num == 0) {
        kh_del(hmsp,tgs,i);
        continue;
      }

      /*
      if (tg->tex)
        sen_texture_bind(tg->tex);
      else if (tg->font)
        sen_font_bind(tg->font);
        */

      sgs = tg->sgs;

      for (j = kh_begin(sgs); j != kh_end(sgs); ++j)
      {
        if (!kh_exist(sgs,j)) continue;
        sg = kh_val(sgs, j);
        if (sg->num == 0 || !sg->buff) {
          kh_del(hmsp,sgs,j);
          continue;
        }
        if (sg->buff) {
          /*
          sen_shader_use(sg->program);
          {
            if (tg->tex || tg->font)
              sen_uniform_1iN(sg->program, "u_tex0", 0);
            sen_uniform_m4fN(sg->program, "u_mvp",  cam->view_proj.data);
            vertex_buffer_render( sg->buff, GL_TRIANGLES);
            total+=vertex_buffer_size(sg->buff);
            if (clear_buff)
              vertex_buffer_clear( sg->buff );
            //sen_shader_use(NULL);
          }*/
          vector_push_back( zsorter, &sg );
        }
        sg->num = 0;
      }
      tg->num = 0;
    }
    bg->num = 0;
  }
  if (zsorter->size > 0)
    vector_sort(zsorter, zcmp);

  for (j = 0; j < zsorter->size; j++) {
    shader_group_t* sg = *(shader_group_t**)vector_get(zsorter, j);
   // _logfi("%s %d",sg->name, sg->z);


    set_blending( (blend_func) (sg->bg->key)  );


    if (sg->tg->tex)
      sen_texture_bind(sg->tg->tex);
    else if (sg->tg->font)
      sen_font_bind(sg->tg->font);

    sen_shader_use(sg->program);
    {

      if (sg->tg->tex || sg->tg->font)
        sen_uniform_1iN(sg->program, "u_tex0", 0);
      sen_uniform_m4fN(sg->program, "u_mvp", sg->z > 9500 ? cam->proj.data  : cam->view_proj.data);
      vertex_buffer_render( sg->buff, GL_TRIANGLES);
      total+=vertex_buffer_size(sg->buff);
      if (clear_buff)
        vertex_buffer_clear( sg->buff );

      //sen_shader_use(NULL);
    }
  }

 // _logfi("-------------------------------------------------");
  return total;
}
Пример #4
0
int main(int argc, char **argv)
{
    vector *v;
    string *s;
    string **tmp;
    string *sup;
    int i;

    v = vector_init(stcmp);
    sup = string_init_cstring("6");

    while(--argc)
    {
        s = string_init_cstring(argv[argc]);
        vector_append(v, s);
    }

    printf("size: %d\n", v->len);

    printf("---\n");

    /* Print. */
    for(i = 0; i < v->len; ++i)
        string_println(vector_get(v, i));

    printf("---\n");

    /* Sort and print again. */
    vector_sort(v);
    for(i = 0; i < v->len; ++i)
        string_println(vector_get(v, i));

    printf("---\n");

    /* Search for sup. */
    if(vector_index(v, sup) != -1)
        string_print(sup), printf(" found.\n");
    else
        string_print(sup), printf(" not found.\n");

    printf("---\n");

    /* Using bsearch. */
    tmp = vector_search(v, sup);

    if(tmp)
    {
        string_print(*tmp);
        printf(" found using bsearch.\n");
    }
    else
    {
        string_print(sup);
        printf(" bsearch failed.\n");
    }

    printf("---\n");

    /* Shuffle and print again. */
    vector_shuffle(v);

    for(i = 0; i < v->len; ++i)
        string_println(vector_get(v, i));

    printf("---\n");

    for(i = 0; i < v->len; ++i)
        string_free(vector_get(v, i));

    string_free(sup);
    vector_free(v);

    return 0;
}