Browse Source

+ added header translation of jack/thread.h to libjack

Nikolay Nikolov 7 months ago
parent
commit
a2a513958f

+ 8 - 0
packages/libjack/fpmake.pp

@@ -59,6 +59,14 @@ begin
         AddUnit('jack');
       end;
 
+    T:=P.Targets.AddUnit('jackthread.pp');
+    with T.Dependencies do
+      begin
+        AddInclude('thread.inc');
+        AddInclude('weakmacros.inc');
+        AddUnit('jack');
+      end;
+
     P.ExamplePath.Add('examples');
     P.Targets.AddExampleProgram('simple_client.pp');
     P.Targets.AddExampleProgram('simple_session_client.pp');

+ 3 - 0
packages/libjack/namespaced/Api.Jack.Thread.pp

@@ -0,0 +1,3 @@
+unit Api.Jack.Thread;
+{$DEFINE FPC_DOTTEDUNITS}
+{$i jackthread.pp}

+ 1 - 0
packages/libjack/namespaces.lst

@@ -2,5 +2,6 @@ src/jack.pp=namespaced/Api.Jack.pp
 src/jackringbuffer.pp=namespaced/Api.Jack.RingBuffer.pp
 src/jackuuid.pp=namespaced/Api.Jack.Uuid.pp
 src/jacksession.pp=namespaced/Api.Jack.Session.pp
+src/jackthread.pp=namespaced/Api.Jack.Thread.pp
 {s*:src/}=namespaced/
 {i+:src/}

+ 23 - 0
packages/libjack/src/jackthread.pp

@@ -0,0 +1,23 @@
+{$IFNDEF FPC_DOTTEDUNITS}
+unit jackthread;
+{$ENDIF FPC_DOTTEDUNITS}
+
+{$mode ObjFPC}{$H+}
+
+interface
+
+{$packrecords C}
+
+uses
+{$IFDEF FPC_DOTTEDUNITS}
+  System.CTypes, Api.Jack;
+{$ELSE FPC_DOTTEDUNITS}
+  ctypes, jack;
+{$ENDIF FPC_DOTTEDUNITS}
+
+{$I thread.inc}
+
+implementation
+
+end.
+

+ 2 - 0
packages/libjack/src/systemdeps.inc

@@ -125,6 +125,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #endif /* __APPLE__ || __linux__ || __sun__ || sun */*)
 
 type
+  PPjack_native_thread_t = ^Pjack_native_thread_t;
+  Pjack_native_thread_t = ^jack_native_thread_t;
   jack_native_thread_t = System.TThreadID;
 
 (*#if (defined(__arm__) || defined(__aarch64__) || defined(__mips__) || defined(__ppc__) || defined(__powerpc__)) && !defined(__APPLE__)

+ 24 - 1
packages/libjack/src/t_jack.h2paschk

@@ -7,11 +7,13 @@
 # the Pascal program produces the same output as the C program for each
 # supported architecture.
 
-@Pascal uses jack, jackringbuffer;
+@Pascal uses jack, jackringbuffer, jacksession, jackthread;
 @Pascal begin
 
 @C #include <jack/jack.h>
 @C #include <jack/ringbuffer.h>
+@C #include <jack/session.h>
+@C #include <jack/thread.h>
 @C #include <stdio.h>
 @C #include <stddef.h>
 @C int main()
@@ -122,6 +124,27 @@
 .size_mask
 .mlocked
 
+@type jack_session_event_type_t
+@type jack_session_flags_t
+
+@record jack_session_event_t
+._type,type
+.session_dir
+.client_uuid
+.command_line
+.flags
+.future
+
+@type TJackSessionCallback,JackSessionCallback
+
+@record jack_session_command_t
+.uuid
+.client_name
+.command
+.flags
+
+@type jack_thread_creator_t
+
 @C   return 0;
 @C }
 

+ 167 - 0
packages/libjack/src/thread.inc

