Пример #1
0
void odisplay_output_bundle(t_odisplay *x)
{
	// the use of critical sections is a little weird here, but correct.
	critical_enter(x->lock);
	if(x->bndl_s){
		t_osc_bndl_s *b = x->bndl_s;
		long len = osc_bundle_s_getLen(b);
		char *ptr = osc_bundle_s_getPtr(b);
		char buf[len];
		memcpy(buf, ptr, len);
		critical_exit(x->lock);
		omax_util_outletOSC(x->outlet, len, buf);
        OSC_MEM_INVALIDATE(buf);
		return;
	}
	critical_exit(x->lock);

	char buf[OSC_HEADER_SIZE];
	memset(buf, '\0', OSC_HEADER_SIZE);
	osc_bundle_s_setBundleID(buf);
	omax_util_outletOSC(x->outlet, OSC_HEADER_SIZE, buf);
    OSC_MEM_INVALIDATE(buf);
}
Пример #2
0
/*
 * A free operation has occurred -- update malloc type statistics for the
 * amount of the bucket size.  Occurs within a critical section so that the
 * thread isn't preempted and doesn't migrate while updating per-CPU
 * statistics.
 */
void
malloc_type_freed(struct malloc_type *mtp, unsigned long size)
{
	struct malloc_type_internal *mtip;
	struct malloc_type_stats *mtsp;

	critical_enter();
	mtip = mtp->ks_handle;
	mtsp = &mtip->mti_stats[curcpu];
	mtsp->mts_memfreed += size;
	mtsp->mts_numfrees++;

	critical_exit();
}
Пример #3
0
SpiFlashOpResult IRAM spi_flash_erase_sector(uint16_t sec)
{
    CHECK_PARAM_RET (sec < flashchip->chip_size / flashchip->sector_size, SPI_FLASH_RESULT_ERR);

    critical_enter ();
    Cache_Read_Disable();

    SpiFlashOpResult ret = SPIEraseSector (sec);

    Cache_Read_Enable(0, 0, 1);
    critical_exit ();

    return ret;
}
void
update_gdt_fsbase(struct thread *td, uint32_t base)
{
	struct user_segment_descriptor *sd;

	if (td != curthread)
		return;
	td->td_pcb->pcb_full_iret = 1;
	critical_enter();
	sd = PCPU_GET(fs32p);
	sd->sd_lobase = base & 0xffffff;
	sd->sd_hibase = (base >> 24) & 0xff;
	critical_exit();
}
Пример #5
0
/*
 * A very short dispatch, to try and maximise assembler code use
 * between all exception types. Maybe 'true' interrupts should go
 * here, and the trap code can come in separately
 */
