Register the dynamic thread functions
Your application must use the ifxOS_set_thrfunc() function to register the dynamic thread functions with .
The following declaration describes the ifxOS_set_thrfunc() function.
mint ifxOS_set_thrfunc(mint func, mulong (*funcptr)())
The first parameter, func, is a mint that indexes the function being registered. The second parameter is the name of the function that is being registered.
You must call ifxOS_set_thrfunc() once for each of the 17 ifxOS functions listed in Create a dynamic thread library on UNIX operating systems.
The ifxOS_set_thrfunc() function returns
0
if
it successfully registers the function and -1
if
it fails to register the function. For example, to register the user-defined
function my_mutex_lock() as the ifxOS_th_mutex_lock routine,
you use the following call: if (ifxOS_set_thrfunc(TH_MUTEX_LOCK, (mulong (*)())my_mutex_lock)
== -1)
TH_MUTEX_LOCK is defined in sqlhdr.h and tells the client to call my_mutex_lock() whenever it needs to lock a mutex.
The following list shows the indexes and the functions
they register.
- Index
- Function
- TH_ONCE
- ifxOS_th_once
- TH_MUTEXATTR_CREATE
- ifxOS_th_mutexattr_create()
- TH_MUTEXATTR_SETKIND
- ifxOS_th_mutexattr_setkind_np()
- TH_MUTEXATTR_DELETE
- ifxOS_th_mutexattr_delete()
- TH_MUTEX_INIT
- ifxOS_th_mutex_init()
- TH_MUTEX_DESTROY
- ifxOS_th_mutex_destroy()
- TH_MUTEX_LOCK
- ifxOS_th_mutex_lock()
- TH_MUTEX_UNLOCK
- ifxOS_th_mutex_unlock()
- TH_MUTEX_TRYLOCK
- ifxOS_th_mutex_trylock()
- TH_CONDATTR_CREATE
- ifxOS_th_condattr_create()
- TH_CONDATTR_DELETE
- ifxOS_th_condattr_delete()
- TH_COND_INIT
- ifxOS_th_cond_init()
- TH_COND_DESTROY
- ifxOS_th_cond_destroy()
- TH_COND_TIMEDWAIT
- ifxOS_th_cond_timedwait()
- TH_KEYCREATE
- ifxOS_th_keycreate()
- TH_GETSPECIFIC
- ifxOS_th_getspecific()
- TH_SETSPECIFIC
- ifxOS_th_setspecific()
The following function, dynthr_init(), which is
also defined in dynthr.c, registers the 17 functions defined
in Create a dynamic thread library on UNIX operating systems. FUNCFAIL
is defined to be
-1
. dynthr_init()
{
if (ifxOS_set_thrfunc(TH_ONCE, (mulong (*)())ifx_th_once)
== FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_MUTEXATTR_CREATE,
(mulong (*)())ifx_th_mutexattr_create) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_MUTEXATTR_SETKIND,
(mulong (*)())ifx_th_mutexattr_setkind_np) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_MUTEXATTR_DELETE,
(mulong (*)())ifx_th_mutexattr_delete) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_MUTEX_INIT,
(mulong (*)())ifx_th_mutex_init) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_MUTEX_DESTROY,
(mulong (*)()) ifx_th_mutex_destroy) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_MUTEX_LOCK,
(mulong (*)()) ifx_th_mutex_lock) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_MUTEX_UNLOCK,
(mulong (*)())ifx_th_mutex_unlock) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_MUTEX_TRYLOCK,
(mulong (*)())ifx_th_mutex_trylock) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_CONDATTR_CREATE,
(mulong (*)())ifx_th_condattr_create) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_CONDATTR_DELETE,
(mulong (*)())ifx_th_condattr_delete) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_COND_INIT,
(mulong (*)())ifx_th_cond_init) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_COND_DESTROY,
(mulong (*)())ifx_th_cond_destroy) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_COND_TIMEDWAIT,
(mulong (*)())ifx_th_cond_timedwait) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_KEYCREATE,
(mulong (*)())ifx_th_keycreate) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_GETSPECIFIC,
(mulong (*)())ifx_th_getspecific) == FUNCFAIL)
return FUNCFAIL;
if (ifxOS_set_thrfunc(TH_SETSPECIFIC,
(mulong (*)())ifx_th_setspecific) == FUNCFAIL)
return FUNCFAIL;
return 0;
}