1 /*****************************************************************************
2 * threads.c : threads implementation for the VideoLAN client
3 *****************************************************************************
4 * Copyright (C) 1999-2008 the VideoLAN team
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@netcourrier.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
31 #include <vlc_common.h>
41 #define VLC_THREADS_UNINITIALIZED 0
42 #define VLC_THREADS_PENDING 1
43 #define VLC_THREADS_ERROR 2
44 #define VLC_THREADS_READY 3
46 /*****************************************************************************
47 * Global mutex for lazy initialization of the threads system
48 *****************************************************************************/
49 static volatile unsigned i_initializations = 0;
51 #if defined( LIBVLC_USE_PTHREAD )
54 static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
58 * Global process-wide VLC object.
59 * Contains inter-instance data, such as the module cache and global mutexes.
61 static libvlc_global_data_t *p_root;
63 libvlc_global_data_t *vlc_global( void )
65 assert( i_initializations > 0 );
69 #ifdef HAVE_EXECINFO_H
70 # include <execinfo.h>
74 * Print a backtrace to the standard error for debugging purpose.
76 void vlc_trace (const char *fn, const char *file, unsigned line)
78 fprintf (stderr, "at %s:%u in %s\n", file, line, fn);
79 fflush (stderr); /* needed before switch to low-level I/O */
82 int len = backtrace (stack, sizeof (stack) / sizeof (stack[0]));
83 backtrace_symbols_fd (stack, len, 2);
90 static inline unsigned long vlc_threadid (void)
92 #if defined(LIBVLC_USE_PTHREAD)
93 union { pthread_t th; unsigned long int i; } v = { };
94 v.th = pthread_self ();
98 return GetCurrentThread ();
106 /*****************************************************************************
107 * vlc_thread_fatal: Report an error from the threading layer
108 *****************************************************************************
109 * This is mostly meant for debugging.
110 *****************************************************************************/
111 void vlc_thread_fatal (const char *action, int error, const char *function,
112 const char *file, unsigned line)
114 fprintf (stderr, "LibVLC fatal error %s (%d) in thread %lu ",
115 action, error, vlc_threadid ());
116 vlc_trace (function, file, line);
118 /* Sometimes strerror_r() crashes too, so make sure we print an error
119 * message before we invoke it */
121 /* Avoid the strerror_r() prototype brain damage in glibc */
123 fprintf (stderr, " Error message: %m at:\n");
128 switch (strerror_r (error, buf, sizeof (buf)))
133 case ERANGE: /* should never happen */
134 msg = "unknwon (too big to display)";
137 msg = "unknown (invalid error number)";
140 fprintf (stderr, " Error message: %s\n", msg);
148 * Per-thread cancellation data
150 #ifndef LIBVLC_USE_PTHREAD_CANCEL
151 typedef struct vlc_cancel_t
153 vlc_cleanup_t *cleaners;
158 # define VLC_CANCEL_INIT { NULL, false, true }
161 /*****************************************************************************
162 * vlc_threads_init: initialize threads system
163 *****************************************************************************
164 * This function requires lazy initialization of a global lock in order to
165 * keep the library really thread-safe. Some architectures don't support this
166 * and thus do not guarantee the complete reentrancy.
167 *****************************************************************************/
168 int vlc_threads_init( void )
170 int i_ret = VLC_SUCCESS;
172 /* If we have lazy mutex initialization, use it. Otherwise, we just
173 * hope nothing wrong happens. */
174 #if defined( LIBVLC_USE_PTHREAD )
175 pthread_mutex_lock( &once_mutex );
178 if( i_initializations == 0 )
180 p_root = vlc_custom_create( (vlc_object_t *)NULL, sizeof( *p_root ),
181 VLC_OBJECT_GENERIC, "root" );
188 /* We should be safe now. Do all the initialization stuff we want. */
189 #ifndef LIBVLC_USE_PTHREAD_CANCEL
190 vlc_threadvar_create( &cancel_key, free );
196 /* If we have lazy mutex initialization support, unlock the mutex.
197 * Otherwize, we are screwed. */
198 #if defined( LIBVLC_USE_PTHREAD )
199 pthread_mutex_unlock( &once_mutex );
205 /*****************************************************************************
206 * vlc_threads_end: stop threads system
207 *****************************************************************************
208 * FIXME: This function is far from being threadsafe.
209 *****************************************************************************/
210 void vlc_threads_end( void )
212 #if defined( LIBVLC_USE_PTHREAD )
213 pthread_mutex_lock( &once_mutex );
216 assert( i_initializations > 0 );
218 if( i_initializations == 1 )
220 vlc_object_release( p_root );
221 #ifndef LIBVLC_USE_PTHREAD
222 vlc_threadvar_delete( &cancel_key );
227 #if defined( LIBVLC_USE_PTHREAD )
228 pthread_mutex_unlock( &once_mutex );
232 #if defined (__GLIBC__) && (__GLIBC_MINOR__ < 6)
233 /* This is not prototyped under glibc, though it exists. */
234 int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
237 /*****************************************************************************
238 * vlc_mutex_init: initialize a mutex
239 *****************************************************************************/
240 int vlc_mutex_init( vlc_mutex_t *p_mutex )
242 #if defined( LIBVLC_USE_PTHREAD )
243 pthread_mutexattr_t attr;
246 pthread_mutexattr_init( &attr );
249 /* Create error-checking mutex to detect problems more easily. */
250 # if defined (__GLIBC__) && (__GLIBC_MINOR__ < 6)
251 pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP );
253 pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK );
256 i_result = pthread_mutex_init( p_mutex, &attr );
257 pthread_mutexattr_destroy( &attr );
259 #elif defined( UNDER_CE )
260 InitializeCriticalSection( &p_mutex->csection );
263 #elif defined( WIN32 )
264 *p_mutex = CreateMutex( 0, FALSE, 0 );
265 return (*p_mutex != NULL) ? 0 : ENOMEM;
267 #elif defined( HAVE_KERNEL_SCHEDULER_H )
268 /* check the arguments and whether it's already been initialized */
269 if( p_mutex == NULL )
274 if( p_mutex->init == 9999 )
279 p_mutex->lock = create_sem( 1, "BeMutex" );
280 if( p_mutex->lock < B_NO_ERROR )
285 p_mutex->init = 9999;
291 /*****************************************************************************
292 * vlc_mutex_init: initialize a recursive mutex (Do not use)
293 *****************************************************************************/
294 int vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
296 #if defined( LIBVLC_USE_PTHREAD )
297 pthread_mutexattr_t attr;
300 pthread_mutexattr_init( &attr );
301 # if defined (__GLIBC__) && (__GLIBC_MINOR__ < 6)
302 pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_RECURSIVE_NP );
304 pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
306 i_result = pthread_mutex_init( p_mutex, &attr );
307 pthread_mutexattr_destroy( &attr );
309 #elif defined( WIN32 )
310 /* Create mutex returns a recursive mutex */
311 *p_mutex = CreateMutex( 0, FALSE, 0 );
312 return (*p_mutex != NULL) ? 0 : ENOMEM;
314 # error Unimplemented!
319 /*****************************************************************************
320 * vlc_mutex_destroy: destroy a mutex, inner version
321 *****************************************************************************/
322 void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex )
324 #if defined( LIBVLC_USE_PTHREAD )
325 int val = pthread_mutex_destroy( p_mutex );
326 VLC_THREAD_ASSERT ("destroying mutex");
328 #elif defined( UNDER_CE )
329 VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
331 DeleteCriticalSection( &p_mutex->csection );
333 #elif defined( WIN32 )
334 VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
336 CloseHandle( *p_mutex );
338 #elif defined( HAVE_KERNEL_SCHEDULER_H )
339 if( p_mutex->init == 9999 )
340 delete_sem( p_mutex->lock );
347 /*****************************************************************************
348 * vlc_cond_init: initialize a condition
349 *****************************************************************************/
350 int __vlc_cond_init( vlc_cond_t *p_condvar )
352 #if defined( LIBVLC_USE_PTHREAD )
353 pthread_condattr_t attr;
356 ret = pthread_condattr_init (&attr);
360 # if !defined (_POSIX_CLOCK_SELECTION)
361 /* Fairly outdated POSIX support (that was defined in 2001) */
362 # define _POSIX_CLOCK_SELECTION (-1)
364 # if (_POSIX_CLOCK_SELECTION >= 0)
365 /* NOTE: This must be the same clock as the one in mtime.c */
366 pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
369 ret = pthread_cond_init (p_condvar, &attr);
370 pthread_condattr_destroy (&attr);
373 #elif defined( UNDER_CE ) || defined( WIN32 )
374 /* Create an auto-reset event. */
375 *p_condvar = CreateEvent( NULL, /* no security */
376 FALSE, /* auto-reset event */
377 FALSE, /* start non-signaled */
378 NULL ); /* unnamed */
379 return *p_condvar ? 0 : ENOMEM;
381 #elif defined( HAVE_KERNEL_SCHEDULER_H )
387 if( p_condvar->init == 9999 )
392 p_condvar->thread = -1;
393 p_condvar->init = 9999;
399 /*****************************************************************************
400 * vlc_cond_destroy: destroy a condition, inner version
401 *****************************************************************************/
402 void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar )
404 #if defined( LIBVLC_USE_PTHREAD )
405 int val = pthread_cond_destroy( p_condvar );
406 VLC_THREAD_ASSERT ("destroying condition");
408 #elif defined( UNDER_CE ) || defined( WIN32 )
409 VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
411 CloseHandle( *p_condvar );
413 #elif defined( HAVE_KERNEL_SCHEDULER_H )
419 /*****************************************************************************
420 * vlc_tls_create: create a thread-local variable
421 *****************************************************************************/
422 int vlc_threadvar_create( vlc_threadvar_t *p_tls, void (*destr) (void *) )
426 #if defined( LIBVLC_USE_PTHREAD )
427 i_ret = pthread_key_create( p_tls, destr );
428 #elif defined( UNDER_CE )
430 #elif defined( WIN32 )
431 /* FIXME: remember/use the destr() callback and stop leaking whatever */
433 i_ret = (*p_tls == TLS_OUT_OF_INDEXES) ? EAGAIN : 0;
435 # error Unimplemented!
440 void vlc_threadvar_delete (vlc_threadvar_t *p_tls)
442 #if defined( LIBVLC_USE_PTHREAD )
443 pthread_key_delete (*p_tls);
444 #elif defined( UNDER_CE )
445 #elif defined( WIN32 )
448 # error Unimplemented!
452 #if defined (LIBVLC_USE_PTHREAD)
453 #elif defined (WIN32)
454 static unsigned __stdcall vlc_entry (void *data)
456 vlc_cancel_t cancel_data = VLC_CANCEL_INIT;
457 vlc_thread_t self = data;
459 vlc_threadvar_set (&cancel_key, &cancel_data);
460 self->data = self->entry (self->data);
466 * Creates and starts new thread.
468 * @param p_handle [OUT] pointer to write the handle of the created thread to
469 * @param entry entry point for the thread
470 * @param data data parameter given to the entry point
471 * @param priority thread priority value
472 * @return 0 on success, a standard error code on error.
474 int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
479 #if defined( LIBVLC_USE_PTHREAD )
481 pthread_attr_init (&attr);
483 /* Block the signals that signals interface plugin handles.
484 * If the LibVLC caller wants to handle some signals by itself, it should
485 * block these before whenever invoking LibVLC. And it must obviously not
486 * start the VLC signals interface plugin.
488 * LibVLC will normally ignore any interruption caused by an asynchronous
489 * signal during a system call. But there may well be some buggy cases
490 * where it fails to handle EINTR (bug reports welcome). Some underlying
491 * libraries might also not handle EINTR properly.
497 sigdelset (&set, SIGHUP);
498 sigaddset (&set, SIGINT);
499 sigaddset (&set, SIGQUIT);
500 sigaddset (&set, SIGTERM);
502 sigaddset (&set, SIGPIPE); /* We don't want this one, really! */
503 pthread_sigmask (SIG_BLOCK, &set, &oldset);
506 struct sched_param sp = { .sched_priority = priority, };
509 if (sp.sched_priority <= 0)
510 sp.sched_priority += sched_get_priority_max (policy = SCHED_OTHER);
512 sp.sched_priority += sched_get_priority_min (policy = SCHED_RR);
514 pthread_attr_setschedpolicy (&attr, policy);
515 pthread_attr_setschedparam (&attr, &sp);
518 ret = pthread_create (p_handle, &attr, entry, data);
519 pthread_sigmask (SIG_SETMASK, &oldset, NULL);
520 pthread_attr_destroy (&attr);
522 #elif defined( WIN32 ) || defined( UNDER_CE )
523 /* When using the MSVCRT C library you have to use the _beginthreadex
524 * function instead of CreateThread, otherwise you'll end up with
525 * memory leaks and the signal functions not working (see Microsoft
526 * Knowledge Base, article 104641) */
528 vlc_thread_t th = malloc (sizeof (*th));
535 #if defined( UNDER_CE )
536 hThread = CreateThread (NULL, 0, vlc_entry, th, CREATE_SUSPENDED, NULL);
538 hThread = (HANDLE)(uintptr_t)
539 _beginthreadex (NULL, 0, vlc_entry, th, CREATE_SUSPENDED, NULL);
544 /* Thread closes the handle when exiting, duplicate it here
545 * to be on the safe side when joining. */
546 if (!DuplicateHandle (GetCurrentProcess (), hThread,
547 GetCurrentProcess (), &th->handle, 0, FALSE,
548 DUPLICATE_SAME_ACCESS))
550 CloseHandle (hThread);
555 ResumeThread (hThread);
557 SetThreadPriority (hThread, priority);
568 #elif defined( HAVE_KERNEL_SCHEDULER_H )
569 *p_handle = spawn_thread( entry, psz_name, priority, data );
570 ret = resume_thread( *p_handle );
577 /* APC procedure for thread cancellation */
578 static void CALLBACK vlc_cancel_self (ULONG_PTR dummy)
581 vlc_control_cancel (VLC_DO_CANCEL);
586 * Marks a thread as cancelled. Next time the target thread reaches a
587 * cancellation point (while not having disabled cancellation), it will
588 * run its cancellation cleanup handler, the thread variable destructors, and
589 * terminate. vlc_join() must be used afterward regardless of a thread being
592 void vlc_cancel (vlc_thread_t thread_id)
594 #if defined (LIBVLC_USE_PTHREAD_CANCEL)
595 pthread_cancel (thread_id);
596 #elif defined (WIN32)
597 QueueUserAPC (vlc_cancel_self, thread_id->handle, 0);
599 # warning vlc_cancel is not implemented!
604 * Waits for a thread to complete (if needed), and destroys it.
605 * This is a cancellation point; in case of cancellation, the join does _not_
608 * @param handle thread handle
609 * @param p_result [OUT] pointer to write the thread return value or NULL
610 * @return 0 on success, a standard error code otherwise.
612 void vlc_join (vlc_thread_t handle, void **result)
614 #if defined( LIBVLC_USE_PTHREAD )
615 int val = pthread_join (handle, result);
617 vlc_thread_fatal ("joining thread", val, __func__, __FILE__, __LINE__);
619 #elif defined( UNDER_CE ) || defined( WIN32 )
622 while (WaitForSingleObjectEx (handle->handle, INFINITE, TRUE)
623 == WAIT_IO_COMPLETION);
625 CloseHandle (handle->handle);
627 *result = handle->data;
630 #elif defined( HAVE_KERNEL_SCHEDULER_H )
632 int val = (B_OK == wait_for_thread( p_priv->thread_id, &exit_value ));
634 *result = (void *)exit_value;
640 struct vlc_thread_boot
642 void * (*entry) (vlc_object_t *);
643 vlc_object_t *object;
646 static void *thread_entry (void *data)
648 vlc_object_t *obj = ((struct vlc_thread_boot *)data)->object;
649 void *(*func) (vlc_object_t *) = ((struct vlc_thread_boot *)data)->entry;
652 msg_Dbg (obj, "thread started");
654 msg_Dbg (obj, "thread ended");
659 /*****************************************************************************
660 * vlc_thread_create: create a thread, inner version
661 *****************************************************************************
662 * Note that i_priority is only taken into account on platforms supporting
663 * userland real-time priority threads.
664 *****************************************************************************/
665 int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line,
666 const char *psz_name, void * ( *func ) ( vlc_object_t * ),
667 int i_priority, bool b_wait )
670 vlc_object_internals_t *p_priv = vlc_internals( p_this );
672 struct vlc_thread_boot *boot = malloc (sizeof (*boot));
676 boot->object = p_this;
678 vlc_object_lock( p_this );
680 /* Make sure we don't re-create a thread if the object has already one */
681 assert( !p_priv->b_thread );
683 #if defined( LIBVLC_USE_PTHREAD )
685 if( config_GetInt( p_this, "rt-priority" ) > 0 )
688 /* Hack to avoid error msg */
689 if( config_GetType( p_this, "rt-offset" ) )
690 i_priority += config_GetInt( p_this, "rt-offset" );
694 i_ret = vlc_clone( &p_priv->thread_id, thread_entry, boot, i_priority );
699 msg_Dbg( p_this, "waiting for thread initialization" );
700 vlc_object_wait( p_this );
703 p_priv->b_thread = true;
704 msg_Dbg( p_this, "thread %lu (%s) created at priority %d (%s:%d)",
705 (unsigned long)p_priv->thread_id, psz_name, i_priority,
711 msg_Err( p_this, "%s thread could not be created at %s:%d (%m)",
712 psz_name, psz_file, i_line );
715 vlc_object_unlock( p_this );
719 /*****************************************************************************
720 * vlc_thread_set_priority: set the priority of the current thread when we
721 * couldn't set it in vlc_thread_create (for instance for the main thread)
722 *****************************************************************************/
723 int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
724 int i_line, int i_priority )
726 vlc_object_internals_t *p_priv = vlc_internals( p_this );
728 if( !p_priv->b_thread )
730 msg_Err( p_this, "couldn't set priority of non-existent thread" );
734 #if defined( LIBVLC_USE_PTHREAD )
736 if( config_GetInt( p_this, "rt-priority" ) > 0 )
739 int i_error, i_policy;
740 struct sched_param param;
742 memset( ¶m, 0, sizeof(struct sched_param) );
743 if( config_GetType( p_this, "rt-offset" ) )
744 i_priority += config_GetInt( p_this, "rt-offset" );
745 if( i_priority <= 0 )
747 param.sched_priority = (-1) * i_priority;
748 i_policy = SCHED_OTHER;
752 param.sched_priority = i_priority;
755 if( (i_error = pthread_setschedparam( p_priv->thread_id,
756 i_policy, ¶m )) )
759 msg_Warn( p_this, "couldn't set thread priority (%s:%d): %m",
765 #elif defined( WIN32 ) || defined( UNDER_CE )
766 VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
768 if( !SetThreadPriority(p_priv->thread_id->handle, i_priority) )
770 msg_Warn( p_this, "couldn't set a faster priority" );
779 /*****************************************************************************
780 * vlc_thread_join: wait until a thread exits, inner version
781 *****************************************************************************/
782 void __vlc_thread_join( vlc_object_t *p_this )
784 vlc_object_internals_t *p_priv = vlc_internals( p_this );
786 #if defined( LIBVLC_USE_PTHREAD )
787 vlc_join (p_priv->thread_id, NULL);
789 #elif defined( UNDER_CE ) || defined( WIN32 )
791 FILETIME create_ft, exit_ft, kernel_ft, user_ft;
792 int64_t real_time, kernel_time, user_time;
794 if( ! DuplicateHandle(GetCurrentProcess(),
795 p_priv->thread_id->handle,
800 DUPLICATE_SAME_ACCESS) )
802 p_priv->b_thread = false;
803 return; /* We have a problem! */
806 vlc_join( p_priv->thread_id, NULL );
808 if( GetThreadTimes( hThread, &create_ft, &exit_ft, &kernel_ft, &user_ft ) )
811 ((((int64_t)exit_ft.dwHighDateTime)<<32)| exit_ft.dwLowDateTime) -
812 ((((int64_t)create_ft.dwHighDateTime)<<32)| create_ft.dwLowDateTime);
816 ((((int64_t)kernel_ft.dwHighDateTime)<<32)|
817 kernel_ft.dwLowDateTime) / 10;
820 ((((int64_t)user_ft.dwHighDateTime)<<32)|
821 user_ft.dwLowDateTime) / 10;
823 msg_Dbg( p_this, "thread times: "
824 "real %"PRId64"m%fs, kernel %"PRId64"m%fs, user %"PRId64"m%fs",
825 real_time/60/1000000,
826 (double)((real_time%(60*1000000))/1000000.0),
827 kernel_time/60/1000000,
828 (double)((kernel_time%(60*1000000))/1000000.0),
829 user_time/60/1000000,
830 (double)((user_time%(60*1000000))/1000000.0) );
832 CloseHandle( hThread );
835 vlc_join( p_priv->thread_id, NULL );
839 p_priv->b_thread = false;
842 void vlc_thread_cancel (vlc_object_t *obj)
844 vlc_object_internals_t *priv = vlc_internals (obj);
847 vlc_cancel (priv->thread_id);
850 void vlc_control_cancel (int cmd, ...)
852 /* NOTE: This function only modifies thread-specific data, so there is no
853 * need to lock anything. */
854 #ifdef LIBVLC_USE_PTHREAD_CANCEL
862 vlc_cancel_t *nfo = vlc_threadvar_get (&cancel_key);
866 /* Main thread - cannot be cancelled anyway */
869 nfo = malloc (sizeof (*nfo));
871 return; /* Uho! Expect problems! */
872 *nfo = VLC_CANCEL_INIT;
873 vlc_threadvar_set (&cancel_key, nfo);
879 case VLC_SAVE_CANCEL:
881 int *p_state = va_arg (ap, int *);
882 *p_state = nfo->killable;
883 nfo->killable = false;
887 case VLC_RESTORE_CANCEL:
889 int state = va_arg (ap, int);
890 nfo->killable = state != 0;
894 case VLC_TEST_CANCEL:
895 if (nfo->killable && nfo->killed)
897 for (vlc_cleanup_t *p = nfo->cleaners; p != NULL; p = p->next)
900 #if defined (LIBVLC_USE_PTHREAD)
901 pthread_exit (PTHREAD_CANCELLED);
902 #elif defined (WIN32)
905 # error Not implemented!
914 case VLC_CLEANUP_PUSH:
916 /* cleaner is a pointer to the caller stack, no need to allocate
917 * and copy anything. As a nice side effect, this cannot fail. */
918 vlc_cleanup_t *cleaner = va_arg (ap, vlc_cleanup_t *);
919 cleaner->next = nfo->cleaners;
920 nfo->cleaners = cleaner;
924 case VLC_CLEANUP_POP:
926 nfo->cleaners = nfo->cleaners->next;