Example #1
0
void
tr_runInEventThread( struct tr_handle *       handle,
                     void               func( void* ),
                     void *                   user_data )
{
    assert( handle );
    assert( handle->events );

    if( tr_amInThread( handle->events->thread ) )
    {
        (func)( user_data );
    }
    else
    {
        const char         ch = 'r';
        int                fd = handle->events->fds[1];
        tr_lock *          lock = handle->events->lock;
        struct tr_run_data data;

        tr_lockLock( lock );
        pipewrite( fd, &ch, 1 );
        data.func = func;
        data.user_data = user_data;
        pipewrite( fd, &data, sizeof( data ) );
        tr_lockUnlock( lock );
    }
}
Example #2
0
void
tr_runInEventThread( tr_session * session,
                     void func( void* ), void * user_data )
{
    assert( tr_isSession( session ) );
    assert( session->events != NULL );

    if( tr_amInThread( session->events->thread ) )
    {
        (func)( user_data );
    }
    else
    {
        const char         ch = 'r';
        int                fd = session->events->fds[1];
        tr_lock *          lock = session->events->lock;
        struct tr_run_data data;

        tr_lockLock( lock );
        pipewrite( fd, &ch, 1 );
        data.func = func;
        data.user_data = user_data;
        pipewrite( fd, &data, sizeof( data ) );
        tr_lockUnlock( lock );
    }
}
bool
tr_amInEventThread (const tr_session * session)
{
    assert (tr_isSession (session));
    assert (session->events != NULL);

    return tr_amInThread (session->events->thread);
}
Example #4
0
int
tr_amInEventThread( struct tr_handle * handle )
{
    assert( handle );
    assert( handle->events );

    return tr_amInThread( handle->events->thread );
}
void
tr_runInEventThread (tr_session * session,
                     void func (void*), void * user_data)
{
  assert (tr_isSession (session));
  assert (session->events != NULL);

  if (tr_amInThread (session->events->thread))
    {
      (func)(user_data);
    }
  else
    {
      int fd;
      char ch;
      ssize_t res_1;
      ssize_t res_2;
      tr_event_handle * e = session->events;
      struct tr_run_data data;

      tr_lockLock (e->lock);

      fd = e->fds[1];
      ch = 'r';
      res_1 = pipewrite (fd, &ch, 1);

      data.func = func;
      data.user_data = user_data;
      res_2 = pipewrite (fd, &data, sizeof (data));

      tr_lockUnlock (e->lock);

      if ((res_1 == -1) || (res_2 == -1))
        tr_logAddError ("Unable to write to libtransmisison event queue: %s", tr_strerror(errno));
    }
}
Example #6
0
tr_timer*
tr_timerNew( struct tr_handle * handle,
             timer_func         func,
             void *             user_data,
             uint64_t           interval_milliseconds )
{
    tr_timer * timer;

    assert( handle );
    assert( handle->events );

    timer = tr_new0( tr_timer, 1 );
    tr_timevalMsec( interval_milliseconds, &timer->tv );
    timer->func = func;
    timer->user_data = user_data;
    timer->eh = handle->events;
    evtimer_set( &timer->event, timerCallback, timer );

    if( tr_amInThread( handle->events->thread ) )
    {
        evtimer_add( &timer->event,  &timer->tv );
    }
    else
    {
        const char ch = 't';
        int        fd = handle->events->fds[1];
        tr_lock *  lock = handle->events->lock;

        tr_lockLock( lock );
        pipewrite( fd, &ch, 1 );
        pipewrite( fd, &timer, sizeof( timer ) );
        tr_lockUnlock( lock );
    }

    return timer;
}