Exemple #1
0
void set_psc_ep_to_psc(Psc psc_to_set, Psc target_psc) {
    if (get_arity(psc_to_set) != get_arity(target_psc)) {
        xsb_abort("[IMPORT AS] Cannot import predicate as a predicate with a different arity: %s/%d\n",
                  get_name(psc_to_set),get_arity(psc_to_set));
    } else if (get_ep(psc_to_set) != (byte *)&(psc_to_set->load_inst) &&
               get_ep(psc_to_set) != (byte *)&(target_psc->load_inst)) {
        xsb_warn("[IMPORT AS] Redefining entry to import-as predicate: %s/%d\n",
                 get_name(psc_to_set),get_arity(psc_to_set));
        set_ep(psc_to_set,(byte *)&(target_psc->load_inst));
    } else {
        set_ep(psc_to_set,(byte *)&(target_psc->load_inst));
    }
}
int prolog_call0(CTXTdeclc Cell term)
{
    Psc  psc;
    if (isconstr(term)) {
      int  disp;
      char *addr;
      psc = get_str_psc(term);
      addr = (char *)(clref_val(term));
      for (disp = 1; disp <= (int)get_arity(psc); ++disp) {
	bld_copy(reg+disp, cell((CPtr)(addr)+disp));
      }
    } else if (isstring(term)) {
      int  value;
      Pair sym;
      if (string_val(term) == true_string) return TRUE; /* short-circuit if calling "true" */
      sym = insert(string_val(term),0,(Psc)flags[CURRENT_MODULE],&value);
      psc = pair_psc(sym);
    } else {
      if (isnonvar(term))
	xsb_type_error(CTXTc "callable",term,"call/1",1);
      else xsb_instantiation_error(CTXTc "call/1",1);
      return FALSE;
    }
#ifdef CP_DEBUG
    pscreg = psc;
#endif
    pcreg = get_ep(psc);
    if (asynint_val) intercept(CTXTc psc);
    return TRUE;
}
Exemple #3
0
static int cyapi_bulk_transfer(void *driver, uint8_t endpoint, void *buffer,
                              uint32_t buffer_len, uint32_t timeout_ms)
{
    bool success;
    int status = BLADERF_ERR_IO;
    CCyUSBDevice *dev = get_device(driver);
    CCyBulkEndPoint *ep = get_ep(dev, endpoint);

    if (ep != NULL) {
        LONG len = buffer_len;
        dev->ControlEndPt->TimeOut = timeout_ms ? timeout_ms : INFINITE;
        success = ep->XferData((PUCHAR)buffer, len);

        if (success) {
            if (len == buffer_len) {
                status = 0;
            } else {
                log_debug("Transfer len mismatch: %u vs %u\n",
                          (unsigned int) buffer_len, (unsigned int) len);
            }
        } else {
            log_debug("Transfered failed.\n");
        }
    } else {
        log_debug("Failed to get EP handle.\n");
    }

    return status;
}
Exemple #4
0
TIFptr get_tip(Psc temp) 
{
    CPtr temp1 ;

    switch (get_type(temp)) {
      case T_DYNA:
      case T_PRED:
	temp1 = (CPtr)get_ep(temp);
	if (temp1 != 0) {
	  switch (*(pb)temp1) {
	    case tabletry:
	    case tabletrysingle:
	      return (TIFptr) (temp1[2]) ;
	    case test_heap:
	      if (*(pb)(temp1+2) == tabletry ||
		  *(pb)(temp1+2) == tabletrysingle)
		return (TIFptr) (temp1[4]) ;
	      else return NULL;
	      break;
	    case switchon3bound:
	    case switchonbound:
	    case switchonterm:
	      if (  *(pb) (temp1+3) == tabletry 
	        ||  *(pb) (temp1+3) == tabletrysingle) 
		return (TIFptr) (temp1[5]) ;
	      else return (TIFptr) NULL;
	    default:
	      return (TIFptr) NULL;
	  }
	}
	else return (TIFptr) NULL;
      default: 
	return (TIFptr) NULL;
    }
}
Exemple #5
0
TIFptr get_tip(CTXTdeclc Psc psc) {
    TIFptr *tip = get_tip_or_tdisp(psc);
#ifndef MULTI_THREAD
    return tip?(*tip):NULL;
#else
    if (!tip) { /* get it out of dispatch table */
        CPtr temp1 = (CPtr) get_ep(psc);
        if ((get_type(psc) == T_DYNA) &&
                (*(pb)(temp1) ==  switchonthread)) {
            temp1 = dynpredep_to_prortb(CTXTc temp1);
            if (temp1 && (*(pb)temp1 == tabletrysingle) )
                return *(TIFptr *)(temp1+2);
            else return (TIFptr) NULL;
        } else {
            if (get_tabled(psc)) {
                xsb_error("Internal Error in table dispatch\n");
            } else {
                return NULL;
            }
        }
    }
    if (TIF_EvalMethod(*tip) != DISPATCH_BLOCK) return *tip;
    /* *tip points to 3rd word in TDispBlk, so get addr of TDispBlk */
    {   struct TDispBlk_t *tdispblk = (struct TDispBlk_t *) (*tip);
        TIFptr rtip = (TIFptr)((&(tdispblk->Thread0))[xsb_thread_entry]);
        if (!rtip) {
            rtip = New_TIF(CTXTc psc);
            (&(tdispblk->Thread0))[xsb_thread_entry] = rtip;
        }
        return rtip;
    }
#endif
}
Exemple #6
0
Psc synint_proc(CTXTdeclc Psc psc, int intcode)
{
  if (pflags[intcode+INT_HANDLERS_FLAGS_START]==(Cell)0) {
    /* default hard handler */
    default_inthandler(CTXTc intcode);
    psc = 0;
  } else {				/* call Prolog handler */
    switch (intcode) {
    case MYSIG_UNDEF:		/*  0 */
      SYS_MUTEX_LOCK( MUTEX_LOAD_UNDEF ) ;
    case MYSIG_KEYB:		/*  1 */
    case MYSIG_SPY:		/*  3 */
    case MYSIG_TRACE:		/*  4 */
    case THREADSIG_CANCEL:		/* f */
    case MYSIG_CLAUSE:		/* 16 */
      if (psc) bld_cs(reg+1, build_call(CTXTc psc));
      psc = (Psc)pflags[intcode+INT_HANDLERS_FLAGS_START];
      bld_int(reg+2, asynint_code);
      pcreg = get_ep(psc);
      break;
    case MYSIG_ATTV:		/*  8 */
      /* the old call must be built first */
      if (psc)
	bld_cs(reg+2, build_call(CTXTc psc));
      psc = (Psc)pflags[intcode+INT_HANDLERS_FLAGS_START];
      /*
       * Pass the interrupt chain to reg 1.  The interrupt chain
       * will be reset to 0 in build_interrupt_chain()).
       */
      bld_copy(reg + 1, build_interrupt_chain(CTXT));
      /* bld_int(reg + 3, intcode); */	/* Not really needed */
      pcreg = get_ep(psc);
      break;
    default:
      xsb_abort("Unknown intcode in synint_proc()");
    } /* switch */
  }
  return psc;
}
Exemple #7
0
static void start_ep_timer(struct iwch_ep *ep)
{
	PDBG("%s ep %p\n", __func__, ep);
	if (timer_pending(&ep->timer)) {
		PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
		del_timer_sync(&ep->timer);
	} else
		get_ep(&ep->com);
	ep->timer.expires = jiffies + ep_timeout_secs * HZ;
	ep->timer.data = (unsigned long)ep;
	ep->timer.function = ep_timeout;
	add_timer(&ep->timer);
}
Exemple #8
0
static void
start_ep_timer(struct iwch_ep *ep)
{
	CTR2(KTR_IW_CXGB, "%s ep %p", __FUNCTION__, ep);
	if (callout_pending(&ep->timer)) {
		CTR2(KTR_IW_CXGB, "%s stopped / restarted timer ep %p", __FUNCTION__, ep);
		callout_deactivate(&ep->timer);
		callout_drain(&ep->timer);
	} else {
		/*
		 * XXX this looks racy
		 */
		get_ep(&ep->com);
		callout_init(&ep->timer, 1);
	}
	callout_reset(&ep->timer, ep_timeout_secs * hz, ep_timeout, ep);
}
Exemple #9
0
TIFptr *get_tip_or_tdisp(Psc temp)
{
    CPtr temp1 ;

    switch (get_type(temp)) {
    case T_DYNA:
    case T_PRED:
        temp1 = (CPtr)get_ep(temp);
        if (temp1 != 0) {
            switch (*(pb)temp1) {
            case tabletry:
            case tabletrysinglenoanswers: /* incremental evaluation */
            case tabletrysingle:
                return (TIFptr *) (temp1+2) ;
            case test_heap:
                if (*(pb)(temp1+2) == tabletry ||
                        *(pb)(temp1+2) == tabletrysingle  ||
                        *(pb)(temp1+2) == tabletrysinglenoanswers
                   )
                    return (TIFptr *) (temp1+4) ;
                else return (TIFptr *)NULL;
                break;
            case switchon3bound:
            case switchonbound:
            case switchonterm:
                if (  *(pb) (temp1+3) == tabletry
                        ||  *(pb) (temp1+3) == tabletrysingle
                        ||  *(pb) (temp1+3) == tabletrysinglenoanswers
                   )
                    return (TIFptr *) (temp1+5) ;
                else return (TIFptr *) NULL;
            default:
                return (TIFptr *) NULL;
            }
        }
        else return (TIFptr *) NULL;
    default:
        return (TIFptr *) NULL;
    }
}
Exemple #10
0
static int cyapi_stream(void *driver, struct bladerf_stream *stream,
                       bladerf_module module)
{
    int status;
    int idx = 0;
    long len;
    void *next_buffer;
    ULONG timeout_ms;
    bool success, done;
    struct stream_data *data = get_stream_data(stream);
    struct bladerf_cyapi *cyapi = get_backend_data(driver);
    struct bladerf_metadata meta;

    assert(stream->dev->transfer_timeout[stream->module] <= ULONG_MAX);
    if (stream->dev->transfer_timeout[stream->module] == 0) {
        timeout_ms = INFINITE;
    } else {
        timeout_ms = stream->dev->transfer_timeout[stream->module];
    }

    switch (module) {
        case BLADERF_MODULE_RX:
            data->ep = get_ep(cyapi->dev, SAMPLE_EP_IN);
            break;

        case BLADERF_MODULE_TX:
            data->ep = get_ep(cyapi->dev, SAMPLE_EP_OUT);
            break;

        default:
            assert(!"Invalid module");
            return BLADERF_ERR_UNEXPECTED;
    }

    if (data->ep == NULL) {
        log_debug("Failed to get EP handle.\n");
        return BLADERF_ERR_UNEXPECTED;
    }

    data->ep->XferMode = XMODE_DIRECT;
    data->ep->Abort();
    data->ep->Reset();

    log_verbose("Starting stream...\n");
    status = 0;
    done = false;
    memset(&meta, 0, sizeof(meta));

    MUTEX_LOCK(&stream->lock);

    for (unsigned int i = 0; i < data->num_transfers && status == 0; i++) {
        if (module == BLADERF_MODULE_TX) {
            next_buffer = stream->cb(stream->dev, stream, &meta, NULL,
                                     stream->samples_per_buffer,
                                     stream->user_data);

            if (next_buffer == BLADERF_STREAM_SHUTDOWN) {
                done = true;
                break;
            } else if (next_buffer == BLADERF_STREAM_NO_DATA) {
                continue;
            }
        } else {
            next_buffer = stream->buffers[i];
        }

        status = submit_transfer(stream, next_buffer);
    }

    MUTEX_UNLOCK(&stream->lock);
    if (status != 0) {
        goto out;
    }

    while (!done) {
        struct transfer *xfer;
        size_t i;

        i = data->inflight_i;
        xfer = &data->transfers[i];
        success = data->ep->WaitForXfer(&xfer->event, timeout_ms);

        if (!success) {
            status = BLADERF_ERR_TIMEOUT;
            log_debug("Steam timed out.\n");
            break;
        }

        len = 0;
        next_buffer = NULL;

        log_verbose("Got transfer complete in slot %u (buffer %p)\n",
                    i, data->transfers[i].buffer);

        MUTEX_LOCK(&stream->lock);
        success = data->ep->FinishDataXfer(data->transfers[i].buffer, len,
                                           &data->transfers[i].event,
                                           xfer->handle);

        if (success) {
            next_buffer = stream->cb(stream->dev, stream, &meta,
                                     data->transfers[i].buffer,
                                     bytes_to_samples(stream->format, len),
                                     stream->user_data);

        } else {
            done = true;
            status = BLADERF_ERR_IO;
            log_debug("Failed to finish transfer %u, buf=%p.\n",
                      (unsigned int)i, &data->transfers[i].buffer);
        }

        data->transfers[i].buffer = NULL;
        data->transfers[i].handle = NULL;
        data->num_avail++;
        pthread_cond_signal(&stream->can_submit_buffer);

        if (next_buffer == BLADERF_STREAM_SHUTDOWN) {
            done = true;
        } else if (next_buffer != BLADERF_STREAM_NO_DATA) {
            status = submit_transfer(stream, next_buffer);
            done = (status != 0);
        }

        data->inflight_i = next_idx(data, data->inflight_i);
        MUTEX_UNLOCK(&stream->lock);
    }

out:

    MUTEX_LOCK(&stream->lock);
    stream->error_code = status;
    stream->state = STREAM_SHUTTING_DOWN;

    data->ep->Abort();
    data->ep->Reset();


    for (unsigned int i = 0; i < data->num_transfers; i++) {
        LONG len = 0;
        if (data->transfers[i].handle != NULL) {
            data->ep->FinishDataXfer(data->transfers[i].buffer, len,
                                     &data->transfers[i].event,
                                     data->transfers[i].handle);


            data->transfers[i].buffer = NULL;
            data->transfers[i].handle = NULL;
            data->num_avail++;
        }
    }

    assert(data->num_avail == data->num_transfers);

    stream->state = STREAM_DONE;
    log_verbose("Stream done (error_code = %d)\n", stream->error_code);
    MUTEX_UNLOCK(&stream->lock);

    return 0;
}