Vuo  1.2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Enumerations | Functions | Variables
VuoRuntimeHelper.cc File Reference

Description

VuoRuntimeHelper implementation.

Enumerations

enum  ChangeType
 Possible changes to a node across a live-coding reload. More...
 

Functions

void vuoSetPortContextData (struct PortContext *portContext, void *data)
 Sets the port context's data field.
 
static unsigned long hash (const char *str)
 Returns an integer hash for a C string.
 
static vector< Worker > dequeueWorkers (void)
 Chooses one or more workers, from those waiting for threads, to be the next workers to get threads.
 
void vuoInitWorkerThreadPool (void)
 Sets up the pool of worker threads.
 
void vuoFiniWorkerThreadPool (void)
 Cleans up the pool of worker threads.
 
void vuoScheduleTriggerWorker (dispatch_queue_t queue, void *context, void(*function)(void *), int minThreadsNeeded, int maxThreadsNeeded, unsigned long eventId, char *compositionIdentifier, int chainCount)
 Schedules a trigger worker function to be called when enough threads are available from the thread pool.
 
void vuoScheduleChainWorker (dispatch_queue_t queue, void *context, void(*function)(void *), int minThreadsNeeded, int maxThreadsNeeded, unsigned long eventId, char *compositionIdentifier, unsigned long chainIndex, unsigned long *upstreamChainIndices, int upstreamChainIndicesCount)
 Schedules a chain worker function to be called when enough threads are available from the thread pool.
 
void vuoGrantThreadsToSubcomposition (unsigned long eventId, char *compositionIdentifier, unsigned long chainIndex, char *subcompositionIdentifier)
 Allows the published input trigger of a subcomposition node to use the threads allocated for the chain containing the node.
 
void vuoReturnThreadsForTriggerWorker (unsigned long eventId)
 Returns the threads allocated for the trigger worker to the thread pool.
 
void vuoReturnThreadsForChainWorker (unsigned long eventId, char *compositionIdentifier, unsigned long chainIndex)
 Returns the threads allocated for the chain worker to the thread pool.
 
unsigned long vuoGetNextEventId (void)
 Returns a unique event ID.
 
static void splitCompositionIdentifier (const string &compositionIdentifier, string &parentCompositionIdentifier, string &nodeIdentifier)
 If compositionIdentifier refers to a subcomposition, outputs the identifier of the parent composition and the subcomposition node within the parent composition.
 
static string joinCompositionIdentifier (const string &parentCompositionIdentifier, const string &nodeIdentifier)
 Constructs the composition identifier for a subcomposition.
 
static string joinPortIdentifier (const string &nodeIdentifier, const string &portName)
 Constructs the identifier of a port on a node.
 
void vuoAddNodeMetadata (const char *compositionIdentifier, const char *nodeIdentifier)
 Registers metadata for a node.
 
void vuoAddPortMetadata (const char *compositionIdentifier, const char *portIdentifier, const char *portName, unsigned long typeIndex, const char *initialValue)
 Registers metadata for a port.
 
static string vuoGetNodeIdentifierForIndex (const char *compositionIdentifier, unsigned long nodeIndex)
 Looks up the node identifier for the node with the given index.
 
static unsigned long vuoGetNodeIndexForIdentifier (const string &compositionIdentifier, const string &nodeIdentifier)
 Looks up the node index for the node with the given identifier.
 
static string vuoGetCompositionIdentifierForHash (unsigned long compositionIdentifierHash)
 Looks up the composition identifier that corresponds to the given hash.
 
static void vuoAddNodeContext (const char *compositionIdentifier, unsigned long nodeIndex, struct NodeContext *nodeContext)
 Registers a node context.
 
static void vuoRemoveNodeContext (const char *compositionIdentifier, unsigned long nodeIndex)
 Un-registers a node context.
 
static void vuoRelocateAllNodeContexts (void)
 Preserves all remaining node contexts to be accessed after a live-coding reload, and clears the list of registered node contexts.
 
