Exemple #1
0
void picture_pool_NonEmpty(picture_pool_t *pool, bool reset)
{
    picture_t *old = NULL;

    for (int i = 0; i < pool->picture_count; i++) {
        if (pool->picture_reserved[i])
            continue;

        picture_t *picture = pool->picture[i];
        if (reset) {
            if (atomic_load(&picture->gc.refcount) > 0)
                Unlock(picture);
            atomic_store(&picture->gc.refcount, 0);
        } else if (atomic_load(&picture->gc.refcount) == 0) {
            return;
        } else if (!old || picture->gc.p_sys->tick < old->gc.p_sys->tick) {
            old = picture;
        }
    }
    if (!reset && old) {
        if (atomic_load(&old->gc.refcount) > 0)
            Unlock(old);
        atomic_store(&old->gc.refcount, 0);
    }
}
int aeron_distinct_error_log_init(
    aeron_distinct_error_log_t *log,
    uint8_t *buffer,
    size_t buffer_size,
    aeron_clock_func_t clock,
    aeron_resource_linger_func_t linger,
    void *clientd)
{
    if (NULL == log || NULL == clock || NULL == linger)
    {
        aeron_set_err(EINVAL, "%s", "invalid argument");
        return -1;
    }

    if (aeron_alloc((void **)&log->observations_pimpl, sizeof(aeron_distinct_error_log_observations_pimpl_t)) < 0)
    {
        return -1;
    }

    log->buffer = buffer;
    log->buffer_capacity = buffer_size;
    log->clock = clock;
    log->linger_resource = linger;
    log->linger_resource_clientd = clientd;
    log->next_offset = 0;
    atomic_store(&log->observations_pimpl->num_observations, 0);
    atomic_store(&log->observations_pimpl->observations, NULL);
    pthread_mutex_init(&log->mutex, NULL);

    return 0;
}
Exemple #3
0
/* ConstructSystemPipe
 * Construct an already existing pipe by initializing the pipe with the given configuration. */
