Logo Search packages:      
Sourcecode: jack-audio-connection-kit version File versions  Download package

int jack_client_create_thread ( jack_client_t *  client,
pthread_t *  thread,
int  priority,
int  realtime,
void *(*)(void *)  start_routine,
void *  arg 
)

Create a thread for JACK or one of its clients. The thread is created executing start_routine with arg as its sole argument.

Parameters:
client the JACK client for whom the thread is being created. May be NULL if the client is being created within the JACK server.
thread place to return POSIX thread ID.
priority thread priority, if realtime.
realtime true for the thread to use realtime scheduling. On some systems that may require special privileges.
start_routine function the thread calls when it starts.
arg parameter passed to the start_routine.
Returns:
0, if successful; otherwise some error number.

Definition at line 115 of file thread.c.

References jack_client_create_thread().

Referenced by jack_client_create_thread().

{
#ifndef JACK_USE_MACH_THREADS
      pthread_attr_t attr;
      jack_thread_arg_t* thread_args;
#endif /* !JACK_USE_MACH_THREADS */

      int result = 0;

      if (!realtime) {
            result = pthread_create (thread, 0, start_routine, arg);
            if (result) {
                  log_result("creating thread with default parameters",
                           result);
            }
            return result;
      }

      /* realtime thread. this disgusting mess is a reflection of
       * the 2nd-class nature of RT programming under POSIX in
       * general and Linux in particular.
       */

#ifndef JACK_USE_MACH_THREADS

      pthread_attr_init(&attr);
      result = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
      if (result) {
            log_result("requesting explicit scheduling", result);
            return result;
      }
      result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
      if (result) {
            log_result("requesting joinable thread creation", result);
            return result;
      }
      result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
      if (result) {
            log_result("requesting system scheduling scope", result);
            return result;
      }

      thread_args = (jack_thread_arg_t *) malloc (sizeof (jack_thread_arg_t));

      thread_args->client = client;
      thread_args->work_function = start_routine;
      thread_args->arg = arg;
      thread_args->realtime = 1;
      thread_args->priority = priority;

      result = pthread_create (thread, &attr, jack_thread_proxy, thread_args);
      if (result) {
            log_result ("creating realtime thread", result);
            return result;
      }

#else /* JACK_USE_MACH_THREADS */

      result = pthread_create (thread, 0, start_routine, arg);
      if (result) {
            log_result ("creating realtime thread", result);
            return result;
      }

      /* time constraint thread */
      setThreadToPriority (*thread, 96, TRUE, 10000000);
      
#endif /* JACK_USE_MACH_THREADS */

      return 0;
}


Generated by  Doxygen 1.6.0   Back to index