Control Structures in C

Within the C language, policy decisions will be specified via a dragonPolicy structure as given here.

API Specification

enum dragonAffinity_t

Specifies where to locate resources at creation time.

Values:

enumerator DRAGON_AFFINITY_TO_CREATOR

Locate on the same node as the process requesting the resource

enumerator DRAGON_AFFINITY_ANYWHERE

Let the Dragon runtime automatically decide where to place a resource

enum dragonWaitMode_t

Wait Mode constants.

The mode of operation to use when waiting for an event on a resource. Idle waiting is appropriate for long waiting periods, lower power consumption, and when processor cores are over-subscribed. Spin waiting is appropriate for shorter duration waits and when latency and throughput is more important.

Values:

enumerator DRAGON_IDLE_WAIT

Lower power consumption with a litte more wakeup overhead.

enumerator DRAGON_SPIN_WAIT

Minimal wakeup overhead. More power consumption and contention.

enumerator DRAGON_ADAPTIVE_WAIT

Perhaps the best of both worlds.

struct dragonPolicy_t

Policies to apply to a resource at creation time.

Public Members

dragonAffinity_t placement

Where to place the resource

dragonWaitMode_t wait_type

The type of operation to use when waiting for an event

bool refcount

Apply global reference counting to the resource and cleanup the resource when the count drops to zero

Examples

The programmer can specify a policy by instantiating an instance of this structure in their code and supplying that policy while creating Dragon objects, like queues.

Listing 34 Creating a Queue with a non-default policy using C
 1#include <dragon/global_types.h>
 2#include <dragon/queue.h>
 3
 4void sample() {
 5  dragonPolicy_t policy;
 6  dragonError_t err;
 7  dragonQueueDescr_t queue;
 8
 9  err = dragon_policy_init(&policy);
10
11  policy.wait_type = DRAGON_IDLE_WAIT;
12
13  err = dragon_managed_queue_create("my_unique_queue_name", 100, true, NULL, &policy, &queue);
14
15  /* being a managed queue, multiple processes can "create" this queue instance. The first one will actually
16     create it while all others will automatically be given access to this queue instance. It can also
17     be shared across languages since the same API is available in all languages and interacts with the Dragon
18     run-time in the same way. */
19
20}