void
powerpc_interrupt(struct trapframe *framep)
{
	struct thread *td;
	struct trapframe *oldframe;
	register_t ee;

	td = curthread;

	CTR2(KTR_INTR, "%s: EXC=%x", __func__, framep->exc);

	switch (framep->exc) {
	case EXC_EXI:
		critical_enter();
		PIC_DISPATCH(root_pic, framep);
		critical_exit();
		break;

	case EXC_DECR:
		critical_enter();
		atomic_add_int(&td->td_intr_nesting_level, 1);
		oldframe = td->td_intr_frame;
		td->td_intr_frame = framep;
		decr_intr(framep);
		td->td_intr_frame = oldframe;
		atomic_subtract_int(&td->td_intr_nesting_level, 1);
		critical_exit();
		break;

	default:
		/* Re-enable interrupts if applicable. */
		ee = framep->srr1 & PSL_EE;
		if (ee != 0)
			mtmsr(mfmsr() | ee);
		trap(framep);
	}	        
}
Пример #6
0
int
_rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
    int trylock, const char *file, int line)
{

	if (SCHEDULER_STOPPED())
		return (1);

#ifdef INVARIANTS
	if (!(rm->lock_object.lo_flags & LO_RECURSABLE) && !trylock) {
		critical_enter();
		KASSERT(rm_trackers_present(pcpu_find(curcpu), rm,
		    curthread) == 0,
		    ("rm_rlock: recursed on non-recursive rmlock %s @ %s:%d\n",
		    rm->lock_object.lo_name, file, line));
		critical_exit();
	}
#endif
	KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread),
	    ("rm_rlock() by idle thread %p on rmlock %s @ %s:%d",
	    curthread, rm->lock_object.lo_name, file, line));
	KASSERT(!rm_destroyed(rm),
	    ("rm_rlock() of destroyed rmlock @ %s:%d", file, line));
	if (!trylock) {
		KASSERT(!rm_wowned(rm),
		    ("rm_rlock: wlock already held for %s @ %s:%d",
		    rm->lock_object.lo_name, file, line));
		WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER, file, line,
		    NULL);
	}

	if (_rm_rlock(rm, tracker, trylock)) {
		if (trylock)
			LOCK_LOG_TRY("RMRLOCK", &rm->lock_object, 0, 1, file,
			    line);
		else
			LOCK_LOG_LOCK("RMRLOCK", &rm->lock_object, 0, 0, file,
			    line);
		WITNESS_LOCK(&rm->lock_object, 0, file, line);

		curthread->td_locks++;

		return (1);
	} else if (trylock)
		LOCK_LOG_TRY("RMRLOCK", &rm->lock_object, 0, 0, file, line);

	return (0);
}
Пример #7
0
setval_t set_lookup(set_t *s, setkey_t k)
{
    node_t *n;
    setval_t v = NULL;
    ptst_t *ptst;

    k = CALLER_TO_INTERNAL_KEY(k);

    ptst = critical_enter();

    n = weak_find(&s->root, k);
    if ( n != NULL ) v = GET_VALUE(n);

    critical_exit(ptst);
    return v;
}
Пример #8
0
t_max_err polywave_interp_set(t_polywave *x, t_object *attr, long argc, t_atom *argv)
{
    
    if(argc == 1 && atom_gettype(argv) == A_LONG)
    {
        critical_enter(x->lock);
        x->interp_type = atom_getlong(argv);
        x->backup = x->interp_type; // << HORRIBLE KLUDGE
        //post("%d %d", x->interp_type, x->backup);
        critical_exit(x->lock);
    } else {
        object_error((t_object *)x, "unknown interpolation ");
    }
    
    return 0;
}
Пример #9
0
int
cpu_set_user_tls(struct thread *td, void *tls_base)
{

	td->td_md.md_tp = (register_t)tls_base;
	if (td == curthread) {
		critical_enter();
#ifdef ARM_TP_ADDRESS
		*(register_t *)ARM_TP_ADDRESS = (register_t)tls_base;
#else
		set_tls((void *)tls_base);
#endif
		critical_exit();
	}
	return (0);
}
Пример #10
0
/*
 * Decrementer interrupt routine
 */
void
powerpc_decr_interrupt(struct trapframe *framep)
{
	struct thread *td;
	struct trapframe *oldframe;

	td = curthread;
	critical_enter();
	atomic_add_int(&td->td_intr_nesting_level, 1);
	oldframe = td->td_intr_frame;
	td->td_intr_frame = framep;
	decr_intr(framep);
	td->td_intr_frame = oldframe;
	atomic_subtract_int(&td->td_intr_nesting_level, 1);
	critical_exit();
	framep->srr1 &= ~PSL_WE;
}
Пример #11
0
void o_freenect_grab_callback(t_object *x_obj)
{
    t_jit_pcl_freenect *x = (t_jit_pcl_freenect *)x_obj;
    
    //    x->kinect->getRegisteredFrames();
    critical_enter(x->lock);
    
    if( x->kinect )
        x->kinect->getFrames( &x->rgb_frame, &x->depth_frame, &x->ir_frame );
    
    critical_exit(x->lock);
    
    
    if( x->rgb_frame )
        post("outer %ld %ld %d %d", x->rgb_frame->width, x->rgb_frame->height, x->rgb_frame->data[0], x->rgb_frame->data[1]);
    
}
Пример #12
0
void hub_init(t_hub *x, t_symbol*, long, t_atom*)
{
	subscriberList	*subscriber = x->subscriber;
	subscriberIterator i;

	// The flag is indicating that we're in the middle of initialization
	x->flag_init = 1;
	// Search the linked list for jcom.init objects and 'bang' them
	critical_enter(0);
	for(i = subscriber->begin(); i != subscriber->end(); ++i) {
		if((*i)->type == jps_subscribe_init)
			object_method((*i)->object, jps_go);		// TODO: This is an exceptionally bad thing to do inside of the critical region
														// It could result in a deadlock
	}
	
	critical_exit(0);
	defer_low(x, (method)hub_preset_default, 0, 0, 0L);
}
Пример #13
0
void
cpu_thread_exit(struct thread *td)
{
	struct pcb *pcb;

	critical_enter();
	if (td == PCPU_GET(fpcurthread))
		fpudrop();
	critical_exit();

	pcb = td->td_pcb;

	/* Disable any hardware breakpoints. */
	if (pcb->pcb_flags & PCB_DBREGS) {
		reset_dbregs();
		clear_pcb_flags(pcb, PCB_DBREGS);
	}
}
Пример #14
0
/*
 * call platform specific code to halt (until next interrupt) for the idle loop
 */