void
ConstructSystemPipe(
    _In_ SystemPipe_t*              Pipe,
    _In_ Flags_t                    Configuration,
    _In_ size_t                     SegmentLgSize)
{
    // Variables
    SystemPipeSegment_t *Segment;

    // Sanitize input
    assert(Pipe != NULL);

    // Initialize pipe instance
    memset((void*)Pipe, 0, sizeof(SystemPipe_t));
    Pipe->Configuration = Configuration;
    Pipe->SegmentLgSize = SegmentLgSize;

    // Stride is the multiplier we apply for the index of the segment
    // this is not used in bounded conditions or SPSC conditions
    Pipe->Stride            = ((Configuration & PIPE_MPMC) != PIPE_MPMC || 
        ((Configuration & PIPE_UNBOUNDED) == 0) || SegmentLgSize <= 1) ? 1 : 27;

    // Initialize first segment
    CreateSegment(Pipe, &Segment, 0);
    atomic_store(&Pipe->ConsumerState.Head, Segment);
    atomic_store(&Pipe->ProducerState.Tail, Segment);
}
Exemple #4
0
static void InputEvent( input_thread_t *input,
                        const struct vlc_input_event *event, void *task_ )
{
    VLC_UNUSED( input );
    input_preparser_task_t* task = task_;

    switch( event->type )
    {
        case INPUT_EVENT_STATE:
            atomic_store( &task->state, event->state );
            break;

        case INPUT_EVENT_DEAD:
            atomic_store( &task->done, true );
            background_worker_RequestProbe( task->preparser->worker );
            break;
        case INPUT_EVENT_SUBITEMS:
        {
            input_preparser_req_t *req = task->req;
            if (req->cbs && req->cbs->on_subtree_added)
                req->cbs->on_subtree_added(req->item, event->subitems, req->userdata);
            break;
        }
        default: ;
    }
}
Exemple #5
0
// Actual queue push.
static void qpush(intq* self, qitem* n)
{
	qitem* prev;
	atomic_store(&n->next, 0);
	prev = atomic_exchange(&self->head, n);
	atomic_store(&prev->next, n);
}
Exemple #6
0
int ping_cmd(int argc, char **argv)
{
    ipv6_addr_t dst;
    int payload_len, _num;

    if ((argc < 2) || (ipv6_addr_from_str(&dst, argv[1]) == NULL)) {
        usage(argv[0]);
        return 1;
    }
    if ((argc < 3) || ((_num = atoi(argv[2])) == 0)) {
        _num = 3;
    }
    if ((argc < 4) || ((payload_len = atoi(argv[3])) == 0)) {
        payload_len = 16;
    }
    atomic_store(&num, _num);
    atomic_store(&received, 0);
    seq = 0;
    if (recv_ntfy.callback == NULL) {
        uip_icmp6_echo_reply_callback_add(&recv_ntfy, handle_reply);
    }
    for (uint16_t i = 0; i < _num; i++) {
        _waiting = true;
        ping_send((uip_ipaddr_t *)&dst, payload_len);
        xtimer_usleep(1000000);
        if (_waiting) {
            puts("Timeout");
        }
    }

    return 0;
}
Exemple #7
0
static void timer_trylock_cb(struct timer* t, zx_time_t now, void* void_arg) {
    timer_args* arg = reinterpret_cast<timer_args*>(void_arg);
    atomic_store(&arg->timer_fired, 1);
    while (atomic_load(&arg->wait)) {
    }

    int result = timer_trylock_or_cancel(t, arg->lock);
    if (!result) {
        spin_unlock(arg->lock);
    }

    atomic_store(&arg->result, result);
}
static void *Worker( void *arg ) {
    TYPE id = (size_t)arg;
	uint64_t entry;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

    for ( int r = 0; r < RUNS; r += 1 ) {
        entry = 0;
        while ( atomic_load(&stop) == 0 ) {
            atomic_store(&states[id*PADRATIO], LOCKED);
            while (1) {
                int lturn = atomic_load(&turn);
                if (!validate_left(id, lturn)) {
                    atomic_store(&states[id*PADRATIO], WAITING);
                    while (1) {
                        if (validate_left(id, lturn) && lturn == atomic_load_explicit(&turn, memory_order_acquire)) break;
                        Pause();
                        lturn = atomic_load_explicit(&turn, memory_order_acquire);
                    }
                    atomic_store(&states[id*PADRATIO], LOCKED);
                    continue;
                }
                while (lturn == atomic_load_explicit(&turn, memory_order_acquire)) {
                    if (validate_right(id, lturn)) break;
                    Pause();
                }
                if (lturn == atomic_load_explicit(&turn, memory_order_acquire)) break;
            }
			CriticalSection( id );						// critical section
			int lturn = (atomic_load_explicit(&turn, memory_order_relaxed)+1) % N;
			atomic_store_explicit(&turn, lturn, memory_order_relaxed);
			atomic_store_explicit(&states[id*PADRATIO], UNLOCKED, memory_order_release); // exit protocol
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
        atomic_fetch_add( &Arrived, 1 );
        while ( atomic_load(&stop) != 0 ) Pause();
        atomic_fetch_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemple #9
0
static int FilterCallback ( vlc_object_t *p_this, char const *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    filter_sys_t *p_sys = p_data;

    if( !strcmp( psz_var, CFG_PREFIX "color" ) )
        atomic_store( &p_sys->i_color, newval.i_int );
    else if( !strcmp( psz_var, CFG_PREFIX "similaritythres" ) )
        atomic_store( &p_sys->i_simthres, newval.i_int );
    else /* CFG_PREFIX "saturationthres" */
        atomic_store( &p_sys->i_satthres, newval.i_int );

    (void)p_this; (void)oldval;
    return VLC_SUCCESS;
}
void Executer::doRun(){
    
    if(atomic_load(&m_state) != EXECUTER_STATE_STARTED){
        return;
    }
    
    for(;;){
        if(m_task_queue->isEmpty()){
            // just sleep
            usleep(1000);
            continue;
        }
        
        
        Task t = m_task_queue->wait_to_take();
        t.run();
        
        if(atomic_load(&m_state) == EXECUTER_STATE_SHUTTINGDOWN){
            if(m_task_queue->isEmpty()){
                atomic_store(&m_state, EXECUTER_STATE_SHUTDOWN);
                return;
            }
        }
        
    }
}
Exemple #11
0
int
main ()
{
  v = 0;
  count = 0;

  atomic_init (&v, count + 1);
  if (v != ++count)
    abort ();

  atomic_store_explicit (&v, count + 1, memory_order_relaxed);
  if (v != ++count)
    abort ();

  atomic_store_explicit (&v, count + 1, memory_order_release);
  if (v != ++count)
    abort ();

  atomic_store_explicit (&v, count + 1, memory_order_seq_cst);
  if (v != ++count)
    abort ();

  count++;

  atomic_store (&v, count);
  if (v != count)
    abort ();

  return 0;
}
Exemple #12
0
static void caerModuleShutdownListener(sshsNode node, void *userData, enum sshs_node_attribute_events event,
	const char *changeKey, enum sshs_node_attr_value_type changeType, union sshs_node_attr_value changeValue) {
	UNUSED_ARGUMENT(node);

	caerModuleData data = userData;

	if (event == ATTRIBUTE_MODIFIED && changeType == BOOL && caerStrEquals(changeKey, "shutdown")) {
		// Shutdown changed, let's see.
		if (changeValue.boolean == true) {
			atomic_store(&data->running, false);
		}
		else {
			atomic_store(&data->running, true);
		}
	}
}
Exemple #13
0
TEST(stdatomic, atomic_store) {
  atomic_int i;
  atomic_store(&i, 123);
  ASSERT_EQ(123, atomic_load(&i));
  atomic_store_explicit(&i, 123, memory_order_relaxed);
  ASSERT_EQ(123, atomic_load_explicit(&i, memory_order_relaxed));
}
Exemple #14
0
static int ffmal_update_format(AVCodecContext *avctx)
{
    MMALDecodeContext *ctx = avctx->priv_data;
    MMAL_STATUS_T status;
    int ret = 0;
    MMAL_COMPONENT_T *decoder = ctx->decoder;
    MMAL_ES_FORMAT_T *format_out = decoder->output[0]->format;

    ffmmal_poolref_unref(ctx->pool_out);
    if (!(ctx->pool_out = av_mallocz(sizeof(*ctx->pool_out)))) {
        ret = AVERROR(ENOMEM);
        goto fail;
    }
    atomic_store(&ctx->pool_out->refcount, 1);

    if (!format_out)
        goto fail;

    if ((status = mmal_port_parameter_set_uint32(decoder->output[0], MMAL_PARAMETER_EXTRA_BUFFERS, ctx->extra_buffers)))
        goto fail;

    if ((status = mmal_port_parameter_set_boolean(decoder->output[0], MMAL_PARAMETER_VIDEO_INTERPOLATE_TIMESTAMPS, 0)))
        goto fail;

    if (avctx->pix_fmt == AV_PIX_FMT_MMAL) {
        format_out->encoding = MMAL_ENCODING_OPAQUE;
    } else {
        format_out->encoding_variant = format_out->encoding = MMAL_ENCODING_I420;
    }

    if ((status = mmal_port_format_commit(decoder->output[0])))
        goto fail;

    if ((ret = ff_set_dimensions(avctx, format_out->es->video.crop.x + format_out->es->video.crop.width,
                                        format_out->es->video.crop.y + format_out->es->video.crop.height)) < 0)
        goto fail;

    if (format_out->es->video.par.num && format_out->es->video.par.den) {
        avctx->sample_aspect_ratio.num = format_out->es->video.par.num;
        avctx->sample_aspect_ratio.den = format_out->es->video.par.den;
    }

    avctx->colorspace = ffmmal_csp_to_av_csp(format_out->es->video.color_space);

    decoder->output[0]->buffer_size =
        FFMAX(decoder->output[0]->buffer_size_min, decoder->output[0]->buffer_size_recommended);
    decoder->output[0]->buffer_num =
        FFMAX(decoder->output[0]->buffer_num_min, decoder->output[0]->buffer_num_recommended) + ctx->extra_buffers;
    ctx->pool_out->pool = mmal_pool_create(decoder->output[0]->buffer_num,
                                           decoder->output[0]->buffer_size);
    if (!ctx->pool_out->pool) {
        ret = AVERROR(ENOMEM);
        goto fail;
    }

    return 0;

fail:
    return ret < 0 ? ret : AVERROR_UNKNOWN;
}
Exemple #15
0
int main()
{
   _Atomic int hogs;
   atomic_store(&hogs, 12);

   return EXIT_SUCCESS;
}
Exemple #16
0
static void flush(filter_t *filter)
{
    filter_sys_t *sys = filter->p_sys;
    MMAL_BUFFER_HEADER_T *buffer;

    msg_Dbg(filter, "flush deinterlace filter");

    msg_Dbg(filter, "flush: flush ports (input: %d, output: %d in transit)",
            sys->input_in_transit, sys->output_in_transit);
    mmal_port_flush(sys->output);
    mmal_port_flush(sys->input);

    msg_Dbg(filter, "flush: wait for all buffers to be returned");
    while (atomic_load(&sys->input_in_transit) ||
            atomic_load(&sys->output_in_transit))
        vlc_sem_wait(&sys->sem);

    while ((buffer = mmal_queue_get(sys->filtered_pictures))) {
        picture_t *pic = (picture_t *)buffer->user_data;
        msg_Dbg(filter, "flush: release already filtered pic %p",
                (void *)pic);
        picture_Release(pic);
    }
    atomic_store(&sys->started, false);
    msg_Dbg(filter, "flush: done");
}
Exemple #17
0
static void set_thread_state(struct ao *ao,
                             enum wasapi_thread_state thread_state)
{
    struct wasapi_state *state = ao->priv;
    atomic_store(&state->thread_state, thread_state);
    SetEvent(state->hWake);
}
Exemple #18
0
QueueResult queue_pop(queue_p q)
{
    assert(q);
    assert(queue_has_front(q) == QUEUE_TRUE);

    /* get the head */
    node *popped = (node*) atomic_load(&q->head);
    node *compare = popped;

    /* set the tail and head to nothing if they are the same */
    if (atomic_compare_exchange_strong(&q->tail, &compare, 0)) {
        compare = popped;
        /* it is possible for another thread to have pushed after
         * we swap out the tail. In this case, the head will be different
         * then what was popped, so we just do a blind exchange regardless
         * of the result.
         */
        atomic_compare_exchange_strong(&q->head, &compare, 0);
    } else {
        /* tail is different from head, set the head to the next value */
        node *new_head = 0;
        while (!new_head) {
            /* it is possible that the next node has not been assigned yet,
             * so just spin until the pushing thread stores the value.
	     */
            new_head = (node *) atomic_load(&popped->next);
        }
        atomic_store(&q->head, new_head->next);
    }

    free(popped);
    return QUEUE_SUCCESS;
}
Exemple #19
0
static void output_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
{
    filter_t *filter = (filter_t *)port->userdata;
    filter_sys_t *sys = filter->p_sys;
    picture_t *picture;

    if (buffer->cmd == 0) {
        vlc_mutex_lock(&sys->buffer_cond_mutex);
        if (buffer->length > 0) {
            atomic_store(&sys->started, true);
            mmal_queue_put(sys->filtered_pictures, buffer);
            picture = (picture_t *)buffer->user_data;
        } else {
            picture = (picture_t *)buffer->user_data;
            picture_Release(picture);
        }

        atomic_fetch_sub(&sys->output_in_transit, 1);
        vlc_cond_signal(&sys->buffer_cond);
        vlc_mutex_unlock(&sys->buffer_cond_mutex);
    } else if (buffer->cmd == MMAL_EVENT_FORMAT_CHANGED) {
        msg_Warn(filter, "MMAL_EVENT_FORMAT_CHANGED seen but not handled");
        mmal_buffer_header_release(buffer);
    } else {
        mmal_buffer_header_release(buffer);
    }
}
Exemple #20
0
/**
 * Delete an update_t struct
 *
 * \param p_update update_t* pointer
 * \return nothing
 */
void update_Delete( update_t *p_update )
{
    assert( p_update );

    if( p_update->p_check )
    {
        vlc_join( p_update->p_check->thread, NULL );
        free( p_update->p_check );
    }

    if( p_update->p_download )
    {
        atomic_store( &p_update->p_download->aborted, true );
        vlc_join( p_update->p_download->thread, NULL );
        vlc_object_release( p_update->p_download );
    }

    vlc_mutex_destroy( &p_update->lock );

    free( p_update->release.psz_url );
    free( p_update->release.psz_desc );
    free( p_update->p_pkey );

    free( p_update );
}
void Executer::start(){
    atomic_store(&m_state, EXECUTER_STATE_STARTED);
    if(m_thread){
        delete m_thread;
    }
    m_thread = new thread(&Executer::doRun, this);
}
Exemple #22
0
void picture_pool_Delete(picture_pool_t *pool)
{
    for (int i = 0; i < pool->picture_count; i++) {
        picture_t *picture = pool->picture[i];
        if (pool->master) {
            for (int j = 0; j < pool->master->picture_count; j++) {
                if (pool->master->picture[j] == picture)
                    pool->master->picture_reserved[j] = false;
            }
        } else {
            picture_gc_sys_t *gc_sys = picture->gc.p_sys;

            assert(!pool->picture_reserved[i]);

            /* Restore the original garbage collector */
            if (atomic_fetch_add(&picture->gc.refcount, 1) == 0)
            {   /* Simple case: the picture is not locked, destroy it now. */
                picture->gc.pf_destroy = gc_sys->destroy;
                picture->gc.p_sys      = gc_sys->destroy_sys;
                free(gc_sys);
            }
            else /* Intricate case: the picture is still locked and the gc
                    cannot be modified (w/o memory synchronization). */
                atomic_store(&gc_sys->zombie, true);

            picture_Release(picture);
        }
    }
    free(pool->picture_reserved);
    free(pool->picture);
    free(pool);
}
Exemple #23
0
bool initUartOutput(flowOutputState state, char* port, unsigned int baud, size_t bufferSize) {
	// Initialize UART communication
	int uartErrno = uart_open(port, baud);
	if (uartErrno) {
		caerLog(CAER_LOG_ALERT, SUBSYSTEM_UART,
				"Failed to identify serial communication, errno=%i.",uartErrno);
		return (false);
	}
	// Test message
	char* testMessage = "DVS128UART";
	if (uart_tx((int) strlen(testMessage), (unsigned char*) testMessage)) {
		caerLog(CAER_LOG_ALERT, SUBSYSTEM_UART,
				"Test transmission unsuccessful - connection closed.");
		uart_close();
		return(false);
	}

	// Start output handler thread
	state->thread = 0;
	if (thrd_create(&state->thread, &outputHandlerThread, state) != thrd_success) {
		caerLog(CAER_LOG_ALERT, SUBSYSTEM_UART,"Failed to start output handler thread");
		return (false);
	}
	state->buffer = ringBufferInit(bufferSize);
	if (state->buffer == NULL) {
		caerLog(CAER_LOG_ERROR, SUBSYSTEM_UART, "Failed to allocate transfer ring-buffer.");
		return (false);
	}
	atomic_store(&state->running, true);
	caerLog(CAER_LOG_NOTICE, SUBSYSTEM_UART, "Streaming flow events to port %s.",port);
	return (true);
}
Exemple #24
0
void vlc_interrupt_kill(vlc_interrupt_t *ctx)
{
    assert(ctx != NULL);

    atomic_store(&ctx->killed, true);
    vlc_interrupt_raise(ctx);
}
Exemple #25
0
static void tv_callback(void *callback_data, uint32_t reason, uint32_t param1,
                        uint32_t param2)
{
    struct ra_ctx *ctx = callback_data;
    struct priv *p = ctx->priv;
    atomic_store(&p->reload_display, true);
    vo_wakeup(ctx->vo);
}
Exemple #26
0
void vlc_cancel (vlc_thread_t th)
{
#if !VLC_WINSTORE_APP
    QueueUserAPC (vlc_cancel_self, th->id, (uintptr_t)th);
#else
    atomic_store (&th->killed, true);
#endif
}
FileDescriptorTable& FileDescriptorTable::operator=(
        const FileDescriptorTable& rhs)
{
    Lock<FastMutex> l(mutex);
    for(int i=0;i<MAX_OPEN_FILES;i++)
        atomic_store(&this->files[i],atomic_load(&rhs.files[i]));
    return *this;
}
Exemple #28
0
static void store_trigo( struct filter_sys_t *sys, float f_angle )
{
    f_angle *= (float)(M_PI / 180.); /* degrees -> radians */

    uint16_t i_sin = lroundf(sinf(f_angle) * 4096.f);
    uint16_t i_cos = lroundf(cosf(f_angle) * 4096.f);
    atomic_store( &sys->sincos, (i_cos << 16u) | (i_sin << 0u));
}
Exemple #29
0
// sunqueen add end
static void store_trigo( struct filter_sys_t *sys, float f_angle )
{
    f_angle *= M_PI / 180.f; /* degrees -> radians */

    uint16_t i_sin = cover_lroundf(sinf(f_angle) * 4096.f);			// sunqueen modify
    uint16_t i_cos = cover_lroundf(cosf(f_angle) * 4096.f);			// sunqueen modify
    atomic_store( &sys->sincos, (atomic_uint)((i_cos << 16) | (i_sin << 0)));			// sunqueen modify
}
Exemple #30
0
static void audio_reset(struct ao *ao)
{
    struct wasapi_state *state = (struct wasapi_state *)ao->priv;

    IAudioClient_Stop(state->pAudioClientProxy);
    IAudioClient_Reset(state->pAudioClientProxy);
    atomic_store(&state->sample_count, 0);
}