gasyncqueue.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. {$ifndef __G_ASYNCQUEUE_H__}
  2. {$define __G_ASYNCQUEUE_H__}
  3. // {$include gthread.inc}
  4. {* Asyncronous Queues, can be used to communicate between threads
  5. *}
  6. type
  7. PGAsyncQueue = pointer;
  8. {* Get a new GAsyncQueue with the ref_count 1 *}
  9. function g_async_queue_new:PGAsyncQueue;cdecl;external gliblib name 'g_async_queue_new';
  10. {* Lock and unlock an GAsyncQueue, all functions lock the queue for
  11. * themselves, but in certain cirumstances you want to hold the lock longer,
  12. * thus you lock the queue, call the *_unlocked functions and unlock it again
  13. *}
  14. procedure g_async_queue_lock(queue:PGAsyncQueue);cdecl;external gliblib name 'g_async_queue_lock';
  15. procedure g_async_queue_unlock(queue:PGAsyncQueue);cdecl;external gliblib name 'g_async_queue_unlock';
  16. {* Ref and unref the GAsyncQueue. g_async_queue_unref_unlocked makes
  17. * no sense, as after the unreffing the Queue might be gone and can't
  18. * be unlocked. So you have a function to call, if you don't hold the
  19. * lock (g_async_queue_unref) and one to call, when you already hold
  20. * the lock (g_async_queue_unref_and_unlock). After that however, you
  21. * don't hold the lock anymore and the Queue might in fact be
  22. * destroyed, if you unrefed to zero *}
  23. procedure g_async_queue_ref(queue:PGAsyncQueue);cdecl;external gliblib name 'g_async_queue_ref';
  24. procedure g_async_queue_ref_unlocked(queue:PGAsyncQueue);cdecl;external gliblib name 'g_async_queue_ref_unlocked';
  25. procedure g_async_queue_unref(queue:PGAsyncQueue);cdecl;external gliblib name 'g_async_queue_unref';
  26. procedure g_async_queue_unref_and_unlock(queue:PGAsyncQueue);cdecl;external gliblib name 'g_async_queue_unref_and_unlock';
  27. {* Push data into the async queue. Must not be NULL *}
  28. procedure g_async_queue_push(queue:PGAsyncQueue; data:gpointer);cdecl;external gliblib name 'g_async_queue_push';
  29. procedure g_async_queue_push_unlocked(queue:PGAsyncQueue; data:gpointer);cdecl;external gliblib name 'g_async_queue_push_unlocked';
  30. {* Pop data from the async queue, when no data is there, the thread is blocked
  31. * until data arrives *}
  32. function g_async_queue_pop(queue:PGAsyncQueue):gpointer;cdecl;external gliblib name 'g_async_queue_pop';
  33. function g_async_queue_pop_unlocked(queue:PGAsyncQueue):gpointer;cdecl;external gliblib name 'g_async_queue_pop_unlocked';
  34. {* Try to pop data, NULL is returned in case of empty queue *}
  35. function g_async_queue_try_pop(queue:PGAsyncQueue):gpointer;cdecl;external gliblib name 'g_async_queue_try_pop';
  36. function g_async_queue_try_pop_unlocked(queue:PGAsyncQueue):gpointer;cdecl;external gliblib name 'g_async_queue_try_pop_unlocked';
  37. {* Wait for data until at maximum until end_time is reached, NULL is returned
  38. * in case of empty queue*}
  39. function g_async_queue_timed_pop(queue:PGAsyncQueue; end_time:PGTimeVal):gpointer;cdecl;external gliblib name 'g_async_queue_timed_pop';
  40. function g_async_queue_timed_pop_unlocked(queue:PGAsyncQueue; end_time:PGTimeVal):gpointer;cdecl;external gliblib name 'g_async_queue_timed_pop_unlocked';
  41. {* Return the length of the queue, negative values mean, that threads
  42. * are waiting, positve values mean, that there are entries in the
  43. * queue. Actually this function returns the length of the queue minus
  44. * the number of waiting threads, g_async_queue_length == 0 could also
  45. * mean 'n' entries in the queue and 'n' thread waiting, such can
  46. * happen due to locking of the queue or due to scheduling. *}
  47. function g_async_queue_length(queue:PGAsyncQueue):gint;cdecl;external gliblib name 'g_async_queue_length';
  48. function g_async_queue_length_unlocked(queue:PGAsyncQueue):gint;cdecl;external gliblib name 'g_async_queue_length_unlocked';
  49. {$endif}