void
cpu_idle(int busy)
{
	KASSERT((mips_rd_status() & MIPS_SR_INT_IE) != 0,
		("interrupts disabled in idle process."));
	KASSERT((mips_rd_status() & MIPS_INT_MASK) != 0,
		("all interrupts masked in idle process."));

	if (!busy) {
		critical_enter();
		cpu_idleclock();
	}
	mips_wait();
	if (!busy) {
		cpu_activeclock();
		critical_exit();
	}
}
Пример #15
0
void hub_returnnames_get(t_hub *x)
{
	subscriberList	*subscriber = x->subscriber;	// head of the linked list
	t_atom			a;
	
	hub_outlet_return(x, jps_return_names_start, 0, NULL);
	
	subscriberIterator i;
	t_subscriber* t;
	critical_enter(0);
	for(i = subscriber->begin(); i != subscriber->end(); ++i) {
		t = *i;
		atom_setsym(&a, t->name);
		if(t->type == jps_subscribe_return)
			hub_outlet_return(x, jps_message_return, 1, &a);
	}
	critical_exit(0);
	hub_outlet_return(x, jps_return_names_end, 0, NULL);
}
Пример #16
0
/*
 * An allocation has succeeded -- update malloc type statistics for the
 * amount of bucket size.  Occurs within a critical section so that the
 * thread isn't preempted and doesn't migrate while updating per-PCU
 * statistics.
 */
