source: trunk/third/evolution/e-util/e-msgport.h @ 18142

Revision 18142, 2.8 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18141, which included commits to RCS files with non-trunk default branches.
Line 
1
2#ifndef _E_MSGPORT_H
3#define _E_MSGPORT_H
4
5/* double-linked list yeah another one, deal */
6typedef struct _EDListNode {
7        struct _EDListNode *next;
8        struct _EDListNode *prev;
9} EDListNode;
10
11typedef struct _EDList {
12        struct _EDListNode *head;
13        struct _EDListNode *tail;
14        struct _EDListNode *tailpred;
15} EDList;
16
17#define E_DLIST_INITIALISER(l) { (EDListNode *)&l.tail, 0, (EDListNode *)&l.head }
18
19void e_dlist_init(EDList *v);
20EDListNode *e_dlist_addhead(EDList *l, EDListNode *n);
21EDListNode *e_dlist_addtail(EDList *l, EDListNode *n);
22EDListNode *e_dlist_remove(EDListNode *n);
23EDListNode *e_dlist_remhead(EDList *l);
24EDListNode *e_dlist_remtail(EDList *l);
25int e_dlist_empty(EDList *l);
26int e_dlist_length(EDList *l);
27
28/* message ports - a simple inter-thread 'ipc' primitive */
29/* opaque handle */
30typedef struct _EMsgPort EMsgPort;
31
32/* header for any message */
33typedef struct _EMsg {
34        EDListNode ln;
35        EMsgPort *reply_port;
36} EMsg;
37
38EMsgPort *e_msgport_new(void);
39void e_msgport_destroy(EMsgPort *mp);
40/* get a fd that can be used to wait on the port asynchronously */
41int e_msgport_fd(EMsgPort *mp);
42void e_msgport_put(EMsgPort *mp, EMsg *msg);
43EMsg *e_msgport_wait(EMsgPort *mp);
44EMsg *e_msgport_get(EMsgPort *mp);
45void e_msgport_reply(EMsg *msg);
46#ifdef HAVE_NSS
47struct PRFileDesc *e_msgport_prfd(EMsgPort *mp);
48#endif
49
50/* e threads, a server thread with a message based request-response, and flexible queuing */
51typedef struct _EThread EThread;
52
53typedef enum {
54        E_THREAD_QUEUE = 0,     /* run one by one, until done, if the queue_limit is reached, discard new request */
55        E_THREAD_DROP,          /* run one by one, until done, if the queue_limit is reached, discard oldest requests */
56        E_THREAD_NEW,           /* always run in a new thread, if the queue limit is reached, new requests are
57                                   stored in the queue until a thread becomes available for it, creating a thread pool */
58} e_thread_t;
59
60typedef void (*EThreadFunc)(EThread *, EMsg *, void *data);
61
62EThread *e_thread_new(e_thread_t type);
63void e_thread_destroy(EThread *e);
64void e_thread_set_queue_limit(EThread *e, int limit);
65void e_thread_set_msg_lost(EThread *e, EThreadFunc destroy, void *data);
66void e_thread_set_msg_destroy(EThread *e, EThreadFunc destroy, void *data);
67void e_thread_set_reply_port(EThread *e, EMsgPort *reply_port);
68void e_thread_set_msg_received(EThread *e, EThreadFunc received, void *data);
69void e_thread_put(EThread *e, EMsg *msg);
70int e_thread_busy(EThread *e);
71
72/* sigh, another mutex interface, this one allows different mutex types, portably */
73typedef struct _EMutex EMutex;
74
75typedef enum _e_mutex_t {
76        E_MUTEX_SIMPLE,         /* == pthread_mutex */
77        E_MUTEX_REC,            /* recursive mutex */
78} e_mutex_t;
79
80EMutex *e_mutex_new(e_mutex_t type);
81int e_mutex_destroy(EMutex *m);
82int e_mutex_lock(EMutex *m);
83int e_mutex_unlock(EMutex *m);
84void e_mutex_assert_locked(EMutex *m);
85
86#endif
Note: See TracBrowser for help on using the repository browser.