public
Description: Message passing, Work-Stealing, Lock-Free, Dynamic Scheduling, and other buzzwords for GLib
Homepage:
Clone URL: git://github.com/chergert/iris.git
iris / iris / iris-coordination-arbiter.c
100644 646 lines (590 sloc) 19.245 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
/* iris-coordination-arbiter.c
*
* Copyright (C) 2009 Christian Hergert <chris@dronelabs.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
* 02110-1301 USA
*/
 
#include "iris-arbiter.h"
#include "iris-arbiter-private.h"
#include "iris-coordination-arbiter.h"
#include "iris-coordination-arbiter-private.h"
#include "iris-port.h"
#include "iris-receiver.h"
#include "iris-receiver-private.h"
 
#define ATTACH_ARBITER(r,a) \
G_STMT_START { \
if (r && !r->priv->arbiter) \
r->priv->arbiter = g_object_ref (a); \
} G_STMT_END
 
/**
* SECTION:iris-coordination-receiver
* @short_description: #IrisArbiter to manage exclusive vs concurrent messages
*
* The #IrisCoordinationArbiter provides management over how incoming messages
* can be handled. Its primary purpose is to allow messages to be as
* concurrent as possible until an exclusive message is received. When that
* happens, it will bleed off the concurrent messages and then run the
* exclusive messages. After the exclusive messages have processed, the flood
* gates can re-open and throttle back up to full concurrency.
*/
 
G_DEFINE_TYPE (IrisCoordinationArbiter,
               iris_coordination_arbiter,
               IRIS_TYPE_ARBITER);
 