static NodeContextvuoCarryOverNodeContext (const char *compositionIdentifier, unsigned long nodeIndex)
 Carries over a node context from before a live-coding reload — registering it with the new node contexts and removing it from the list of carried-over node contexts.
 
static void vuoRemoveCarriedOverNodeContext (const char *compositionIdentifier, const string &nodeIdentifier)
 Removes the node from the list of carried-over node contexts.
 
static void vuoRemoveAllCarriedOverNodeContexts (void(*compositionDestroyNodeContext)(const char *, const char *, NodeContext *))
 Removes all remaining items from the list of carried-over node contexts.
 
struct NodeContextvuoGetNodeContext (const char *compositionIdentifier, unsigned long nodeIndex)
 Returns the node context registered for the node index, or null if none is found.
 
struct NodeContextvuoGetCompositionContext (const char *compositionIdentifier)
 Returns the node context registered for the composition (top-level or subcomposition), or null if none is found.
 
void * vuoGetDataForPort (const char *compositionIdentifier, const char *portIdentifier)
 Returns the data field in a port's context, given the port's identifier.
 
dispatch_semaphore_t vuoGetNodeSemaphoreForPort (const char *compositionIdentifier, const char *portIdentifier)
 Returns the semaphore field in a node's context, given the identifier of a port on the node.
 
unsigned long vuoGetNodeIndexForPort (const char *compositionIdentifier, const char *portIdentifier)
 Returns the numerical index for a node, given the identifier of a port on the node.
 
unsigned long vuoGetTypeIndexForPort (const char *compositionIdentifier, const char *portIdentifier)
 Returns the numerical index for a port's type, given the port's identifier.
 
static void vuoAddPortIdentifier (const char *compositionIdentifier, const string &portIdentifier, void *data, dispatch_semaphore_t nodeSemaphore, unsigned long nodeIndex, unsigned long typeIndex)
 Caches information about the port so it can be efficiently retrieved later.
 
static void vuoRemovePortIdentifier (const char *compositionIdentifier, const string &portIdentifier)
 Removes the port from the port cache.
 
static void vuoRelocateAllPortIdentifiers (void)
 Preserves all remaining port cache entries to be accessed after a live-coding reload, and clears the port cache.
 
static void vuoCarryOverPortIdentifier (const char *compositionIdentifier, const string &portIdentifier, unsigned long nodeIndex, unsigned long typeIndex)
 Carries over a port's cache entry from before a live-coding reload — transferring the entry to the new port cache and removing it from the list of carried-over port cache entries.
 
static void vuoCarryOverPortIdentifiersForNode (const char *compositionIdentifier, const string &nodeIdentifier, unsigned long nodeIndex, const vector< string > &portIdentifiers, const vector< unsigned long > typeIndexes)
 Carries over all of the node's port cache entries from before a live-coding reload — transferring the entries to the new port cache and removing them from the list of carried-over port cache entries.
 
static void vuoRemoveCarriedOverPortIdentifier (const char *compositionIdentifier, const string &oldPortIdentifier)
 Removes the port from the list of carried-over port cache entries.
 
static void vuoRemoveAllCarriedOverPortIdentifiers (void)
 Removes all remaining items from the list of carried-over port cache entries.
 