static void
malloc_type_zone_allocated(struct malloc_type *mtp, unsigned long size,
    int zindx)
{
	struct malloc_type_internal *mtip;
	struct malloc_type_stats *mtsp;

	critical_enter();
	mtip = mtp->ks_handle;
	mtsp = &mtip->mti_stats[curcpu];
	if (size > 0) {
		mtsp->mts_memalloced += size;
		mtsp->mts_numallocs++;
	}
	if (zindx != -1)
		mtsp->mts_size |= 1 << zindx;

	critical_exit();
}
Пример #17
0
void o_freenect_grab_connect(t_jit_pcl_freenect *x)
{
    critical_enter(x->lock);
    
    x->kinect = new io_kinect_device;
    
    t_object *x_obj = (t_object *)x;
    std::function<void(t_object*)> cb = std::bind(o_freenect_grab_callback, x_obj);
    x->kinect->setCallbackType( cb, x_obj, libfreenect2::Frame::Type::Depth );
    
    if ( ! x->kinect->acitve() )
    {
        post("no active kinect");
        return;
    }
    
    critical_exit(x->lock);
    
}
Пример #18
0
void model_preset_dowrite(TTPtr self, t_symbol *msg, long argc, t_atom *argv)
{
	WrappedModularInstancePtr	x = (WrappedModularInstancePtr)self;
	char 			filename[MAX_FILENAME_CHARS];
	TTSymbol		fullpath;
	TTValue			o, v, none;
	TTObject        aTextHandler;
	TTErr			tterr;

	// stop filewatcher
	if (EXTRA->filewatcher)
		filewatcher_stop(EXTRA->filewatcher);

	if (EXTRA->presetManager->valid()) {

		// Default TEXT File Name
		snprintf(filename, MAX_FILENAME_CHARS, "%s.%s.presets.txt", x->patcherClass.c_str(), x->patcherContext.c_str());
		fullpath = jamoma_file_write((t_object*)x, argc, argv, filename);
		v.append(fullpath);

		tterr = x->internals->lookup(kTTSym_TextHandler, o);

		if (!tterr) {
			aTextHandler = o[0];

			aTextHandler.set(kTTSym_object, *EXTRA->presetManager);

			critical_enter(0);
			tterr = aTextHandler.send(kTTSym_Write, v, none);
			critical_exit(0);

			if (!tterr)
				object_obex_dumpout(self, _sym_write, argc, argv);
			else
				object_obex_dumpout(self, _sym_error, 0, NULL);
		}
	}

	// start filewatcher
	if (EXTRA->filewatcher)
		filewatcher_start(EXTRA->filewatcher);
}
Пример #19
0
void odisplay_clearBundles(t_odisplay *x)
{
	critical_enter(x->lock);
	if(x->bndl_u){
		osc_bundle_u_free(x->bndl_u);
		x->bndl_u = NULL;
	}
	if(x->bndl_s){
		osc_bundle_s_deepFree(x->bndl_s);
		x->bndl_s = NULL;
	}
#ifndef OMAX_PD_VERSION
	if(x->text){
		x->textlen = 0;
		osc_mem_free(x->text);
		x->text = NULL;
	}
#endif
	critical_exit(x->lock);
}
Пример #20
0
static uintptr_t
unlock_rm(struct lock_object *lock)
{
	struct thread *td;
	struct pcpu *pc;
	struct rmlock *rm;
	struct rm_queue *queue;
	struct rm_priotracker *tracker;
	uintptr_t how;

	rm = (struct rmlock *)lock;
	tracker = NULL;
	how = 0;
	rm_assert(rm, RA_LOCKED | RA_NOTRECURSED);
	if (rm_wowned(rm))
		rm_wunlock(rm);
	else {
		/*
		 * Find the right rm_priotracker structure for curthread.
		 * The guarantee about its uniqueness is given by the fact
		 * we already asserted the lock wasn't recursively acquired.
		 */
		critical_enter();
		td = curthread;
		pc = pcpu_find(curcpu);
		for (queue = pc->pc_rm_queue.rmq_next;
		    queue != &pc->pc_rm_queue; queue = queue->rmq_next) {
			tracker = (struct rm_priotracker *)queue;
				if ((tracker->rmp_rmlock == rm) &&
				    (tracker->rmp_thread == td)) {
					how = (uintptr_t)tracker;
					break;
				}
		}
		KASSERT(tracker != NULL,
		    ("rm_priotracker is non-NULL when lock held in read mode"));
		critical_exit();
		rm_runlock(rm, tracker);
	}
	return (how);
}
Пример #21
0
setval_t set_lookup(set_t *s, setkey_t k)
{
    ptst_t  *ptst;
    node_t  *m, *n;
    setval_t v;

    k = CALLER_TO_INTERNAL_KEY(k);

    ptst = critical_enter();

    n = &s->root;
    while ( (m = (k <= n->k) ? n->l : n->r) != NULL )
        n = m;

    v = (k == n->k) ? GET_VALUE(n->v) : NULL;
    if ( v == GARBAGE_VALUE ) v = NULL;

    critical_exit(ptst);

    return v;
}
Пример #22
0
// FREEZE UI for all parameters
void hub_ui_freeze(t_hub *x, t_symbol*, long argc, t_atom *argv)
{
	subscriberList *subscriber = x->subscriber;	// head of the linked list
	t_max_err err = MAX_ERR_NONE;

	// Change freeze status for all messages and parameters
	subscriberIterator i;
	t_subscriber* t;

	// Change freeze attribute for the gui
	// FIXME: This call is not working!!!!
	// this means that the ui menu does not always reflect the state correctly
	err = object_attr_setlong(x->gui_object, gensym("ui_is_frozen"), atom_getlong(argv));

	critical_enter(0);
 	for(i = subscriber->begin(); i != subscriber->end(); ++i) {
		t = *i;
		if(t->type == jps_subscribe_parameter)
			object_method_typed(t->object, jps_ui_slash_freeze, 1, argv, NULL);
	}
	critical_exit(0);
}
Пример #23
0
/*
 * Clear registers on exec
 * XXX copied from ia32_signal.c.
 */
