Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

121 строка
4.8 KiB

  1. /* GLIB - Library of useful routines for C programming
  2. * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. /*
  20. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  21. * file for a list of people on the GLib Team. See the ChangeLog
  22. * files for a list of changes. These files are distributed with
  23. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  24. */
  25. #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. #ifndef __G_ASYNCQUEUE_H__
  29. #define __G_ASYNCQUEUE_H__
  30. #include <glib/gthread.h>
  31. G_BEGIN_DECLS
  32. typedef struct _GAsyncQueue GAsyncQueue;
  33. /* Asyncronous Queues, can be used to communicate between threads */
  34. /* Get a new GAsyncQueue with the ref_count 1 */
  35. GAsyncQueue* g_async_queue_new (void);
  36. GAsyncQueue* g_async_queue_new_full (GDestroyNotify item_free_func);
  37. /* Lock and unlock a GAsyncQueue. All functions lock the queue for
  38. * themselves, but in certain cirumstances you want to hold the lock longer,
  39. * thus you lock the queue, call the *_unlocked functions and unlock it again.
  40. */
  41. void g_async_queue_lock (GAsyncQueue *queue);
  42. void g_async_queue_unlock (GAsyncQueue *queue);
  43. /* Ref and unref the GAsyncQueue. */
  44. GAsyncQueue* g_async_queue_ref (GAsyncQueue *queue);
  45. void g_async_queue_unref (GAsyncQueue *queue);
  46. #ifndef G_DISABLE_DEPRECATED
  47. /* You don't have to hold the lock for calling *_ref and *_unref anymore. */
  48. void g_async_queue_ref_unlocked (GAsyncQueue *queue);
  49. void g_async_queue_unref_and_unlock (GAsyncQueue *queue);
  50. #endif /* !G_DISABLE_DEPRECATED */
  51. /* Push data into the async queue. Must not be NULL. */
  52. void g_async_queue_push (GAsyncQueue *queue,
  53. gpointer data);
  54. void g_async_queue_push_unlocked (GAsyncQueue *queue,
  55. gpointer data);
  56. void g_async_queue_push_sorted (GAsyncQueue *queue,
  57. gpointer data,
  58. GCompareDataFunc func,
  59. gpointer user_data);
  60. void g_async_queue_push_sorted_unlocked (GAsyncQueue *queue,
  61. gpointer data,
  62. GCompareDataFunc func,
  63. gpointer user_data);
  64. /* Pop data from the async queue. When no data is there, the thread is blocked
  65. * until data arrives.
  66. */
  67. gpointer g_async_queue_pop (GAsyncQueue *queue);
  68. gpointer g_async_queue_pop_unlocked (GAsyncQueue *queue);
  69. /* Try to pop data. NULL is returned in case of empty queue. */
  70. gpointer g_async_queue_try_pop (GAsyncQueue *queue);
  71. gpointer g_async_queue_try_pop_unlocked (GAsyncQueue *queue);
  72. /* Wait for data until at maximum until end_time is reached. NULL is returned
  73. * in case of empty queue.
  74. */
  75. gpointer g_async_queue_timed_pop (GAsyncQueue *queue,
  76. GTimeVal *end_time);
  77. gpointer g_async_queue_timed_pop_unlocked (GAsyncQueue *queue,
  78. GTimeVal *end_time);
  79. /* Return the length of the queue. Negative values mean that threads
  80. * are waiting, positve values mean that there are entries in the
  81. * queue. Actually this function returns the length of the queue minus
  82. * the number of waiting threads, g_async_queue_length == 0 could also
  83. * mean 'n' entries in the queue and 'n' thread waiting. Such can
  84. * happen due to locking of the queue or due to scheduling.
  85. */
  86. gint g_async_queue_length (GAsyncQueue *queue);
  87. gint g_async_queue_length_unlocked (GAsyncQueue *queue);
  88. void g_async_queue_sort (GAsyncQueue *queue,
  89. GCompareDataFunc func,
  90. gpointer user_data);
  91. void g_async_queue_sort_unlocked (GAsyncQueue *queue,
  92. GCompareDataFunc func,
  93. gpointer user_data);
  94. /* Private API */
  95. GMutex* _g_async_queue_get_mutex (GAsyncQueue *queue);
  96. G_END_DECLS
  97. #endif /* __G_ASYNCQUEUE_H__ */