static IrisReceiveDecision
can_receive (IrisArbiter *arbiter,
             IrisReceiver *receiver)
{
IrisCoordinationArbiter *coord;
IrisCoordinationArbiterPrivate *priv;
IrisReceiver *resume = NULL;
IrisReceiveDecision decision = IRIS_RECEIVE_NEVER;
 
g_return_val_if_fail (IRIS_IS_COORDINATION_ARBITER (arbiter), IRIS_RECEIVE_NEVER);
g_return_val_if_fail (IRIS_IS_RECEIVER (receiver), IRIS_RECEIVE_NEVER);
 
coord = IRIS_COORDINATION_ARBITER (arbiter);
priv = coord->priv;
 
g_static_rec_mutex_lock (&priv->mutex);
 
/* Current Receiver: ANY
* Request Receiver: ANY
* Has Active......: ANY
* Pending.........: ANY
* Completed.......: YES
* Receive.........: NEVER
*/
if (priv->flags & IRIS_COORD_COMPLETE) {
decision = IRIS_RECEIVE_NEVER;
goto finish;
}
 
/* Current Receiver: TEARDOWN
* Request Receiver: CONCURRENT or EXCLUSIVE
* Has Active......: ANY
* Pending.........: ANY
* Receive.........: NEVER
*/
if (priv->flags & IRIS_COORD_TEARDOWN) {
if (receiver == priv->concurrent || receiver == priv->exclusive) {
decision = IRIS_RECEIVE_NEVER;
goto finish;
}
}
 
/* Current Receiver: TEARDOWN
* Request Receiver: TEARDOWN
* Has Active......: 0
* Pending.........: NONE
* Completed.......: NO
* Receive.........: NOW
*/
if (priv->flags & IRIS_COORD_TEARDOWN) {
if ((priv->flags & IRIS_COORD_COMPLETE) == 0) {
if (receiver == priv->teardown) {
if (priv->active == 0) {
decision = IRIS_RECEIVE_NOW;
priv->flags &= ~IRIS_COORD_NEEDS_TEARDOWN;
priv->flags |= IRIS_COORD_COMPLETE;
goto finish;
}
}
}
}
 
/* Current Receiver: TEARDOWN
* Request Receiver: TEARDOWN
* Has Active......: YES
* Pending.........: NONE
* Completed.......: NO
* Receive.........: NEVER
*/
if (priv->flags & IRIS_COORD_TEARDOWN) {
if (receiver == priv->teardown) {
if (priv->active > 0) {
if ((priv->flags & IRIS_COORD_COMPLETE) == 0) {
decision = IRIS_RECEIVE_NEVER;
goto finish;
}
}
}
}
 
/* Current Receiver: ANY
* Request Receiver: CONCURRENT or EXCUSIVE
* Has Active......: ANY
* Pending.........: TEARDOWN
* Receive.........: NEVER
*/
if (receiver == priv->concurrent || receiver == priv->exclusive) {
if (priv->flags & IRIS_COORD_NEEDS_TEARDOWN) {
decision = IRIS_RECEIVE_NEVER;
goto finish;
}
}
 
/* Current Receiver: CONCURRENT
* Request Receiver: CONCURRENT
* Has Active......: *
* Pending.........: NONE or CONCURRENT
* Receive.........: NOW
*/
if ((priv->flags & IRIS_COORD_CONCURRENT) != 0) {
if (receiver == priv->concurrent) {
if (((priv->flags & IRIS_COORD_NEEDS_ANY) | IRIS_COORD_NEEDS_CONCURRENT) == IRIS_COORD_NEEDS_CONCURRENT) {
decision = IRIS_RECEIVE_NOW;
priv->flags &= ~IRIS_COORD_NEEDS_CONCURRENT;
resume = priv->concurrent;
goto finish;
}
}
}
 
/* Current Receiver: CONCURRENT
* Request Receiver: CONCURRENT
* Has Active......: *
* Pending.........: ANY
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_CONCURRENT) != 0) {
if (receiver == priv->concurrent) {
if ((priv->flags & IRIS_COORD_NEEDS_ANY) != 0) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_CONCURRENT;
goto finish;
}
}
}
 
/* Current Receiver: CONCURRENT
* Request Receiver: EXCLUSIVE
* Has Active......: YES
* Pending.........: ANY
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_CONCURRENT) != 0) {
if (receiver == priv->exclusive) {
if (priv->active > 0) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_EXCLUSIVE;
goto finish;
}
}
}
 
/* Current Receiver: CONCURRENT
* Request Receiver: EXCLUSIVE
* Has Active......: NO
* Pending.........: NONE or EXCLUSIVE
* Receive.........: NOW
*/
if ((priv->flags & IRIS_COORD_CONCURRENT) != 0) {
if (receiver == priv->exclusive) {
if (priv->active == 0) {
if (((priv->flags & IRIS_COORD_NEEDS_ANY) | IRIS_COORD_NEEDS_EXCLUSIVE) == IRIS_COORD_NEEDS_EXCLUSIVE) {
decision = IRIS_RECEIVE_NOW;
priv->flags &= ~(IRIS_COORD_CONCURRENT | IRIS_COORD_NEEDS_EXCLUSIVE);
priv->flags |= IRIS_COORD_EXCLUSIVE;
goto finish;
}
}
}
}
 
/* Current Receiver: CONCURRENT
* Request Receiver: EXCLUSIVE
* Has Active......: NO
* Pending.........: EXCLUSIVE or TEARDOWN
* Receive.........: NOW
*/
if ((priv->flags & IRIS_COORD_CONCURRENT) != 0) {
if (receiver == priv->exclusive) {
if (priv->active == 0) {
if ((priv->flags & IRIS_COORD_NEEDS_ANY) != IRIS_COORD_NEEDS_CONCURRENT) {
decision = IRIS_RECEIVE_NOW;
priv->flags &= ~(IRIS_COORD_CONCURRENT | IRIS_COORD_NEEDS_EXCLUSIVE);
priv->flags |= IRIS_COORD_EXCLUSIVE;
goto finish;
}
}
}
}
 
/* Current Receiver: CONCURRENT
* Request Receiver: TEARDOWN
* Has Active......: NO
* Pending.........: NONE or TEARDOWN
* Receive.........: NOW
*/
if ((priv->flags & IRIS_COORD_CONCURRENT) != 0) {
if (receiver == priv->teardown) {
if (priv->active == 0) {
if (((priv->flags & IRIS_COORD_NEEDS_ANY) | IRIS_COORD_NEEDS_TEARDOWN) == IRIS_COORD_NEEDS_TEARDOWN) {
decision = IRIS_RECEIVE_NOW;
priv->flags &= ~(IRIS_COORD_CONCURRENT | IRIS_COORD_NEEDS_TEARDOWN);
priv->flags |= IRIS_COORD_TEARDOWN;
goto finish;
}
}
}
}
 
/* Current Receiver: CONCURRENT
* Request Receiver: TEARDOWN
* Has Active......: YES
* Pending.........: ANY
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_CONCURRENT) != 0) {
if (receiver == priv->teardown) {
if (priv->active > 0) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_TEARDOWN;
goto finish;
}
}
}
 
/* Current Receiver: CONCURRENT
* Request Receiver: TEARDOWN
* Has Active......: NO
* Pending.........: ANY
* Receive.........: NOW
*/
if ((priv->flags & IRIS_COORD_CONCURRENT) != 0) {
if (receiver == priv->teardown) {
if (priv->active == 0) {
decision = IRIS_RECEIVE_NOW;
priv->flags &= ~(IRIS_COORD_CONCURRENT | IRIS_COORD_NEEDS_TEARDOWN);
priv->flags |= IRIS_COORD_TEARDOWN;
goto finish;
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: EXCLUSIVE
* Has Active......: YES
* Pending.........: ANY
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->exclusive) {
if (priv->active > 0) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_EXCLUSIVE;
goto finish;
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: EXCLUSIVE
* Has Active......: NO
* Pending.........: ANY
* Receive.........: NOW
* Notes...........: This should help us utilize our exclusive mode
* better so we don't do so many switches when
* already in exclusive mode.
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->exclusive) {
if (priv->active == 0) {
decision = IRIS_RECEIVE_NOW;
priv->flags &= ~IRIS_COORD_NEEDS_EXCLUSIVE;
goto finish;
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: EXCLUSIVE
* Has Active......: NO
* Pending.........: CONCURRENT or TEARDOWN
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->exclusive) {
if (priv->active == 0) {
if ((priv->flags & IRIS_COORD_NEEDS_ANY) & ~IRIS_COORD_NEEDS_EXCLUSIVE) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_EXCLUSIVE;
goto finish;
}
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: EXCLUSIVE
* Has Active......: YES
* Pending.........: ANY
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->exclusive) {
if (priv->active > 0) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_EXCLUSIVE;
goto finish;
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: CONCURRENT
* Has Active......: NO
* Pending.........: NONE or CONCURRENT
* Receive.........: NOW
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->concurrent) {
if (priv->active == 0) {
if (((priv->flags & IRIS_COORD_NEEDS_ANY) | IRIS_COORD_NEEDS_CONCURRENT) == IRIS_COORD_NEEDS_CONCURRENT) {
decision = IRIS_RECEIVE_NOW;
priv->flags &= ~(IRIS_COORD_EXCLUSIVE | IRIS_COORD_NEEDS_CONCURRENT);
priv->flags |= IRIS_COORD_CONCURRENT;
resume = priv->concurrent;
goto finish;
}
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: CONCURRENT
* Has Active......: NO
* Pending.........: EXCLUSIVE or TEARDOWN
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->concurrent) {
if (priv->active == 0) {
if ((priv->flags & IRIS_COORD_NEEDS_ANY) & ~IRIS_COORD_NEEDS_CONCURRENT) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_CONCURRENT;
goto finish;
}
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: CONCURRENT
* Has Active......: YES
* Pending.........: ANY
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->concurrent) {
if (priv->active > 0) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_CONCURRENT;
goto finish;
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: TEARDOWN
* Has Active......: NO
* Pending.........: NONE or TEARDOWN
* Receive.........: NOW
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->teardown) {
if (priv->active == 0) {
if (((priv->flags & IRIS_COORD_NEEDS_ANY) | IRIS_COORD_NEEDS_TEARDOWN) == IRIS_COORD_NEEDS_TEARDOWN) {
decision = IRIS_RECEIVE_NOW;
priv->flags &= ~(IRIS_COORD_EXCLUSIVE | IRIS_COORD_NEEDS_TEARDOWN);
priv->flags |= IRIS_COORD_TEARDOWN;
goto finish;
}
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: TEARDOWN
* Has Active......: YES
* Pending.........: ANY
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->teardown) {
if (priv->active > 0) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_TEARDOWN;
goto finish;
}
}
}
 
/* Current Receiver: EXCLUSIVE
* Request Receiver: TEARDOWN
* Has Active......: NO
* Pending.........: ANY
* Receive.........: LATER
*/
if ((priv->flags & IRIS_COORD_EXCLUSIVE) != 0) {
if (receiver == priv->teardown) {
if (priv->active <= 0) {
decision = IRIS_RECEIVE_LATER;
priv->flags |= IRIS_COORD_NEEDS_TEARDOWN;
goto finish;
}
}
}
 
g_print ("\nMISSING ARBITER BRANCH REPORT\n"
"====================================\n"
"Current.....: %s\n"
"Receiver....: %s\n"
"Active......: %lu\n"
"Pending.....: %u\n",
(priv->flags & IRIS_COORD_EXCLUSIVE) ? "EXCLUSIVE" : (priv->flags & IRIS_COORD_CONCURRENT) ? "CONCURRENT" : "TEARDOWN",
(receiver == priv->exclusive) ? "EXCLUSIVE" : (receiver == priv->concurrent) ? "CONCURRENT" : "TEARDOWN",
priv->active,
priv->flags & IRIS_COORD_NEEDS_ANY);
 
finish:
if (decision == IRIS_RECEIVE_NOW) {
if (receiver == priv->teardown)
priv->flags |= IRIS_COORD_COMPLETE;
g_atomic_int_inc ((gint*)&priv->active);
}
 
/* It would be nice to hold on to this lock while we resume to make
* sure our resuming receiver gets more in, but it can create a
* dead-lock if we are calling resume and try to lock on the receiver
* while someone in the receiver thread is trying to lock on us to
* try to deliver. */
g_static_rec_mutex_unlock (&priv->mutex);
 
if (resume)
iris_receiver_resume (resume);
 
return decision;
}
 
static void
receive_completed (IrisArbiter *arbiter,
                   IrisReceiver *receiver)
{
IrisCoordinationArbiter *coord;
IrisCoordinationArbiterPrivate *priv;
IrisReceiver *resume = NULL;
 
g_return_if_fail (IRIS_IS_COORDINATION_ARBITER (arbiter));
g_return_if_fail (IRIS_IS_RECEIVER (receiver));
 
coord = IRIS_COORDINATION_ARBITER (arbiter);
priv = coord->priv;
 
g_static_rec_mutex_lock (&priv->mutex);
 
if (g_atomic_int_dec_and_test ((gint*)&priv->active)) {
if (priv->flags & IRIS_COORD_COMPLETE) {
}
else if (priv->flags & IRIS_COORD_CONCURRENT) {
if (priv->flags & IRIS_COORD_NEEDS_EXCLUSIVE) {
priv->flags &= ~(IRIS_COORD_CONCURRENT | IRIS_COORD_NEEDS_EXCLUSIVE);
priv->flags |= IRIS_COORD_EXCLUSIVE;
resume = priv->exclusive;
}
else if (priv->flags & IRIS_COORD_NEEDS_TEARDOWN) {
priv->flags &= ~(IRIS_COORD_CONCURRENT | IRIS_COORD_NEEDS_TEARDOWN);
priv->flags |= IRIS_COORD_TEARDOWN;
resume = priv->teardown;
}
else if (!priv->concurrent->priv->active) {
resume = priv->concurrent;
}
}
else if (priv->flags & IRIS_COORD_EXCLUSIVE) {
if (priv->flags & IRIS_COORD_NEEDS_EXCLUSIVE) {
/* Try to save mode switches by running exclusive now
* regardless of what other modes want to run. */
resume = priv->exclusive;
}
else if (priv->flags & IRIS_COORD_NEEDS_CONCURRENT) {
priv->flags &= ~(IRIS_COORD_EXCLUSIVE | IRIS_COORD_NEEDS_CONCURRENT);
priv->flags |= IRIS_COORD_CONCURRENT;
resume = priv->concurrent;
}
else if (priv->flags & IRIS_COORD_NEEDS_TEARDOWN) {
priv->flags &= ~(IRIS_COORD_EXCLUSIVE | IRIS_COORD_NEEDS_TEARDOWN);
priv->flags |= IRIS_COORD_TEARDOWN;
resume = priv->teardown;
}
else if (!priv->exclusive->priv->active) {
resume = priv->exclusive;
}
}
else if (priv->flags & IRIS_COORD_TEARDOWN) {
if ((priv->flags & IRIS_COORD_COMPLETE) == 0) {
priv->flags &= ~IRIS_COORD_NEEDS_TEARDOWN;
resume = priv->teardown;
}
}
else {
g_warn_if_reached ();
}
}
 
g_static_rec_mutex_unlock (&priv->mutex);
 
if (resume)
iris_receiver_resume (resume);
}
 
static void
iris_coordination_arbiter_finalize (GObject *object)
{
G_OBJECT_CLASS (iris_coordination_arbiter_parent_class)->finalize (object);
}
 
static void
iris_coordination_arbiter_class_init (IrisCoordinationArbiterClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
IrisArbiterClass *arbiter_class = IRIS_ARBITER_CLASS (klass);
 
arbiter_class->can_receive = can_receive;
arbiter_class->receive_completed = receive_completed;
object_class->finalize = iris_coordination_arbiter_finalize;
 
g_type_class_add_private (object_class, sizeof (IrisCoordinationArbiterPrivate));
}
 
static void
iris_coordination_arbiter_init (IrisCoordinationArbiter *arbiter)
{
arbiter->priv = G_TYPE_INSTANCE_GET_PRIVATE (arbiter,
IRIS_TYPE_COORDINATION_ARBITER,
IrisCoordinationArbiterPrivate);
g_static_rec_mutex_init (&arbiter->priv->mutex);
arbiter->priv->flags = IRIS_COORD_CONCURRENT;
}
 
static IrisArbiter*
iris_coordination_arbiter_new (IrisReceiver *exclusive,
                               IrisReceiver *concurrent,
                               IrisReceiver *teardown)
{
IrisCoordinationArbiter *arbiter;
 
g_return_val_if_fail (exclusive == NULL || IRIS_IS_RECEIVER (exclusive), NULL);
g_return_val_if_fail (concurrent == NULL || IRIS_IS_RECEIVER (concurrent), NULL);
g_return_val_if_fail (teardown == NULL || IRIS_IS_RECEIVER (teardown), NULL);
 
g_return_val_if_fail (!exclusive || exclusive != concurrent, NULL);
g_return_val_if_fail (!teardown || exclusive != teardown, NULL);
g_return_val_if_fail (!concurrent || concurrent != teardown, NULL);
g_return_val_if_fail (exclusive || concurrent || teardown, NULL);
 
arbiter = g_object_new (IRIS_TYPE_COORDINATION_ARBITER, NULL);
arbiter->priv->exclusive = exclusive ? g_object_ref (exclusive) : NULL;
arbiter->priv->concurrent = concurrent ? g_object_ref (concurrent) : NULL;
arbiter->priv->teardown = teardown ? g_object_ref (teardown) : NULL;
 
ATTACH_ARBITER (exclusive, arbiter);
ATTACH_ARBITER (concurrent, arbiter);
ATTACH_ARBITER (teardown, arbiter);
 
return IRIS_ARBITER (arbiter);
}
 
/**
* iris_arbiter_coordinate:
* @exclusive: An #IrisReceiver
* @concurrent: An #IrisReceiver
* @teardown: An #IrisReceiver
*
* Coordinates messages incoming to the receivers. This is used to guarantee
* semantics for the receivers.
*
* Any message received on the @exclusive receiver is guaranteed to be the
* only message received at a time. No other exclusive, concurrent, or
* teardown messages will be running.
*
* Messages received on the @concurrent receiver can be received concurrently
* meaning more than one message is allowed to be received at a time.
*
* Only one message can be recieved on @teardown ever. After a message has
* been received on @teardown, no further messages will ever be received
* on any receivers.
*
* Return value: An new #IrisArbiter that will arbitrate messages incoming
* to the passed receivers.
*/
IrisArbiter*
iris_arbiter_coordinate (IrisReceiver *exclusive,
                         IrisReceiver *concurrent,
                         IrisReceiver *teardown)
{
return iris_coordination_arbiter_new (exclusive, concurrent, teardown);
}