gsttask: avoid join to return early
[platform/upstream/gstreamer.git] / gst / gsttask.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2005 Wim Taymans <wim@fluendo.com>
4  *
5  * gsttask.c: Streaming tasks
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /**
24  * SECTION:gsttask
25  * @short_description: Abstraction of GStreamer streaming threads.
26  * @see_also: #GstElement, #GstPad
27  *
28  * #GstTask is used by #GstElement and #GstPad to provide the data passing
29  * threads in a #GstPipeline.
30  *
31  * A #GstPad will typically start a #GstTask to push or pull data to/from the
32  * peer pads. Most source elements start a #GstTask to push data. In some cases
33  * a demuxer element can start a #GstTask to pull data from a peer element. This
34  * is typically done when the demuxer can perform random access on the upstream
35  * peer element for improved performance.
36  *
37  * Although convenience functions exist on #GstPad to start/pause/stop tasks, it 
38  * might sometimes be needed to create a #GstTask manually if it is not related to
39  * a #GstPad.
40  *
41  * Before the #GstTask can be run, it needs a #GStaticRecMutex that can be set with
42  * gst_task_set_lock().
43  *
44  * The task can be started, paused and stopped with gst_task_start(), gst_task_pause()
45  * and gst_task_stop() respectively or with the gst_task_set_state() function.
46  *
47  * A #GstTask will repeatedly call the #GstTaskFunction with the user data
48  * that was provided when creating the task with gst_task_create(). While calling
49  * the function it will acquire the provided lock. The provided lock is released
50  * when the task pauses or stops.
51  *
52  * Stopping a task with gst_task_stop() will not immediately make sure the task is
53  * not running anymore. Use gst_task_join() to make sure the task is completely
54  * stopped and the thread is stopped.
55  *
56  * After creating a #GstTask, use gst_object_unref() to free its resources. This can
57  * only be done it the task is not running anymore.
58  *
59  * Last reviewed on 2006-02-13 (0.10.4)
60  */
61
62 #include "gst_private.h"
63
64 #include "gstinfo.h"
65 #include "gsttask.h"
66
67 GST_DEBUG_CATEGORY_STATIC (task_debug);
68 #define GST_CAT_DEFAULT (task_debug)
69
70 #define GST_TASK_GET_PRIVATE(obj)  \
71    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_TASK, GstTaskPrivate))
72
73 struct _GstTaskPrivate
74 {
75   /* callbacks for managing the thread of this task */
76   GstTaskThreadCallbacks thr_callbacks;
77   gpointer thr_user_data;
78   GDestroyNotify thr_notify;
79
80   gboolean prio_set;
81   GThreadPriority priority;
82
83   /* configured pool */
84   GstTaskPool *pool;
85
86   /* remember the pool and id that is currently running. */
87   gpointer id;
88   GstTaskPool *pool_id;
89 };
90
91 static void gst_task_class_init (GstTaskClass * klass);
92 static void gst_task_init (GstTask * task);
93 static void gst_task_finalize (GObject * object);
94
95 static void gst_task_func (GstTask * task);
96
97 static GStaticMutex pool_lock = G_STATIC_MUTEX_INIT;
98
99 #define _do_init \
100 { \
101   GST_DEBUG_CATEGORY_INIT (task_debug, "task", 0, "Processing tasks"); \
102 }
103
104 G_DEFINE_TYPE_WITH_CODE (GstTask, gst_task, GST_TYPE_OBJECT, _do_init);
105
106 static void
107 init_klass_pool (GstTaskClass * klass)
108 {
109   g_static_mutex_lock (&pool_lock);
110   if (klass->pool) {
111     gst_task_pool_cleanup (klass->pool);
112     gst_object_unref (klass->pool);
113   }
114   klass->pool = gst_task_pool_new ();
115   gst_task_pool_prepare (klass->pool, NULL);
116   g_static_mutex_unlock (&pool_lock);
117 }
118
119 static void
120 gst_task_class_init (GstTaskClass * klass)
121 {
122   GObjectClass *gobject_class;
123
124   gobject_class = (GObjectClass *) klass;
125
126   g_type_class_add_private (klass, sizeof (GstTaskPrivate));
127
128   gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_task_finalize);
129
130   init_klass_pool (klass);
131 }
132
133 static void
134 gst_task_init (GstTask * task)
135 {
136   GstTaskClass *klass;
137
138   klass = GST_TASK_GET_CLASS (task);
139
140   task->priv = GST_TASK_GET_PRIVATE (task);
141   task->running = FALSE;
142   task->abidata.ABI.thread = NULL;
143   task->lock = NULL;
144   task->cond = g_cond_new ();
145   task->state = GST_TASK_STOPPED;
146   task->priv->prio_set = FALSE;
147
148   /* use the default klass pool for this task, users can
149    * override this later */
150   g_static_mutex_lock (&pool_lock);
151   task->priv->pool = gst_object_ref (klass->pool);
152   g_static_mutex_unlock (&pool_lock);
153 }
154
155 static void
156 gst_task_finalize (GObject * object)
157 {
158   GstTask *task = GST_TASK (object);
159   GstTaskPrivate *priv = task->priv;
160
161   GST_DEBUG ("task %p finalize", task);
162
163   if (priv->thr_notify)
164     priv->thr_notify (priv->thr_user_data);
165   priv->thr_notify = NULL;
166   priv->thr_user_data = NULL;
167
168   gst_object_unref (priv->pool);
169
170   /* task thread cannot be running here since it holds a ref
171    * to the task so that the finalize could not have happened */
172   g_cond_free (task->cond);
173   task->cond = NULL;
174
175   G_OBJECT_CLASS (gst_task_parent_class)->finalize (object);
176 }
177
178 static void
179 gst_task_func (GstTask * task)
180 {
181   GStaticRecMutex *lock;
182   GThread *tself;
183   GstTaskPrivate *priv;
184
185   priv = task->priv;
186
187   tself = g_thread_self ();
188
189   GST_DEBUG ("Entering task %p, thread %p", task, tself);
190
191   /* we have to grab the lock to get the mutex. We also
192    * mark our state running so that nobody can mess with
193    * the mutex. */
194   GST_OBJECT_LOCK (task);
195   if (task->state == GST_TASK_STOPPED)
196     goto exit;
197   lock = GST_TASK_GET_LOCK (task);
198   if (G_UNLIKELY (lock == NULL))
199     goto no_lock;
200   task->abidata.ABI.thread = tself;
201   /* only update the priority when it was changed */
202   if (priv->prio_set)
203     g_thread_set_priority (tself, priv->priority);
204   GST_OBJECT_UNLOCK (task);
205
206   /* fire the enter_thread callback when we need to */
207   if (priv->thr_callbacks.enter_thread)
208     priv->thr_callbacks.enter_thread (task, tself, priv->thr_user_data);
209
210   /* locking order is TASK_LOCK, LOCK */
211   g_static_rec_mutex_lock (lock);
212   GST_OBJECT_LOCK (task);
213   while (G_LIKELY (task->state != GST_TASK_STOPPED)) {
214     while (G_UNLIKELY (task->state == GST_TASK_PAUSED)) {
215       gint t;
216
217       t = g_static_rec_mutex_unlock_full (lock);
218       if (t <= 0) {
219         g_warning ("wrong STREAM_LOCK count %d", t);
220       }
221       GST_TASK_SIGNAL (task);
222       GST_TASK_WAIT (task);
223       GST_OBJECT_UNLOCK (task);
224       /* locking order.. */
225       if (t > 0)
226         g_static_rec_mutex_lock_full (lock, t);
227
228       GST_OBJECT_LOCK (task);
229       if (G_UNLIKELY (task->state == GST_TASK_STOPPED))
230         goto done;
231     }
232     GST_OBJECT_UNLOCK (task);
233
234     task->func (task->data);
235
236     GST_OBJECT_LOCK (task);
237   }
238 done:
239   GST_OBJECT_UNLOCK (task);
240   g_static_rec_mutex_unlock (lock);
241
242   GST_OBJECT_LOCK (task);
243   task->abidata.ABI.thread = NULL;
244
245 exit:
246   if (priv->thr_callbacks.leave_thread) {
247     /* fire the leave_thread callback when we need to. We need to do this before
248      * we signal the task and with the task lock released. */
249     GST_OBJECT_UNLOCK (task);
250     priv->thr_callbacks.leave_thread (task, tself, priv->thr_user_data);
251     GST_OBJECT_LOCK (task);
252   } else {
253     /* restore normal priority when releasing back into the pool, we will not
254      * touch the priority when a custom callback has been installed. */
255     g_thread_set_priority (tself, G_THREAD_PRIORITY_NORMAL);
256   }
257   /* now we allow messing with the lock again by setting the running flag to
258    * FALSE. Together with the SIGNAL this is the sign for the _join() to 
259    * complete. 
260    * Note that we still have not dropped the final ref on the task. We could
261    * check here if there is a pending join() going on and drop the last ref
262    * before releasing the lock as we can be sure that a ref is held by the
263    * caller of the join(). */
264   task->running = FALSE;
265   GST_TASK_SIGNAL (task);
266   GST_OBJECT_UNLOCK (task);
267
268   GST_DEBUG ("Exit task %p, thread %p", task, g_thread_self ());
269
270   gst_object_unref (task);
271   return;
272
273 no_lock:
274   {
275     g_warning ("starting task without a lock");
276     goto exit;
277   }
278 }
279
280 /**
281  * gst_task_cleanup_all:
282  *
283  * Wait for all tasks to be stopped. This is mainly used internally
284  * to ensure proper cleanup of internal data structures in test suites.
285  *
286  * MT safe.
287  */
288 void
289 gst_task_cleanup_all (void)
290 {
291   GstTaskClass *klass;
292
293   if ((klass = g_type_class_peek (GST_TYPE_TASK))) {
294     init_klass_pool (klass);
295   }
296 }
297
298 /**
299  * gst_task_create:
300  * @func: The #GstTaskFunction to use
301  * @data: User data to pass to @func
302  *
303  * Create a new Task that will repeatedly call the provided @func
304  * with @data as a parameter. Typically the task will run in
305  * a new thread.
306  *
307  * The function cannot be changed after the task has been created. You
308  * must create a new #GstTask to change the function.
309  *
310  * This function will not yet create and start a thread. Use gst_task_start() or
311  * gst_task_pause() to create and start the GThread.
312  *
313  * Before the task can be used, a #GStaticRecMutex must be configured using the
314  * gst_task_set_lock() function. This lock will always be acquired while
315  * @func is called.
316  *
317  * Returns: A new #GstTask.
318  *
319  * MT safe.
320  */
321 GstTask *
322 gst_task_create (GstTaskFunction func, gpointer data)
323 {
324   GstTask *task;
325
326   task = g_object_new (GST_TYPE_TASK, NULL);
327   task->func = func;
328   task->data = data;
329
330   GST_DEBUG ("Created task %p", task);
331
332   return task;
333 }
334
335 /**
336  * gst_task_set_lock:
337  * @task: The #GstTask to use
338  * @mutex: The #GMutex to use
339  *
340  * Set the mutex used by the task. The mutex will be acquired before
341  * calling the #GstTaskFunction.
342  *
343  * This function has to be called before calling gst_task_pause() or
344  * gst_task_start().
345  *
346  * MT safe.
347  */
348 void
349 gst_task_set_lock (GstTask * task, GStaticRecMutex * mutex)
350 {
351   GST_OBJECT_LOCK (task);
352   if (G_UNLIKELY (task->running))
353     goto is_running;
354   GST_TASK_GET_LOCK (task) = mutex;
355   GST_OBJECT_UNLOCK (task);
356
357   return;
358
359   /* ERRORS */
360 is_running:
361   {
362     GST_OBJECT_UNLOCK (task);
363     g_warning ("cannot call set_lock on a running task");
364   }
365 }
366
367 /**
368  * gst_task_set_priority:
369  * @task: a #GstTask
370  * @priority: a new priority for @task
371  *
372  * Changes the priority of @task to @priority.
373  *
374  * Note: try not to depend on task priorities.
375  *
376  * MT safe.
377  *
378  * Since: 0.10.24
379  */
380 void
381 gst_task_set_priority (GstTask * task, GThreadPriority priority)
382 {
383   GstTaskPrivate *priv;
384   GThread *thread;
385
386   g_return_if_fail (GST_IS_TASK (task));
387
388   priv = task->priv;
389
390   GST_OBJECT_LOCK (task);
391   priv->prio_set = TRUE;
392   priv->priority = priority;
393   thread = task->abidata.ABI.thread;
394   if (thread != NULL) {
395     /* if this task already has a thread, we can configure the priority right
396      * away, else we do that when we assign a thread to the task. */
397     g_thread_set_priority (thread, priority);
398   }
399   GST_OBJECT_UNLOCK (task);
400 }
401
402 /**
403  * gst_task_get_pool:
404  * @task: a #GstTask
405  *
406  * Get the #GstTaskPool that this task will use for its streaming
407  * threads.
408  *
409  * MT safe.
410  *
411  * Returns: the #GstTaskPool used by @task. gst_object_unref()
412  * after usage.
413  *
414  * Since: 0.10.24
415  */
416 GstTaskPool *
417 gst_task_get_pool (GstTask * task)
418 {
419   GstTaskPool *result;
420   GstTaskPrivate *priv;
421
422   g_return_val_if_fail (GST_IS_TASK (task), NULL);
423
424   priv = task->priv;
425
426   GST_OBJECT_LOCK (task);
427   result = gst_object_ref (priv->pool);
428   GST_OBJECT_UNLOCK (task);
429
430   return result;
431 }
432
433 /**
434  * gst_task_set_pool:
435  * @task: a #GstTask
436  * @pool: a #GstTaskPool
437  *
438  * Set @pool as the new GstTaskPool for @task. Any new streaming threads that
439  * will be created by @task will now use @pool.
440  *
441  * MT safe.
442  *
443  * Since: 0.10.24
444  */
445 void
446 gst_task_set_pool (GstTask * task, GstTaskPool * pool)
447 {
448   GstTaskPool *old;
449   GstTaskPrivate *priv;
450
451   g_return_if_fail (GST_IS_TASK (task));
452   g_return_if_fail (GST_IS_TASK_POOL (pool));
453
454   priv = task->priv;
455
456   GST_OBJECT_LOCK (task);
457   if (priv->pool != pool) {
458     old = priv->pool;
459     priv->pool = gst_object_ref (pool);
460   } else
461     old = NULL;
462   GST_OBJECT_UNLOCK (task);
463
464   if (old)
465     gst_object_unref (old);
466 }
467
468
469 /**
470  * gst_task_set_thread_callbacks:
471  * @task: The #GstTask to use
472  * @callbacks: a #GstTaskThreadCallbacks pointer
473  * @user_data: user data passed to the callbacks
474  * @notify: called when @user_data is no longer referenced
475  *
476  * Set callbacks which will be executed when a new thread is needed, the thread
477  * function is entered and left and when the thread is joined.
478  *
479  * By default a thread for @task will be created from a default thread pool.
480  *
481  * Objects can use custom GThreads or can perform additional configuration of
482  * the threads (such as changing the thread priority) by installing callbacks.
483  *
484  * MT safe.
485  *
486  * Since: 0.10.24
487  */
488 void
489 gst_task_set_thread_callbacks (GstTask * task,
490     GstTaskThreadCallbacks * callbacks, gpointer user_data,
491     GDestroyNotify notify)
492 {
493   GDestroyNotify old_notify;
494
495   g_return_if_fail (task != NULL);
496   g_return_if_fail (GST_IS_TASK (task));
497   g_return_if_fail (callbacks != NULL);
498
499   GST_OBJECT_LOCK (task);
500   old_notify = task->priv->thr_notify;
501
502   if (old_notify) {
503     gpointer old_data;
504
505     old_data = task->priv->thr_user_data;
506
507     task->priv->thr_user_data = NULL;
508     task->priv->thr_notify = NULL;
509     GST_OBJECT_UNLOCK (task);
510
511     old_notify (old_data);
512
513     GST_OBJECT_LOCK (task);
514   }
515   task->priv->thr_callbacks = *callbacks;
516   task->priv->thr_user_data = user_data;
517   task->priv->thr_notify = notify;
518   GST_OBJECT_UNLOCK (task);
519 }
520
521 /**
522  * gst_task_get_state:
523  * @task: The #GstTask to query
524  *
525  * Get the current state of the task.
526  *
527  * Returns: The #GstTaskState of the task
528  *
529  * MT safe.
530  */
531 GstTaskState
532 gst_task_get_state (GstTask * task)
533 {
534   GstTaskState result;
535
536   g_return_val_if_fail (GST_IS_TASK (task), GST_TASK_STOPPED);
537
538   GST_OBJECT_LOCK (task);
539   result = task->state;
540   GST_OBJECT_UNLOCK (task);
541
542   return result;
543 }
544
545 /* make sure the task is running and start a thread if it's not.
546  * This function must be called with the task LOCK. */
547 static gboolean
548 start_task (GstTask * task)
549 {
550   gboolean res = TRUE;
551   GstTaskClass *tclass;
552   GError *error = NULL;
553   GstTaskPrivate *priv;
554
555   priv = task->priv;
556
557   /* new task, We ref before so that it remains alive while
558    * the thread is running. */
559   gst_object_ref (task);
560   /* mark task as running so that a join will wait until we schedule
561    * and exit the task function. */
562   task->running = TRUE;
563
564   tclass = GST_TASK_GET_CLASS (task);
565
566   /* push on the thread pool, we remember the original pool because the user
567    * could change it later on and then we join to the wrong pool. */
568   priv->pool_id = gst_object_ref (priv->pool);
569   priv->id =
570       gst_task_pool_push (priv->pool_id, (GstTaskPoolFunction) gst_task_func,
571       task, &error);
572
573   if (error != NULL) {
574     g_warning ("failed to create thread: %s", error->message);
575     g_error_free (error);
576     res = FALSE;
577   }
578   return res;
579 }
580
581
582 /**
583  * gst_task_set_state:
584  * @task: a #GstTask
585  * @state: the new task state
586  *
587  * Sets the state of @task to @state.
588  *
589  * The @task must have a lock associated with it using
590  * gst_task_set_lock() when going to GST_TASK_STARTED or GST_TASK_PAUSED or
591  * this function will return %FALSE.
592  *
593  * MT safe.
594  *
595  * Returns: %TRUE if the state could be changed.
596  *
597  * Since: 0.10.24
598  */
599 gboolean
600 gst_task_set_state (GstTask * task, GstTaskState state)
601 {
602   GstTaskState old;
603   gboolean res = TRUE;
604
605   g_return_val_if_fail (GST_IS_TASK (task), FALSE);
606
607   GST_DEBUG_OBJECT (task, "Changing task %p to state %d", task, state);
608
609   GST_OBJECT_LOCK (task);
610   if (state != GST_TASK_STOPPED)
611     if (G_UNLIKELY (GST_TASK_GET_LOCK (task) == NULL))
612       goto no_lock;
613
614   /* if the state changed, do our thing */
615   old = task->state;
616   if (old != state) {
617     task->state = state;
618     switch (old) {
619       case GST_TASK_STOPPED:
620         /* If the task already has a thread scheduled we don't have to do
621          * anything. */
622         if (G_UNLIKELY (!task->running))
623           res = start_task (task);
624         break;
625       case GST_TASK_PAUSED:
626         /* when we are paused, signal to go to the new state */
627         GST_TASK_SIGNAL (task);
628         break;
629       case GST_TASK_STARTED:
630         /* if we were started, we'll go to the new state after the next
631          * iteration. */
632         break;
633     }
634   }
635   GST_OBJECT_UNLOCK (task);
636
637   return res;
638
639   /* ERRORS */
640 no_lock:
641   {
642     GST_WARNING_OBJECT (task, "state %d set on task without a lock", state);
643     GST_OBJECT_UNLOCK (task);
644     g_warning ("task without a lock can't be set to state %d", state);
645     return FALSE;
646   }
647 }
648
649 /**
650  * gst_task_start:
651  * @task: The #GstTask to start
652  *
653  * Starts @task. The @task must have a lock associated with it using
654  * gst_task_set_lock() or this function will return %FALSE.
655  *
656  * Returns: %TRUE if the task could be started.
657  *
658  * MT safe.
659  */
660 gboolean
661 gst_task_start (GstTask * task)
662 {
663   return gst_task_set_state (task, GST_TASK_STARTED);
664 }
665
666 /**
667  * gst_task_stop:
668  * @task: The #GstTask to stop
669  *
670  * Stops @task. This method merely schedules the task to stop and
671  * will not wait for the task to have completely stopped. Use
672  * gst_task_join() to stop and wait for completion.
673  *
674  * Returns: %TRUE if the task could be stopped.
675  *
676  * MT safe.
677  */
678 gboolean
679 gst_task_stop (GstTask * task)
680 {
681   return gst_task_set_state (task, GST_TASK_STOPPED);
682 }
683
684 /**
685  * gst_task_pause:
686  * @task: The #GstTask to pause
687  *
688  * Pauses @task. This method can also be called on a task in the
689  * stopped state, in which case a thread will be started and will remain
690  * in the paused state. This function does not wait for the task to complete
691  * the paused state.
692  *
693  * Returns: %TRUE if the task could be paused.
694  *
695  * MT safe.
696  */
697 gboolean
698 gst_task_pause (GstTask * task)
699 {
700   return gst_task_set_state (task, GST_TASK_PAUSED);
701 }
702
703 /**
704  * gst_task_join:
705  * @task: The #GstTask to join
706  *
707  * Joins @task. After this call, it is safe to unref the task
708  * and clean up the lock set with gst_task_set_lock().
709  *
710  * The task will automatically be stopped with this call.
711  *
712  * This function cannot be called from within a task function as this
713  * would cause a deadlock. The function will detect this and print a 
714  * g_warning.
715  *
716  * Returns: %TRUE if the task could be joined.
717  *
718  * MT safe.
719  */
720 gboolean
721 gst_task_join (GstTask * task)
722 {
723   GThread *tself;
724   GstTaskPrivate *priv;
725   gpointer id;
726   GstTaskPool *pool = NULL;
727
728   priv = task->priv;
729
730   g_return_val_if_fail (GST_IS_TASK (task), FALSE);
731
732   tself = g_thread_self ();
733
734   GST_DEBUG_OBJECT (task, "Joining task %p, thread %p", task, tself);
735
736   /* we don't use a real thread join here because we are using
737    * thread pools */
738   GST_OBJECT_LOCK (task);
739   if (G_UNLIKELY (tself == task->abidata.ABI.thread))
740     goto joining_self;
741   task->state = GST_TASK_STOPPED;
742   /* signal the state change for when it was blocked in PAUSED. */
743   GST_TASK_SIGNAL (task);
744   /* we set the running flag when pushing the task on the thread pool.
745    * This means that the task function might not be called when we try
746    * to join it here. */
747   while (G_LIKELY (task->running))
748     GST_TASK_WAIT (task);
749   /* clean the thread */
750   task->abidata.ABI.thread = NULL;
751   /* get the id and pool to join */
752   if ((id = priv->id)) {
753     if ((pool = priv->pool_id))
754       gst_object_ref (pool);
755     priv->pool_id = NULL;
756     priv->id = NULL;
757   }
758   GST_OBJECT_UNLOCK (task);
759
760   if (pool) {
761     gst_task_pool_join (pool, id);
762     gst_object_unref (pool);
763   }
764
765   GST_DEBUG_OBJECT (task, "Joined task %p", task);
766
767   return TRUE;
768
769   /* ERRORS */
770 joining_self:
771   {
772     GST_WARNING_OBJECT (task, "trying to join task from its thread");
773     GST_OBJECT_UNLOCK (task);
774     g_warning ("\nTrying to join task %p from its thread would deadlock.\n"
775         "You cannot change the state of an element from its streaming\n"
776         "thread. Use g_idle_add() or post a GstMessage on the bus to\n"
777         "schedule the state change from the main thread.\n", task);
778     return FALSE;
779   }
780 }