* src/misc/threads.c, src/misc/win32_specific.c, include/interface.h: fixed typos.
[vlc.git] / src / misc / threads.c
1 /*****************************************************************************
2  * threads.c : threads implementation for the VideoLAN client
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
5  * $Id: threads.c,v 1.20 2002/10/04 12:01:40 gbazin Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Gildas Bazin <gbazin@netcourrier.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 #include <vlc/vlc.h>
27
28 #define VLC_THREADS_UNINITIALIZED  0
29 #define VLC_THREADS_PENDING        1
30 #define VLC_THREADS_ERROR          2
31 #define VLC_THREADS_READY          3
32
33 /*****************************************************************************
34  * Global mutex for lazy initialization of the threads system
35  *****************************************************************************/
36 static volatile int i_initializations = 0;
37
38 #if defined( PTH_INIT_IN_PTH_H )
39 #elif defined( ST_INIT_IN_ST_H )
40 #elif defined( WIN32 )
41 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
42     static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
43 #elif defined( HAVE_CTHREADS_H )
44 #elif defined( HAVE_KERNEL_SCHEDULER_H )
45 #endif
46
47 /*****************************************************************************
48  * vlc_threads_init: initialize threads system
49  *****************************************************************************
50  * This function requires lazy initialization of a global lock in order to
51  * keep the library really thread-safe. Some architectures don't support this
52  * and thus do not guarantee the complete reentrancy.
53  *****************************************************************************/
54 int __vlc_threads_init( vlc_object_t *p_this )
55 {
56     static volatile int i_status = VLC_THREADS_UNINITIALIZED;
57
58     libvlc_t *p_libvlc = (libvlc_t *)p_this;
59     int i_ret = VLC_SUCCESS;
60
61     /* If we have lazy mutex initialization, use it. Otherwise, we just
62      * hope nothing wrong happens. */
63 #if defined( PTH_INIT_IN_PTH_H )
64 #elif defined( ST_INIT_IN_ST_H )
65 #elif defined( WIN32 )
66     HINSTANCE hInstLib;
67 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
68     pthread_mutex_lock( &once_mutex );
69 #elif defined( HAVE_CTHREADS_H )
70 #elif defined( HAVE_KERNEL_SCHEDULER_H )
71 #endif
72
73     if( i_status == VLC_THREADS_UNINITIALIZED )
74     {
75         i_status = VLC_THREADS_PENDING;
76
77         /* We should be safe now. Do all the initialization stuff we want. */
78         vlc_object_create( p_libvlc, VLC_OBJECT_ROOT );
79         p_libvlc->b_ready = VLC_FALSE;
80
81 #if defined( PTH_INIT_IN_PTH_H )
82         i_ret = pth_init();
83
84 #elif defined( ST_INIT_IN_ST_H )
85         i_ret = st_init();
86
87 #elif defined( WIN32 )
88         /* Dynamically get the address of SignalObjectAndWait */
89         if( GetVersion() < 0x80000000 )
90         {
91             /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
92             hInstLib = LoadLibrary( "kernel32" );
93             if( hInstLib )
94             {
95                 p_libvlc->SignalObjectAndWait =
96                     (SIGNALOBJECTANDWAIT)GetProcAddress( hInstLib,
97                                                      "SignalObjectAndWait" );
98             }
99         }
100         else
101         {
102             p_libvlc->SignalObjectAndWait = NULL;
103         }
104
105         p_libvlc->b_fast_mutex = 0;
106         p_libvlc->i_win9x_cv = 0;
107
108 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
109 #elif defined( HAVE_CTHREADS_H )
110 #elif defined( HAVE_KERNEL_SCHEDULER_H )
111 #endif
112
113         vlc_mutex_init( p_libvlc, &p_libvlc->global_lock );
114
115         if( i_ret )
116         {
117             i_status = VLC_THREADS_ERROR;
118         }
119         else
120         {
121             i_initializations++;
122             i_status = VLC_THREADS_READY;
123         }
124     }
125     else
126     {
127         /* Just increment the initialization count */
128         i_initializations++;
129     }
130
131     /* If we have lazy mutex initialization support, unlock the mutex;
132      * otherwize, do a naive wait loop. */
133 #if defined( PTH_INIT_IN_PTH_H )
134     while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
135 #elif defined( ST_INIT_IN_ST_H )
136     while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
137 #elif defined( WIN32 )
138     while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
139 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
140     pthread_mutex_unlock( &once_mutex );
141 #elif defined( HAVE_CTHREADS_H )
142     while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
143 #elif defined( HAVE_KERNEL_SCHEDULER_H )
144     while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
145 #endif
146
147     if( i_status != VLC_THREADS_READY )
148     {
149         return VLC_ETHREAD;
150     }
151
152     return i_ret;
153 }
154
155 /*****************************************************************************
156  * vlc_threads_end: stop threads system
157  *****************************************************************************
158  * FIXME: This function is far from being threadsafe. We should undo exactly
159  * what we did above in vlc_threads_init.
160  *****************************************************************************/
161 int __vlc_threads_end( vlc_object_t *p_this )
162 {
163 #if defined( PTH_INIT_IN_PTH_H )
164     i_initializations--;
165     if( i_initializations == 0 )
166     {
167         return pth_kill();
168     }
169
170 #elif defined( ST_INIT_IN_ST_H )
171     i_initializations--;
172
173 #elif defined( WIN32 )
174     i_initializations--;
175
176 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
177     pthread_mutex_lock( &once_mutex );
178     i_initializations--;
179     pthread_mutex_unlock( &once_mutex );
180
181 #elif defined( HAVE_CTHREADS_H )
182     i_initializations--;
183
184 #elif defined( HAVE_KERNEL_SCHEDULER_H )
185     i_initializations--;
186
187 #endif
188     return VLC_SUCCESS;
189 }
190
191 /*****************************************************************************
192  * Prototype for GPROF wrapper
193  *****************************************************************************/
194 #ifdef GPROF
195 /* Wrapper function for profiling */
196 static void *      vlc_thread_wrapper ( void *p_wrapper );
197
198 #   ifdef WIN32
199
200 #       define ITIMER_REAL 1
201 #       define ITIMER_PROF 2
202
203 struct itimerval
204 {
205     struct timeval it_value;
206     struct timeval it_interval;
207 };  
208
209 int setitimer(int kind, const struct itimerval* itnew, struct itimerval* itold);
210 #   endif /* WIN32 */
211
212 typedef struct wrapper_t
213 {
214     /* Data lock access */
215     vlc_mutex_t lock;
216     vlc_cond_t  wait;
217     
218     /* Data used to spawn the real thread */
219     vlc_thread_func_t func;
220     void *p_data;
221     
222     /* Profiling timer passed to the thread */
223     struct itimerval itimer;
224     
225 } wrapper_t;
226
227 #endif /* GPROF */
228
229 /*****************************************************************************
230  * vlc_mutex_init: initialize a mutex
231  *****************************************************************************/
232 int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex )
233 {
234     p_mutex->p_this = p_this;
235
236 #if defined( PTH_INIT_IN_PTH_H )
237     return pth_mutex_init( &p_mutex->mutex );
238
239 #elif defined( ST_INIT_IN_ST_H )
240     p_mutex->mutex = st_mutex_new();
241     return ( p_mutex->mutex == NULL ) ? errno : 0;
242
243 #elif defined( WIN32 )
244     /* We use mutexes on WinNT/2K/XP because we can use the SignalObjectAndWait
245      * function and have a 100% correct vlc_cond_wait() implementation.
246      * As this function is not available on Win9x, we can use the faster
247      * CriticalSections */
248     if( p_this->p_libvlc->SignalObjectAndWait &&
249         !p_this->p_libvlc->b_fast_mutex )
250     {
251         /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
252         p_mutex->mutex = CreateMutex( 0, FALSE, 0 );
253         return ( p_mutex->mutex != NULL ? 0 : 1 );
254     }
255     else
256     {
257         p_mutex->mutex = NULL;
258         InitializeCriticalSection( &p_mutex->csection );
259         return 0;
260     }
261
262 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
263 #   if defined(DEBUG) && defined(SYS_LINUX)
264     {
265         /* Create error-checking mutex to detect problems more easily. */
266         pthread_mutexattr_t attr;
267         int                 i_result;
268
269         pthread_mutexattr_init( &attr );
270         pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP );
271         i_result = pthread_mutex_init( &p_mutex->mutex, &attr );
272         pthread_mutexattr_destroy( &attr );
273         return( i_result );
274     }
275 #   endif
276     return pthread_mutex_init( &p_mutex->mutex, NULL );
277
278 #elif defined( HAVE_CTHREADS_H )
279     mutex_init( p_mutex );
280     return 0;
281
282 #elif defined( HAVE_KERNEL_SCHEDULER_H )
283     /* check the arguments and whether it's already been initialized */
284     if( p_mutex == NULL )
285     {
286         return B_BAD_VALUE;
287     }
288
289     if( p_mutex->init == 9999 )
290     {
291         return EALREADY;
292     }
293
294     p_mutex->lock = create_sem( 1, "BeMutex" );
295     if( p_mutex->lock < B_NO_ERROR )
296     {
297         return( -1 );
298     }
299
300     p_mutex->init = 9999;
301     return B_OK;
302
303 #endif
304 }
305
306 /*****************************************************************************
307  * vlc_mutex_destroy: destroy a mutex, inner version
308  *****************************************************************************/
309 int __vlc_mutex_destroy( char * psz_file, int i_line, vlc_mutex_t *p_mutex )
310 {
311     int i_result;
312     /* In case of error : */
313     int i_thread = -1;
314     const char * psz_error = "";
315
316 #if defined( PTH_INIT_IN_PTH_H )
317     return 0;
318
319 #elif defined( ST_INIT_IN_ST_H )
320     i_result = st_mutex_destroy( p_mutex->mutex );
321
322 #elif defined( WIN32 )
323     if( p_mutex->mutex )
324     {
325         CloseHandle( p_mutex->mutex );
326     }
327     else
328     {
329         DeleteCriticalSection( &p_mutex->csection );
330     }
331     return 0;
332
333 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )    
334     i_result = pthread_mutex_destroy( &p_mutex->mutex );
335     if ( i_result )
336     {
337         i_thread = (int)pthread_self();
338         psz_error = strerror(i_result);
339     }
340
341 #elif defined( HAVE_CTHREADS_H )
342     return 0;
343
344 #elif defined( HAVE_KERNEL_SCHEDULER_H )
345     if( p_mutex->init == 9999 )
346     {
347         delete_sem( p_mutex->lock );
348     }
349
350     p_mutex->init = 0;
351     return B_OK;
352 #endif    
353
354     if( i_result )
355     {
356         msg_Err( p_mutex->p_this,
357                  "thread %d: mutex_destroy failed at %s:%d (%d:%s)",
358                  i_thread, psz_file, i_line, i_result, psz_error );
359     }
360     return i_result;
361 }
362
363 /*****************************************************************************
364  * vlc_cond_init: initialize a condition
365  *****************************************************************************/
366 int __vlc_cond_init( vlc_object_t *p_this, vlc_cond_t *p_condvar )
367 {
368     p_condvar->p_this = p_this;
369
370 #if defined( PTH_INIT_IN_PTH_H )
371     return pth_cond_init( &p_condvar->cond );
372
373 #elif defined( ST_INIT_IN_ST_H )
374     p_condvar->cond = st_cond_new();
375     return ( p_condvar->cond == NULL ) ? errno : 0;
376
377 #elif defined( WIN32 )
378     /* Initialize counter */
379     p_condvar->i_waiting_threads = 0;
380
381     /* Misc init */
382     p_condvar->i_win9x_cv = p_this->p_libvlc->i_win9x_cv;
383     p_condvar->SignalObjectAndWait = p_this->p_libvlc->SignalObjectAndWait;
384
385     if( (p_condvar->SignalObjectAndWait && !p_this->p_libvlc->b_fast_mutex)
386         || p_condvar->i_win9x_cv == 0 )
387     {
388         /* Create an auto-reset event. */
389         p_condvar->event = CreateEvent( NULL,   /* no security */
390                                         FALSE,  /* auto-reset event */
391                                         FALSE,  /* start non-signaled */
392                                         NULL ); /* unnamed */
393
394         p_condvar->semaphore = NULL;
395         return !p_condvar->event;
396     }
397     else
398     {
399         p_condvar->semaphore = CreateSemaphore( NULL,       /* no security */
400                                                 0,          /* initial count */
401                                                 0x7fffffff, /* max count */
402                                                 NULL );     /* unnamed */
403
404         if( p_condvar->i_win9x_cv == 1 )
405             /* Create a manual-reset event initially signaled. */
406             p_condvar->event = CreateEvent( NULL, TRUE, TRUE, NULL );
407         else
408             /* Create a auto-reset event. */
409             p_condvar->event = CreateEvent( NULL, FALSE, FALSE, NULL );
410
411         InitializeCriticalSection( &p_condvar->csection );
412
413         return !p_condvar->semaphore || !p_condvar->event;
414     }
415
416 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
417     return pthread_cond_init( &p_condvar->cond, NULL );
418
419 #elif defined( HAVE_CTHREADS_H )
420     /* condition_init() */
421     spin_lock_init( &p_condvar->lock );
422     cthread_queue_init( &p_condvar->queue );
423     p_condvar->name = 0;
424     p_condvar->implications = 0;
425
426     return 0;
427
428 #elif defined( HAVE_KERNEL_SCHEDULER_H )
429     if( !p_condvar )
430     {
431         return B_BAD_VALUE;
432     }
433
434     if( p_condvar->init == 9999 )
435     {
436         return EALREADY;
437     }
438
439     p_condvar->thread = -1;
440     p_condvar->init = 9999;
441     return 0;
442 #endif
443 }
444
445 /*****************************************************************************
446  * vlc_cond_destroy: destroy a condition, inner version
447  *****************************************************************************/
448 int __vlc_cond_destroy( char * psz_file, int i_line, vlc_cond_t *p_condvar )
449 {
450     int i_result;
451     /* In case of error : */
452     int i_thread = -1;
453     const char * psz_error = "";
454
455 #if defined( PTH_INIT_IN_PTH_H )
456     return 0;
457
458 #elif defined( ST_INIT_IN_ST_H )
459     i_result = st_cond_destroy( p_condvar->cond );
460
461 #elif defined( WIN32 )
462     if( !p_condvar->semaphore )
463         i_result = !CloseHandle( p_condvar->event );
464     else
465         i_result = !CloseHandle( p_condvar->event )
466           || !CloseHandle( p_condvar->semaphore );
467
468 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
469     i_result = pthread_cond_destroy( &p_condvar->cond );
470     if ( i_result )
471     {
472         i_thread = (int)pthread_self();
473         psz_error = strerror(i_result);
474     }
475
476 #elif defined( HAVE_CTHREADS_H )
477     return 0;
478
479 #elif defined( HAVE_KERNEL_SCHEDULER_H )
480     p_condvar->init = 0;
481     return 0;
482 #endif
483
484     if( i_result )
485     {
486         msg_Err( p_condvar->p_this,
487                  "thread %d: cond_destroy failed at %s:%d (%d:%s)",
488                  i_thread, psz_file, i_line, i_result, psz_error );
489     }
490     return i_result;
491 }
492
493 /*****************************************************************************
494  * vlc_thread_create: create a thread, inner version
495  *****************************************************************************
496  * Note that i_priority is only taken into account on platforms supporting
497  * userland real-time priority threads.
498  *****************************************************************************/
499 int __vlc_thread_create( vlc_object_t *p_this, char * psz_file, int i_line,
500                          char *psz_name, void * ( *func ) ( void * ),
501                          int i_priority, vlc_bool_t b_wait )
502 {
503     int i_ret;
504
505     vlc_mutex_lock( &p_this->object_lock );
506
507 #ifdef GPROF
508     wrapper_t wrapper;
509
510     /* Initialize the wrapper structure */
511     wrapper.func = func;
512     wrapper.p_data = (void *)p_this;
513     getitimer( ITIMER_PROF, &wrapper.itimer );
514     vlc_mutex_init( p_this, &wrapper.lock );
515     vlc_cond_init( p_this, &wrapper.wait );
516     vlc_mutex_lock( &wrapper.lock );
517
518     /* Alter user-passed data so that we call the wrapper instead
519      * of the real function */
520     p_data = &wrapper;
521     func = vlc_thread_wrapper;
522 #endif
523
524 #if defined( PTH_INIT_IN_PTH_H )
525     p_this->thread_id = pth_spawn( PTH_ATTR_DEFAULT, func, (void *)p_this );
526     i_ret = 0;
527
528 #elif defined( ST_INIT_IN_ST_H )
529     p_this->thread_id = st_thread_create( func, (void *)p_this, 1, 0 );
530     i_ret = 0;
531     
532 #elif defined( WIN32 )
533     {
534         unsigned threadID;
535         /* When using the MSVCRT C library you have to use the _beginthreadex
536          * function instead of CreateThread, otherwise you'll end up with
537          * memory leaks and the signal functions not working */
538         p_this->thread_id =
539                 (HANDLE)_beginthreadex( NULL, 0, (PTHREAD_START) func, 
540                                         (void *)p_this, 0, &threadID );
541     }
542
543     if ( p_this->thread_id && i_priority )
544     {
545         if ( !SetThreadPriority(p_this->thread_id, i_priority) )
546         {
547             msg_Warn( p_this, "couldn't set a faster priority" );
548             i_priority = 0;
549         }
550     }
551
552     i_ret = ( p_this->thread_id ? 0 : 1 );
553
554 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
555     i_ret = pthread_create( &p_this->thread_id, NULL, func, (void *)p_this );
556
557     if ( i_priority )
558     {
559         struct sched_param param;
560         memset( &param, 0, sizeof(struct sched_param) );
561         param.sched_priority = i_priority;
562         if ( pthread_setschedparam( p_this->thread_id, SCHED_RR, &param ) )
563         {
564             msg_Warn( p_this, "couldn't go to real-time priority" );
565             i_priority = 0;
566         }
567     }
568
569 #elif defined( HAVE_CTHREADS_H )
570     p_this->thread_id = cthread_fork( (cthread_fn_t)func, (any_t)p_this );
571     i_ret = 0;
572
573 #elif defined( HAVE_KERNEL_SCHEDULER_H )
574     p_this->thread_id = spawn_thread( (thread_func)func, psz_name,
575                                       B_NORMAL_PRIORITY, (void *)p_this );
576     i_ret = resume_thread( p_this->thread_id );
577
578 #endif
579
580 #ifdef GPROF
581     if( i_ret == 0 )
582     {
583         vlc_cond_wait( &wrapper.wait, &wrapper.lock );
584     }
585
586     vlc_mutex_unlock( &wrapper.lock );
587     vlc_mutex_destroy( &wrapper.lock );
588     vlc_cond_destroy( &wrapper.wait );
589 #endif
590
591     if( i_ret == 0 )
592     {
593         if( b_wait )
594         {
595             msg_Dbg( p_this, "waiting for thread completion" );
596             vlc_cond_wait( &p_this->object_wait, &p_this->object_lock );
597         }
598
599         p_this->b_thread = 1;
600
601         msg_Dbg( p_this, "thread %d (%s) created at priority %d (%s:%d)",
602                  p_this->thread_id, psz_name, i_priority,
603                  psz_file, i_line );
604
605         vlc_mutex_unlock( &p_this->object_lock );
606     }
607     else
608     {
609         msg_Err( p_this, "%s thread could not be created at %s:%d (%s)",
610                          psz_name, psz_file, i_line, strerror(i_ret) );
611         vlc_mutex_unlock( &p_this->object_lock );
612     }
613
614     return i_ret;
615 }
616
617 /*****************************************************************************
618  * vlc_thread_ready: tell the parent thread we were successfully spawned
619  *****************************************************************************/
620 void __vlc_thread_ready( vlc_object_t *p_this )
621 {
622     vlc_mutex_lock( &p_this->object_lock );
623     vlc_cond_signal( &p_this->object_wait );
624     vlc_mutex_unlock( &p_this->object_lock );
625 }
626
627 /*****************************************************************************
628  * vlc_thread_join: wait until a thread exits, inner version
629  *****************************************************************************/
630 void __vlc_thread_join( vlc_object_t *p_this, char * psz_file, int i_line )
631 {
632     int i_ret = 0;
633
634 #if defined( PTH_INIT_IN_PTH_H )
635     i_ret = pth_join( p_this->thread_id, NULL );
636
637 #elif defined( ST_INIT_IN_ST_H )
638     i_ret = st_thread_join( p_this->thread_id, NULL );
639     
640 #elif defined( WIN32 )
641     WaitForSingleObject( p_this->thread_id, INFINITE );
642
643 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
644     i_ret = pthread_join( p_this->thread_id, NULL );
645
646 #elif defined( HAVE_CTHREADS_H )
647     cthread_join( p_this->thread_id );
648     i_ret = 1;
649
650 #elif defined( HAVE_KERNEL_SCHEDULER_H )
651     int32 exit_value;
652     wait_for_thread( p_this->thread_id, &exit_value );
653
654 #endif
655
656     if( i_ret )
657     {
658         msg_Err( p_this, "thread_join(%d) failed at %s:%d (%s)",
659                          p_this->thread_id, psz_file, i_line, strerror(i_ret) );
660     }
661     else
662     {
663         msg_Dbg( p_this, "thread %d joined (%s:%d)",
664                          p_this->thread_id, psz_file, i_line );
665     }
666
667     p_this->b_thread = 0;
668 }
669
670 /*****************************************************************************
671  * vlc_thread_wrapper: wrapper around thread functions used when profiling.
672  *****************************************************************************/
673 #ifdef GPROF
674 static void *vlc_thread_wrapper( void *p_wrapper )
675 {
676     /* Put user data in thread-local variables */
677     void *            p_data = ((wrapper_t*)p_wrapper)->p_data;
678     vlc_thread_func_t func   = ((wrapper_t*)p_wrapper)->func;
679
680     /* Set the profile timer value */
681     setitimer( ITIMER_PROF, &((wrapper_t*)p_wrapper)->itimer, NULL );
682
683     /* Tell the calling thread that we don't need its data anymore */
684     vlc_mutex_lock( &((wrapper_t*)p_wrapper)->lock );
685     vlc_cond_signal( &((wrapper_t*)p_wrapper)->wait );
686     vlc_mutex_unlock( &((wrapper_t*)p_wrapper)->lock );
687
688     /* Call the real function */
689     return func( p_data );
690 }
691 #endif