예제 #1
0
void
glx_ctx_push_thread_local(VdpDeviceData *deviceData)
{
    glx_ctx_lock();
    Display *dpy = deviceData->display;
    const Window wnd = deviceData->root;
    thread_id_t thread_id = get_current_thread_id();

    ctx_stack.dpy = glXGetCurrentDisplay();
    if (!ctx_stack.dpy)
        ctx_stack.dpy = dpy;
    ctx_stack.wnd =     glXGetCurrentDrawable();
    ctx_stack.glc =     glXGetCurrentContext();
    ctx_stack.element_count ++;

    struct val_s *val = g_hash_table_lookup(glc_hash_table, GSIZE_TO_POINTER(thread_id));
    if (!val) {
        GLXContext glc = glXCreateContext(dpy, root_vi, root_glc, GL_TRUE);
        assert(glc);
        val = make_val(dpy, glc);
        g_hash_table_insert(glc_hash_table, GSIZE_TO_POINTER(thread_id), val);

        // try cleanup expired entries
        g_hash_table_foreach_remove(glc_hash_table, is_thread_expired, NULL);
    }
    assert(val->dpy == dpy);

    glXMakeCurrent(dpy, wnd, val->glc);
}
예제 #2
0
int main(int argc, char **argv)
{
  int num = atoi(argv[1]);
  int upp = atoi(argv[2]);
  int len = atoi(argv[3]);

  if ( make_val(NUM-1, UPP-1, LENGTH-1) == -1 ) {
    puts("Error");
  }

  printf("%d\n", sq_parti2(num, upp, len));

  return 0;
}
예제 #3
0
int main(int argc, char **argv)
{
  int num;
  int upp;
  int len;
  int val_num;
  int val_upp;
  int val_len;
  int n = 10000;
  clock_t start, end;

  if ( argc < 6 ) {
    puts("num upp len val_num val_upp val_len");
    return 0;
  }

  num = atoi(argv[1]);
  upp = atoi(argv[2]);
  len = atoi(argv[3]);
  val_num = atoi(argv[4]);
  val_upp = atoi(argv[5]);
  val_len = atoi(argv[6]);

  start = clock();
  while ( n-- ) {
    if ( make_val(val_num, val_upp, val_len) == -1 ) {
      puts("Error");
      return 0;
    }

    sq_parti2(num, upp, len);
  }
  end = clock();

  printf("%lf s\n", (end-start+0.0)/CLOCKS_PER_SEC);

  return 0;
}
예제 #4
0
파일: var_comp.c 프로젝트: koder77/NanoVM
U1 getvarstr_comp (U1 *argstr, S2 pos_start)
{
    S2 pos, pos_end, endvn, dimstart, dimend;
    S4 varind, dims;
    U1 pstr[MAXLINELEN + 1], comm[2], dimensstr[MAXLINELEN + 1], private_var = NORMAL_VAR;
    U1 ok = FALSE;

    U1 varname[MAXLINELEN + 1];
    U1 buf[MAXLINELEN + 1];

    comm[0] = AROPEN_SB;
    comm[1] = BINUL;

     /* bugfix */
    pos_start = 0;
    pos_end = strlen (argstr) - 1;

    endvn = searchstr (argstr, comm, pos_start, pos_end, TRUE);
    if (endvn != -1)
    {
        if (argstr[0] != '_')
        {
            partstr (argstr, varname, pos_start, endvn - 1);
            strcat (varname, AT_SB);
            strcat (varname, function[function_ind].name);
            partstr (argstr, buf, endvn, pos_end);
            strcat (varname, buf);
        }
        else
        {
            partstr (argstr, varname, pos_start, pos_end);
        }
    }
    else
    {
        if (argstr[0] != '_')
        {
            strcpy (varname, argstr);
            strcat (varname, AT_SB);
            strcat (varname, function[function_ind].name);
        }
        else
        {
            /* global variable starting with "_": exp: _foobar */
            strcpy (varname, argstr);
        }
    }

    t_var.dims = NODIMS;
    pos_end = strlen (varname) - 1;

    if (varname[0] == PRIVATE_VAR_SB)
    {
        /* use pvarlist for dimens */

        private_var = PRIVATE_VAR;

        #if DEBUG
            printf ("getvarstr: PRIVATE_VAR SET\n");
        #endif
    }

    partstr (varname, pstr, pos_start, pos_end);

    #if DEBUG
        printf ("getvarstr: argstr: '%s'\n", varname);
    #endif

    /* bugfix */
    pos_start = 0;
    pos_end = strlen (pstr) - 1;

    endvn = searchstr (pstr, comm, pos_start, pos_end, TRUE);
    if (endvn != -1)
    {
        /* area variable, exp. a[5][x] */

        dimstart = endvn;
        endvn--;
        dims = NODIMS;

        while (! ok)
        {
            comm[0] = ARCLOSE_SB;
            comm[1] = BINUL;

            dimend = searchstr (pstr, comm, dimstart + 1, pos_end, TRUE);
            if (dimend != -1)
            {
                if (dims < MAXDIMENS - 1)
                {
                    dims++;
                }
                else
                {
                    printerr (OVERFLOW_IND, plist_ind, ST_PRE, t_var.varname);
                    return (FALSE);
                }

                /*  getstr (U1 *str, U1 *retstr, S2 maxlen, S2 start, S2 end) */

                if (private_var == NORMAL_VAR)
                {
                    getstr (pstr, dimensstr, MAXLINELEN, dimstart + 1, dimend - 1);
                    if (checkdigit (dimensstr) == TRUE)
                    {
                        if (! make_val (INT_VAR, varlist, NORMAL_VAR))
                        {
                            printerr (MEMORY, plist_ind, ST_PRE, t_var.varname);
                            return (FALSE);
                        }
                        t_var.dimens[dims] = t_var.varlist_ind;
                    }
                    else
                    {
                        /* variable, */
                        /* check if already defined */

                        varind = getvarind_comp (dimensstr);
                        if (varind != -1)
                        {
                            if (varlist[varind].type != STRING_VAR && varlist[varind].type != BYTE_VAR)
                            {
                                t_var.dimens[dims] = varind;
                            }
                            else
                            {
                                /* error: its a string or byte var */

                                printerr (WRONG_VARTYPE, plist_ind, ST_PRE, dimensstr);
                                return (FALSE);
                            }
                        }
                        else
                        {
                            printerr (NOTDEF_VAR, plist_ind, ST_PRE, dimensstr);
                            return (FALSE);
                        }
                    }
                }
                else
                {
                    /* private variable */

                    #if DEBUG
                        printf ("getvarstr: PRIVATE VAR!");
                    #endif

                    getstr (pstr, dimensstr, MAXLINELEN, dimstart + 1, dimend - 1);
                    if (checkdigit (dimensstr) == TRUE)
                    {
                        if (! make_val (INT_VAR, pvarlist_obj, PRIVATE_VAR))
                        {
                            printerr (MEMORY, plist_ind, ST_PRE, t_var.varname);
                            return (FALSE);
                        }
                        t_var.dimens[dims] = t_var.varlist_ind;

                        #if DEBUG
                            printf ("getvarstr: PRIVATE VAR: %li", t_var.varlist_ind);
                        #endif
                    }
                    else
                    {
                        /* variable, */
                        /* check if already defined */

                        varind = getvarind_comp (dimensstr);
                        if (varind != -1)
                        {
                            if (pvarlist_obj[varind].type != STRING_VAR && pvarlist_obj[varind].type != BYTE_VAR)
                            {
                                t_var.dimens[dims] = varind;
                            }
                            else
                            {
                                /* error: its a string or byte var */

                                printerr (WRONG_VARTYPE, plist_ind, ST_PRE, dimensstr);
                                return (FALSE);
                            }
                        }
                        else
                        {
                            printerr (NOTDEF_VAR, plist_ind, ST_PRE, dimensstr);
                            return (FALSE);
                        }
                    }
                }
            }
            else
            {
                /* no ] */

                printerr (BRNOT_OK, plist_ind, ST_PRE, "");
                return (FALSE);
            }

            comm[0] = AROPEN_SB;
            comm[1] = BINUL;

            if (dimend < pos_end)
            {
                pos = searchstr (pstr, comm, dimend + 1, pos_end, TRUE);
                if (pos != -1)
                {
                    dimstart = pos;
                }
                else
                {
                    ok = TRUE;
                }
            }
            else
            {
                ok = TRUE;
            }
        }
        getstr (pstr, t_var.varname, MAXVARNAME, pos_start, endvn);
        t_var.dims = dims;

        #if DEBUG
            printf ("getvarstr: dims = %li\n", dims);
        #endif
    }
    else
    {
        getstr (pstr, t_var.varname, MAXVARNAME, pos_start, pos_end);
    }
    return (TRUE);
}