static void vuoCarryOverPortData (const char *compositionIdentifier, const string &oldPortIdentifier, const string &newPortIdentifier, PortContext *newPortContext)
 For a node being replaced across a live-coding reload, transfers port data from a port on the old node to the corresponding port on the new node (by copying the port data's heap address from the old PortContext to the new PortContext).
 
static enum ChangeType findNodeInCompositionDiff (const char *nodeIdentifier, json_object **replacementObj)
 Searches compositionDiff for changes made to the node across a live-coding reload.
 
bool vuoIsNodeBeingRemovedOrReplaced (const char *nodeIdentifier, json_object **replacementObj)
 Returns true if the node is among the removals or replacees across a live-coding reload, or if the composition is being stopped (not a live-coding reload).
 
bool vuoIsNodeBeingAddedOrReplaced (const char *nodeIdentifier, json_object **replacementObj)
 Returns true if the node is among the additions or replacers across a live-coding reload, or if the composition is being started (not a live-coding reload).
 
static bool vuoIsPortBeingReplaced (const char *portName, json_object *replacementObj)
 Returns true if the port is among the replacees across a live-coding reload.
 
static bool vuoIsPortReplacingAnother (const char *portName, json_object *replacementObj, string &oldNodeIdentifier, string &oldPortIdentifier)
 Returns true if the port is among the replacers across a live-coding reload.
 
NodeContextvuoCompositionContextInitHelper (const char *compositionIdentifier, bool hasInstanceData, unsigned long publishedOutputPortCount, NodeContext *(*compositionCreateNodeContext)(const char *, unsigned long), void(*compositionDestroyNodeContext)(const char *, const char *, NodeContext *), void(*compositionSetPortValue)(const char *, const char *, const char *, bool, bool, bool, bool, bool))
 Helper function for compositionContextInit().
 
void vuoCompositionContextFiniHelper (const char *compositionIdentifier, void(*compositionDestroyNodeContext)(const char *, const char *, NodeContext *), void(*compositionReleasePortData)(void *, unsigned long))
 Helper function for compositionContextFini().
 
char * vuoConcatenateStrings2 (const char *s0, const char *s1)
 Returns the strings appended in order.
 
char * vuoConcatenateStrings3 (const char *s0, const char *s1, const char *s2)
 Returns the strings appended in order.
 
char * vuoConcatenateStrings (const char **strings, size_t stringCount)
 Returns the strings appended in order.
 
NodeContextvuoCreateNodeContext (bool hasInstanceData, bool isComposition, size_t outputEventCount)
 Creates a node context, initializing its fields to default values.
 
void vuoFreeNodeContext (NodeContext *nodeContext)
 Frees the port context and its fields.
 
PortContextvuoGetNodeContextPortContext (NodeContext *nodeContext, size_t index)
 Gets the array element at the given index of the node context's portContexts field.
 
dispatch_semaphore_t vuoGetNodeContextSemaphore (struct NodeContext *nodeContext)
 Gets the node context's semaphore field.
 
void vuoRetainPortContextData (struct PortContext *portContext)
 Prevents the port context's data field from being freed by vuoFreePortContext().
 
void * vuoGetPortContextData (struct PortContext *portContext)
 Gets the port context's data field.
 

Variables

bool isPaused = false
 True if node execution is currently paused.
 
dispatch_group_t vuoTriggerWorkersScheduled = NULL
 Keeps track of trigger workers that have been scheduled but have not yet launched an event into the composition.
 
unsigned long vuoLastEventId = 0
 The ID most recently assigned to any event, composition-wide. Used to generate a unique ID for each event.
 
static WorkerQueue workersWaitingForThreads
 Queue of workers waiting to use threads from the pool.
 
ThreadPool mainThreadPool
 Trigger workers claim threads from this thread pool.
 
map< unsigned long, map
< unsigned long, ThreadPool > > 
triggerThreadPools
 Chain workers claim threads from the thread pool for their event ID and hashed composition identifier.
 
static dispatch_queue_t workersWaitingSync
 Synchronizes access to workersWaitingForThreads.
 
static dispatch_queue_t threadPoolSync
 Synchronizes access to mainThreadPool and triggerThreadPools.
 
static dispatch_semaphore_t workersUpdated
 Notifies dequeueWorker() when there may be a new worker available to dequeue.
 
static bool mayMoreWorkersBeEnqueued
 Becomes true when the composition is stopping, indicating that dequeueWorker() is now flushing out the remaining workers and shouldn't expect new events.
 
static bool mayMoreWorkersBeDequeued
 Becomes true when dequeueWorker() has finished flushing out the remaining workers.
 
static map< unsigned long, map
< unsigned long, struct
NodeContext * > > 
nodeContextForIndex
 A registry of all NodeContext values in the running composition, indexed by hashed composition identifier and node index.
 
static map< unsigned long, string > compositionIdentifierForHash
 The composition identifier for each hash registered in nodeContextForIndex.
 
static map< string, map
< string, void * > > 
dataForPort
 The data field in the port's context, indexed by composition and port identifier.
 
static map< string, map
< string, dispatch_semaphore_t > > 
nodeSemaphoreForPort
 The semaphore field in the node's context, indexed by composition and port identifier.
 
static map< string, map
< string, unsigned long > > 
nodeIndexForPort
 The index for a node, indexed by composition and port identifier.
 
static map< string, map
< string, unsigned long > > 
typeIndexForPort
 The index for the port's type, indexed by composition and port identifier.
 
static map< string, map
< string, struct NodeContext * > > 
carriedOverNodeContextForIdentifier
 Info from nodeContextForIndex carried across a live-coding reload, indexed by composition identifier and node identifier.
 
static map< string, map
< string, void * > > 
carriedOverDataForPort
 Info from dataForPort carried across a live-coding reload.
 
static map< string, map
< string, dispatch_semaphore_t > > 
carriedOverNodeSemaphoreForPort
 Info from nodeSemaphoreForPort carried across a live-coding reload.
 
static map< string, map
< string, unsigned long > > 
carriedOverNodeIndexForPort
 Info from nodeIndexForPort carried across a live-coding reload.
 
static map< string, map
< string, unsigned long > > 
carriedOverTypeIndexForPort
 Info from typeIndexForPort carried across a live-coding reload.
 
char * vuoTopLevelCompositionIdentifier
 The composition identifier of the top-level composition.
 
static const unsigned long topLevelCompositionIndex = ULONG_MAX
 The index for the top-level composition's node context in nodeContextForIndex.
 
static const unsigned long invalidCompositionIndex = ULONG_MAX - 1
 Used for error conditions.
 
char * compositionDiff = NULL
 Differences between the old and new composition, when replacing compositions for live coding.
 
static vector< Worker > workersDequeued
 Temporary storage in dequeueWorkers(), made global to avoid the cost of reallocating with every call.
 
static vector
< WorkerQueue::Node * > 
workersDequeuedNodes
 Temporary storage in dequeueWorkers(), made global to avoid the cost of reallocating with every call.
 
static map< string, vector
< NodeMetadata > > 
nodeMetadatas
 The metadata for each node, by composition identifier and node index.
 
static map< string, vector
< NodeMetadata > > 
carriedOverNodeMetadatas
 Node metadata for nodes within subcompositions that are kept across a live-coding reload.
 

Enumeration Type Documentation

enum ChangeType

Possible changes to a node across a live-coding reload.

Function Documentation

static vector<Worker> dequeueWorkers ( void  )
static

Chooses one or more workers, from those waiting for threads, to be the next workers to get threads.

This function goes through the enqueued workers in order from oldest to newest. It chooses a worker if one of the following is true:

  • It's a trigger worker for a new event, there are enough threads available in mainThreadPool, and no trigger worker earlier in the queue has been skipped over because it needs more threads than are available.
  • It's a trigger worker for the published input trigger of a subcomposition node.
  • It's a chain worker, there are enough threads available in triggerThreadPools, and no other chain worker in the queue has a smaller chain index (i.e., comes before this chain in topological order).

If no eligible workers are available, this function blocks until some become available.

static enum ChangeType findNodeInCompositionDiff ( const char *  nodeIdentifier,
json_object **  replacementObj 
)
static

Searches compositionDiff for changes made to the node across a live-coding reload.

This needs to be kept in sync with VuoCompilerComposition::diffAgainstOlderComposition().

static unsigned long hash ( const char *  str)
static

Returns an integer hash for a C string.

static string joinCompositionIdentifier ( const string &  parentCompositionIdentifier,
const string &  nodeIdentifier 
)
static

Constructs the composition identifier for a subcomposition.

static string joinPortIdentifier ( const string &  nodeIdentifier,
const string &  portName 
)
static

Constructs the identifier of a port on a node.

This needs to be kept in sync with VuoCompilerPort::getIdentifier().

static void splitCompositionIdentifier ( const string &  compositionIdentifier,
string &  parentCompositionIdentifier,
string &  nodeIdentifier 
)
static

If compositionIdentifier refers to a subcomposition, outputs the identifier of the parent composition and the subcomposition node within the parent composition.

Otherwise, outputs compositionIdentifier as the parent composition identifier.

This needs to be kept in sync with VuoCompilerNode::generateSubcompositionIdentifierValue().

static void vuoAddNodeContext ( const char *  compositionIdentifier,
unsigned long  nodeIndex,
struct NodeContext nodeContext 
)
static

Registers a node context.

void vuoAddNodeMetadata ( const char *  compositionIdentifier,
const char *  nodeIdentifier 
)

Registers metadata for a node.

When a (sub)composition is added or recompiled, this function should be called for each node in the composition, in the same order as VuoCompilerBitcodeGenerator::orderedNodes.

static void vuoAddPortIdentifier ( const char *  compositionIdentifier,
const string &  portIdentifier,
void *  data,
dispatch_semaphore_t  nodeSemaphore,
unsigned long  nodeIndex,
unsigned long  typeIndex 
)
static

Caches information about the port so it can be efficiently retrieved later.

void vuoAddPortMetadata ( const char *  compositionIdentifier,
const char *  portIdentifier,
const char *  portName,
unsigned long  typeIndex,
const char *  initialValue 
)

Registers metadata for a port.

After vuoAddNodeMetadata() is called for a node, this function should be called for each port on the node, in the same order that ports are added to NodeContext.portContexts.

static NodeContext* vuoCarryOverNodeContext ( const char *  compositionIdentifier,
unsigned long  nodeIndex 
)
static

Carries over a node context from before a live-coding reload — registering it with the new node contexts and removing it from the list of carried-over node contexts.

If the node is a subcomposition, this function also carries over the node contexts of all nodes within the subcomposition.

static void vuoCarryOverPortData ( const char *  compositionIdentifier,
const string &  oldPortIdentifier,
const string &  newPortIdentifier,
PortContext newPortContext 
)
static

For a node being replaced across a live-coding reload, transfers port data from a port on the old node to the corresponding port on the new node (by copying the port data's heap address from the old PortContext to the new PortContext).

static void vuoCarryOverPortIdentifier ( const char *  compositionIdentifier,
const string &  portIdentifier,
unsigned long  nodeIndex,
unsigned long  typeIndex 
)
static

Carries over a port's cache entry from before a live-coding reload — transferring the entry to the new port cache and removing it from the list of carried-over port cache entries.

static void vuoCarryOverPortIdentifiersForNode ( const char *  compositionIdentifier,
const string &  nodeIdentifier,
unsigned long  nodeIndex,
const vector< string > &  portIdentifiers,
const vector< unsigned long >  typeIndexes 
)
static

Carries over all of the node's port cache entries from before a live-coding reload — transferring the entries to the new port cache and removing them from the list of carried-over port cache entries.

If the node is a subcomposition, this function also carries over the port cache entries for all nodes within the subcomposition.

void vuoCompositionContextFiniHelper ( const char *  compositionIdentifier,
void(*)(const char *, const char *, NodeContext *)  compositionDestroyNodeContext,
void(*)(void *, unsigned long)  compositionReleasePortData 
)

Helper function for compositionContextFini().

If the composition contains subcomposition nodes, this function calls each subcomposition's compositionContextFini().

NodeContext* vuoCompositionContextInitHelper ( const char *  compositionIdentifier,
bool  hasInstanceData,
unsigned long  publishedOutputPortCount,
NodeContext *(*)(const char *, unsigned long)  compositionCreateNodeContext,
void(*)(const char *, const char *, NodeContext *)  compositionDestroyNodeContext,
void(*)(const char *, const char *, const char *, bool, bool, bool, bool, bool)  compositionSetPortValue 
)

Helper function for compositionContextInit().

If the composition contains subcomposition nodes, this function calls each subcomposition's compositionContextInit().

char* vuoConcatenateStrings ( const char **  strings,
size_t  stringCount 
)

Returns the strings appended in order.

char* vuoConcatenateStrings2 ( const char *  s0,
const char *  s1 
)

Returns the strings appended in order.

char* vuoConcatenateStrings3 ( const char *  s0,
const char *  s1,
const char *  s2 
)

Returns the strings appended in order.

NodeContext* vuoCreateNodeContext ( bool  hasInstanceData,
bool  isComposition,
size_t  outputEventCount 
)
read

Creates a node context, initializing its fields to default values.

void vuoFiniWorkerThreadPool ( void  )

Cleans up the pool of worker threads.

void vuoFreeNodeContext ( NodeContext nodeContext)

Frees the port context and its fields.

struct NodeContext* vuoGetCompositionContext ( const char *  compositionIdentifier)
read

Returns the node context registered for the composition (top-level or subcomposition), or null if none is found.

static string vuoGetCompositionIdentifierForHash ( unsigned long  compositionIdentifierHash)
static

Looks up the composition identifier that corresponds to the given hash.

void* vuoGetDataForPort ( const char *  compositionIdentifier,
const char *  portIdentifier 
)

Returns the data field in a port's context, given the port's identifier.

unsigned long vuoGetNextEventId ( void  )

Returns a unique event ID.

struct NodeContext* vuoGetNodeContext ( const char *  compositionIdentifier,
unsigned long  nodeIndex 
)
read

Returns the node context registered for the node index, or null if none is found.

PortContext* vuoGetNodeContextPortContext ( NodeContext nodeContext,
size_t  index 
)
read

Gets the array element at the given index of the node context's portContexts field.

dispatch_semaphore_t vuoGetNodeContextSemaphore ( struct NodeContext nodeContext)

Gets the node context's semaphore field.

static string vuoGetNodeIdentifierForIndex ( const char *  compositionIdentifier,
unsigned long  nodeIndex 
)
static

Looks up the node identifier for the node with the given index.

static unsigned long vuoGetNodeIndexForIdentifier ( const string &  compositionIdentifier,
const string &  nodeIdentifier 
)
static

Looks up the node index for the node with the given identifier.

unsigned long vuoGetNodeIndexForPort ( const char *  compositionIdentifier,
const char *  portIdentifier 
)

Returns the numerical index for a node, given the identifier of a port on the node.

dispatch_semaphore_t vuoGetNodeSemaphoreForPort ( const char *  compositionIdentifier,
const char *  portIdentifier 
)

Returns the semaphore field in a node's context, given the identifier of a port on the node.

void* vuoGetPortContextData ( struct PortContext portContext)

Gets the port context's data field.

unsigned long vuoGetTypeIndexForPort ( const char *  compositionIdentifier,
const char *  portIdentifier 
)

Returns the numerical index for a port's type, given the port's identifier.

void vuoGrantThreadsToSubcomposition ( unsigned long  eventId,
char *  compositionIdentifier,
unsigned long  chainIndex,
char *  subcompositionIdentifier 
)

Allows the published input trigger of a subcomposition node to use the threads allocated for the chain containing the node.

This function should be called before vuoScheduleTriggerWorker() is called for the published input trigger.

void vuoInitWorkerThreadPool ( void  )

Sets up the pool of worker threads.

bool vuoIsNodeBeingAddedOrReplaced ( const char *  nodeIdentifier,
json_object **  replacementObj 
)

Returns true if the node is among the additions or replacers across a live-coding reload, or if the composition is being started (not a live-coding reload).

bool vuoIsNodeBeingRemovedOrReplaced ( const char *  nodeIdentifier,
json_object **  replacementObj 
)

Returns true if the node is among the removals or replacees across a live-coding reload, or if the composition is being stopped (not a live-coding reload).

static bool vuoIsPortBeingReplaced ( const char *  portName,
json_object replacementObj 
)
static

Returns true if the port is among the replacees across a live-coding reload.

static bool vuoIsPortReplacingAnother ( const char *  portName,
json_object replacementObj,
string &  oldNodeIdentifier,
string &  oldPortIdentifier 
)
static

Returns true if the port is among the replacers across a live-coding reload.

static void vuoRelocateAllNodeContexts ( void  )
static

Preserves all remaining node contexts to be accessed after a live-coding reload, and clears the list of registered node contexts.

static void vuoRelocateAllPortIdentifiers ( void  )
static

Preserves all remaining port cache entries to be accessed after a live-coding reload, and clears the port cache.

static void vuoRemoveAllCarriedOverNodeContexts ( void(*)(const char *, const char *, NodeContext *)  compositionDestroyNodeContext)
static

Removes all remaining items from the list of carried-over node contexts.

static void vuoRemoveAllCarriedOverPortIdentifiers ( void  )
static

Removes all remaining items from the list of carried-over port cache entries.

static void vuoRemoveCarriedOverNodeContext ( const char *  compositionIdentifier,
const string &  nodeIdentifier 
)
static

Removes the node from the list of carried-over node contexts.

static void vuoRemoveCarriedOverPortIdentifier ( const char *  compositionIdentifier,
const string &  oldPortIdentifier 
)
static

Removes the port from the list of carried-over port cache entries.

static void vuoRemoveNodeContext ( const char *  compositionIdentifier,
unsigned long  nodeIndex 
)
static

Un-registers a node context.

static void vuoRemovePortIdentifier ( const char *  compositionIdentifier,
const string &  portIdentifier 
)
static

Removes the port from the port cache.

void vuoRetainPortContextData ( struct PortContext portContext)

Prevents the port context's data field from being freed by vuoFreePortContext().

void vuoReturnThreadsForChainWorker ( unsigned long  eventId,
char *  compositionIdentifier,
unsigned long  chainIndex 
)

Returns the threads allocated for the chain worker to the thread pool.

void vuoReturnThreadsForTriggerWorker ( unsigned long  eventId)

Returns the threads allocated for the trigger worker to the thread pool.

void vuoScheduleChainWorker ( dispatch_queue_t  queue,
void *  context,
void(*)(void *)  function,
int  minThreadsNeeded,
int  maxThreadsNeeded,
unsigned long  eventId,
char *  compositionIdentifier,
unsigned long  chainIndex,
unsigned long *  upstreamChainIndices,
int  upstreamChainIndicesCount 
)

Schedules a chain worker function to be called when enough threads are available from the thread pool.

void vuoScheduleTriggerWorker ( dispatch_queue_t  queue,
void *  context,
void(*)(void *)  function,
int  minThreadsNeeded,
int  maxThreadsNeeded,
unsigned long  eventId,
char *  compositionIdentifier,
int  chainCount 
)

Schedules a trigger worker function to be called when enough threads are available from the thread pool.

For the published input trigger of a subcomposition node, pass -1 for minThreadsNeeded and maxThreadsNeeded.

After this function is called, either vuoReturnThreadsForTriggerWorker() should be called for the trigger or vuoReturnThreadsForChainWorker() should be called for each chain downstream of the trigger.

void vuoSetPortContextData ( struct PortContext portContext,
void *  data 
)

Sets the port context's data field.

Variable Documentation

map<string, map<string, void *> > carriedOverDataForPort
static

Info from dataForPort carried across a live-coding reload.

map<string, map<string, struct NodeContext *> > carriedOverNodeContextForIdentifier
static

Info from nodeContextForIndex carried across a live-coding reload, indexed by composition identifier and node identifier.

map<string, map<string, unsigned long> > carriedOverNodeIndexForPort
static

Info from nodeIndexForPort carried across a live-coding reload.

map<string, vector<NodeMetadata> > carriedOverNodeMetadatas
static

Node metadata for nodes within subcompositions that are kept across a live-coding reload.

The indexes for these nodes remain the same across the live-coding reload.

map<string, map<string, dispatch_semaphore_t> > carriedOverNodeSemaphoreForPort
static

Info from nodeSemaphoreForPort carried across a live-coding reload.

map<string, map<string, unsigned long> > carriedOverTypeIndexForPort
static

Info from typeIndexForPort carried across a live-coding reload.

char* compositionDiff = NULL

Differences between the old and new composition, when replacing compositions for live coding.

map<unsigned long, string> compositionIdentifierForHash
static

The composition identifier for each hash registered in nodeContextForIndex.

map<string, map<string, void *> > dataForPort
static

The data field in the port's context, indexed by composition and port identifier.

const unsigned long invalidCompositionIndex = ULONG_MAX - 1
static

Used for error conditions.

bool isPaused = false

True if node execution is currently paused.

ThreadPool mainThreadPool

Trigger workers claim threads from this thread pool.

bool mayMoreWorkersBeDequeued
static

Becomes true when dequeueWorker() has finished flushing out the remaining workers.

bool mayMoreWorkersBeEnqueued
static

Becomes true when the composition is stopping, indicating that dequeueWorker() is now flushing out the remaining workers and shouldn't expect new events.

map<unsigned long, map<unsigned long, struct NodeContext *> > nodeContextForIndex
static

A registry of all NodeContext values in the running composition, indexed by hashed composition identifier and node index.

map<string, map<string, unsigned long> > nodeIndexForPort
static

The index for a node, indexed by composition and port identifier.

map<string, vector<NodeMetadata> > nodeMetadatas
static

The metadata for each node, by composition identifier and node index.

A node's index can change across a live-coding reload.

map<string, map<string, dispatch_semaphore_t> > nodeSemaphoreForPort
static

The semaphore field in the node's context, indexed by composition and port identifier.

dispatch_queue_t threadPoolSync
static

Synchronizes access to mainThreadPool and triggerThreadPools.

const unsigned long topLevelCompositionIndex = ULONG_MAX
static

The index for the top-level composition's node context in nodeContextForIndex.

map<unsigned long, map<unsigned long, ThreadPool> > triggerThreadPools

Chain workers claim threads from the thread pool for their event ID and hashed composition identifier.

map<string, map<string, unsigned long> > typeIndexForPort
static

The index for the port's type, indexed by composition and port identifier.

unsigned long vuoLastEventId = 0

The ID most recently assigned to any event, composition-wide. Used to generate a unique ID for each event.

char* vuoTopLevelCompositionIdentifier

The composition identifier of the top-level composition.

dispatch_group_t vuoTriggerWorkersScheduled = NULL

Keeps track of trigger workers that have been scheduled but have not yet launched an event into the composition.

vector<Worker> workersDequeued
static

Temporary storage in dequeueWorkers(), made global to avoid the cost of reallocating with every call.

vector<WorkerQueue::Node *> workersDequeuedNodes
static

Temporary storage in dequeueWorkers(), made global to avoid the cost of reallocating with every call.

dispatch_semaphore_t workersUpdated
static

Notifies dequeueWorker() when there may be a new worker available to dequeue.

WorkerQueue workersWaitingForThreads
static

Queue of workers waiting to use threads from the pool.

dispatch_queue_t workersWaitingSync
static

Synchronizes access to workersWaitingForThreads.