static void
exec_linux_setregs(struct thread *td, struct image_params *imgp, u_long stack)
{
	struct trapframe *regs = td->td_frame;
	struct pcb *pcb = td->td_pcb;

	mtx_lock(&dt_lock);
	if (td->td_proc->p_md.md_ldt != NULL)
		user_ldt_free(td);
	else
		mtx_unlock(&dt_lock);

	critical_enter();
	wrmsr(MSR_FSBASE, 0);
	wrmsr(MSR_KGSBASE, 0);	/* User value while we're in the kernel */
	pcb->pcb_fsbase = 0;
	pcb->pcb_gsbase = 0;
	critical_exit();
	pcb->pcb_initial_fpucw = __LINUX_NPXCW__;

	bzero((char *)regs, sizeof(struct trapframe));
	regs->tf_rip = imgp->entry_addr;
	regs->tf_rsp = stack;
	regs->tf_rflags = PSL_USER | (regs->tf_rflags & PSL_T);
	regs->tf_gs = _ugssel;
	regs->tf_fs = _ufssel;
	regs->tf_es = _udatasel;
	regs->tf_ds = _udatasel;
	regs->tf_ss = _udatasel;
	regs->tf_flags = TF_HASSEGS;
	regs->tf_cs = _ucode32sel;
	regs->tf_rbx = imgp->ps_strings;

	fpstate_drop(td);

	/* Do full restore on return so that we can change to a different %cs */
	set_pcb_flags(pcb, PCB_32BIT | PCB_FULL_IRET);
	td->td_retval[1] = 0;
}
Пример #24
0
setval_t set_update(set_t *s, setkey_t k, setval_t v, int overwrite)
{
    node_t  *f, *w;
    qnode_t  f_qn, w_qn;
    int dir;
    setval_t ov = NULL;
    ptst_t  *ptst;

    k = CALLER_TO_INTERNAL_KEY(k);

    ptst = critical_enter();

retry:
    f = find(&s->root, k, &f_qn, &dir);

    if ( (w = FOLLOW(f, dir)) != NULL )
    {
        /* Protected by parent lock. */
        assert(!IS_BLUE(w));
        ov = w->v;
        if ( overwrite || (ov == NULL) ) w->v = v;
    }
    else
    {
        w = gc_alloc(ptst, gc_id);
        w->l = NULL;
        w->r = NULL;
        w->v = v;
        w->k = k;
        mcs_init(&w->lock);
        UPDATE(f, dir, w);
    }

    UNLOCK(f, &f_qn);

    critical_exit(ptst);

    return ov;
}
Пример #25
0
Файл: mcd.c Проект: MarginC/kame
static int
mcd_play(struct mcd_softc *sc, struct mcd_read2 *pb)
{
	int retry, st = -1, status;

	sc->data.lastpb = *pb;
	for(retry=0; retry<MCD_RETRYS; retry++) {

		critical_enter();
		MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDSINGLESPEEDREAD);
		MCD_WRITE(sc, MCD_REG_COMMAND, pb->start_msf[0]);
		MCD_WRITE(sc, MCD_REG_COMMAND, pb->start_msf[1]);
		MCD_WRITE(sc, MCD_REG_COMMAND, pb->start_msf[2]);
		MCD_WRITE(sc, MCD_REG_COMMAND, pb->end_msf[0]);
		MCD_WRITE(sc, MCD_REG_COMMAND, pb->end_msf[1]);
		MCD_WRITE(sc, MCD_REG_COMMAND, pb->end_msf[2]);
		critical_exit();

		status=mcd_getstat(sc, 0);
		if (status == -1)
			continue;
		else if (status != -2)
			st = 0;
		break;
	}

	if (status == -2) {
		device_printf(sc->dev, "media changed\n");
		return (ENXIO);
	}
	if (sc->data.debug)
		device_printf(sc->dev,
			"mcd_play retry=%d, status=0x%02x\n", retry, status);
	if (st < 0)
		return (ENXIO);
	sc->data.audio_status = CD_AS_PLAY_IN_PROGRESS;
	return (0);
}
Пример #26
0
SpiFlashOpResult IRAM spi_flash_write (uint32_t faddr, uint32_t *src, size_t size)
{
    /*
     * For simplicity, we use the ROM function. Since we need to disable the
     * IROM cache function for that purpose, we have to be in IRAM.
     * Please note, faddr, src and size have to be aligned to 4 byte
     */

    SpiFlashOpResult ret;

    CHECK_PARAM_RET (src != NULL, SPI_FLASH_RESULT_ERR);
    CHECK_PARAM_RET (faddr + size <= flashchip->chip_size, SPI_FLASH_RESULT_ERR);

    critical_enter ();
    Cache_Read_Disable ();

    ret = SPIWrite (faddr, src, size);

    Cache_Read_Enable(0, 0, 1);
    critical_exit ();

    return ret;
}
Пример #27
0
void jsusfx_perform64(t_jsusfx *x, t_object *dsp64, double **ins, long numins, double **outs, long numouts, long sampleframes, long flags, void *userparam) {
    double *inv[2];
    inv[0] = ins[1];
    inv[1] = ins[0];
    
	if ( x->bypass )
        goto bypass;
    
    if ( critical_tryenter(x->critical) )
        goto bypass;

    x->fx->process64(inv, outs, sampleframes);
    
    critical_exit(x->critical);
    return;
    
bypass:
    for(int i=0;i<sampleframes;i++) {
        outs[0][i] = inv[0][i];
        outs[1][i] = inv[1][i];
    }
    
}
Пример #28
0
void
hv_vector_handler(struct trapframe *trap_frame)
{
	int cpu;

	/*
	 * Disable preemption.
	 */
	critical_enter();

	/*
	 * Do a little interrupt counting.
	 */
	cpu = PCPU_GET(cpuid);
	(*hv_vmbus_intr_cpu[cpu])++;

	hv_vmbus_isr(trap_frame);

	/*
	 * Enable preemption.
	 */
	critical_exit();
}
Пример #29
0
static void
pefs_aesni_enter(struct pefs_session *xses)
{
	struct pefs_aesni_ses *ses = &xses->o.ps_aesni;

	if (is_fpu_kern_thread(0)) {
		ses->fpu_saved = 0;
		return;
	}

	critical_enter();
	ses->fpu_ctx = (void *)atomic_swap_ptr(
	    (volatile void *)DPCPU_PTR(pefs_aesni_fpu), (uintptr_t)NULL);
	if (ses->fpu_ctx != NULL) {
		ses->td = curthread;
		ses->fpu_cpuid = curcpu;
		fpu_kern_enter(ses->td, ses->fpu_ctx, FPU_KERN_NORMAL);
		ses->fpu_saved = 1;
	} else {
		ses->fpu_saved = -1;
	}
	critical_exit();
}
Пример #30
0
void hub_free(t_hub *x)
{
	subscriberIterator i;
	subscriberList *subscriber = x->subscriber;
	t_atom a[2];

	object_free(x->preset_interface);
	jamoma_hub_remove(x->osc_name);

	atom_setsym(a, x->attr_name);
	atom_setsym(a+1, x->osc_name);
	object_method_typed(g_jcom_send_notifications, gensym("module.removed"), 2, a, NULL);

	critical_enter(0);
	for(i = subscriber->begin(); i != subscriber->end(); ++i) {
		// notify the subscriber that the hub is going away
		if(!NOGOOD((*i)->object))
			object_method((*i)->object, jps_release);
		sysmem_freeptr(*i);
	}
	critical_exit(0);	

	object_free(x->textEditor);
	if(x->textSize)
		free(x->text);
		
	hub_internals_destroy(x);
 	hub_presets_clear(x, NULL, 0, NULL);
	qelem_free(x->init_qelem);
	if(x->jcom_send)
		object_free(x->jcom_send);
	if(x->jcom_receive)
		object_free(x->jcom_receive);
	x->subscriber->clear();
	delete x->subscriber;
	delete x->preset;
}