@@ -0,0 +1,167 @@
+{
+   Copyright (C) 2004 Paul Davis
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+}
+
+{$ifndef __jack_thread_h__}
+{$define __jack_thread_h__}
+
+//#ifdef __cplusplus
+//extern "C"
+//{
+//#endif
+
+//#include <jack/systemdeps.h>
+{$I systemdeps.inc}
+//#include <jack/weakmacros.h>
+{$I weakmacros.inc}
+
+
+(* use 512KB stack per thread - the default is way too high to be feasible
+ * with mlockall() on many systems *)
+const
+  THREAD_STACK = 524288;
+
+(** @file thread.h
+ *
+ * Library functions to standardize thread creation for JACK and its
+ * clients.  These interfaces hide some system variations in the
+ * handling of realtime scheduling and associated privileges.
+ *)
+
+(**
+ * @defgroup ClientThreads Creating and managing client threads
+ * @{
+ *)
+
+ (**
+ * @returns if JACK is running with realtime scheduling, this returns
+ * the priority that any JACK-created client threads will run at.
+ * Otherwise returns -1.
+ *)
+
+function jack_client_real_time_priority (client: Pjack_client_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
+
+(**
+ * @returns if JACK is running with realtime scheduling, this returns
+ * the maximum priority that a JACK client thread should use if the thread
+ * is subject to realtime scheduling. Otherwise returns -1.
+ *)
+
+function jack_client_max_real_time_priority (client: Pjack_client_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
+
+(**
+ * Attempt to enable realtime scheduling for a thread.  On some
+ * systems that may require special privileges.
+ *
+ * @param thread POSIX thread ID.
+ * @param priority requested thread priority.
+ *
+ * @returns 0, if successful; EPERM, if the calling process lacks
+ * required realtime privileges; otherwise some other error number.
+ *)
+function jack_acquire_real_time_scheduling (thread: jack_native_thread_t; priority: cint): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
+
+(**
+ * Create a thread for JACK or one of its clients.  The thread is
+ * created executing @a start_routine with @a arg as its sole
+ * argument.
+ *
+ * @param client the JACK client for whom the thread is being created. May be
+ * NULL if the client is being created within the JACK server.
+ * @param thread place to return POSIX thread ID.
+ * @param priority thread priority, if realtime.
+ * @param realtime true for the thread to use realtime scheduling.  On
+ * some systems that may require special privileges.
+ * @param start_routine function the thread calls when it starts.
+ * @param arg parameter passed to the @a start_routine.
+ *
+ * @returns 0, if successful; otherwise some error number.
+ *)
+type
+  TJackThreadStartRoutine = function(arg: Pointer): Pointer; cdecl;
+function jack_client_create_thread (client: Pjack_client_t;
+                               thread: Pjack_native_thread_t;
+                               priority: cint;
+                               realtime: cint;  { boolean }
+                               start_routine: TJackThreadStartRoutine;
+                               arg: Pointer): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
+
+(**
+ * Drop realtime scheduling for a thread.
+ *
+ * @param thread POSIX thread ID.
+ *
+ * @returns 0, if successful; otherwise an error number.
+ *)
+function jack_drop_real_time_scheduling (thread: jack_native_thread_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
+
+(**
+ * Stop the thread, waiting for the thread handler to terminate.
+ *
+ * @param thread POSIX thread ID.
+ *
+ * @returns 0, if successful; otherwise an error number.
+ *)
+function jack_client_stop_thread(client: Pjack_client_t; thread: jack_native_thread_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
+
+(**
+ * Kill the thread.
+ *
+ * @param thread POSIX thread ID.
+ *
+ * @returns 0, if successful; otherwise an error number.
+ *)
+function jack_client_kill_thread(client: Pjack_client_t; thread: jack_native_thread_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
+
+{$ifndef MSWINDOWS}
+
+type
+  jack_thread_creator_t = function(thread: {pthread_t*}Pointer;
+				     const attr: {pthread_attr_t*}Pointer;
+                                     start_routine: TJackThreadStartRoutine;
+				     arg: Pointer): cint; cdecl;
+(**
+ * This function can be used in very very specialized cases
+ * where it is necessary that client threads created by JACK
+ * are created by something other than pthread_create(). After
+ * it is used, any threads that JACK needs for the client will
+ * will be created by calling the function passed to this
+ * function.
+ *
+ * No normal application/client should consider calling this.
+ * The specific case for which it was created involves running
+ * win32/x86 plugins under Wine on Linux, where it is necessary
+ * that all threads that might call win32 functions are known
+ * to Wine.
+ *
+ * Set it to NULL to restore thread creation function.
+ *
+ * @param creator a function that creates a new thread
+ *
+ *)
+procedure jack_set_thread_creator (creator: jack_thread_creator_t); cdecl; JACK_OPTIONAL_WEAK_EXPORT;
+
+{$endif}
+
+///**@}*/
+
+//#ifdef __cplusplus
+//}
+//#endif
+
+{$endif __jack_thread_h__}