Objectively
Object oriented framework for C.
Loading...
Searching...
No Matches
Operation.h
Go to the documentation of this file.
1/*
2 * Objectively: Ultra-lightweight object oriented framework for GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <Objectively/Array.h>
28#include <Objectively/Object.h>
29#include <Objectively/Thread.h>
30
36typedef struct Operation Operation;
37typedef struct OperationInterface OperationInterface;
38
39typedef struct OperationQueue OperationQueue;
40
45typedef void (*OperationFunction)(Operation *operation);
46
53struct Operation {
54
59
64 OperationInterface *interface;
65
69 struct {
74
79
87 } locals;
88
94
99
104
109
115
120
125};
126
130struct OperationInterface {
131
135 ObjectInterface objectInterface;
136
144 void (*addDependency)(Operation *self, Operation *dependency);
145
152 void (*cancel)(Operation *self);
153
160 Array *(*dependencies)(const Operation *self);
161
170 Operation *(*init)(Operation *self);
171
181 Operation *(*initWithFunction)(Operation *self, OperationFunction function, ident data);
182
189 bool (*isReady)(const Operation *self);
190
198 void (*removeDependency)(Operation *self, Operation *dependency);
199
211 void (*start)(Operation *self);
212
219 void (*waitUntilFinished)(const Operation *self);
220};
221
Arrays.
POSIX Threads conditional variables.
static Data * data(void)
Definition Data.c:286
Object is the root Class of The Objectively Class hierarchy.
void(* OperationFunction)(Operation *operation)
The function type for Operation execution.
Definition Operation.h:45
OBJECTIVELY_EXPORT Class * _Operation(void)
Definition Operation.c:234
POSIX Threads.
void * ident
The identity type, similar to Objective-C id.
Definition Types.h:49
#define OBJECTIVELY_EXPORT
Definition Types.h:36
Arrays.
Definition Array.h:56
The runtime representation of a Class.
Definition Class.h:95
POSIX Threads conditional variables.
Definition Condition.h:44
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
An abstraction for discrete units of work, or tasks.
Definition Operation.h:53
bool isCancelled
true when this Operation has been cancelled, false otherwise.
Definition Operation.h:108
ident data
The user data.
Definition Operation.h:98
bool isFinished
true when this Operation is finished, false otherwise.
Definition Operation.h:124
Condition * condition
The Condition enabling waitUntilFinished.
Definition Operation.h:73
bool isDispatched
True once an OperationQueue has dispatched this Operation to one of its Threads, so that no other Thr...
Definition Operation.h:114
OperationFunction function
The Operation function.
Definition Operation.h:103
OperationInterface * interface
The interface.
Definition Operation.h:64
Array * dependencies
Contains Operations which must finish before this one can start.
Definition Operation.h:78
bool asynchronous
If true, this Operation will be expected to coordinate its own concurrency and internal state managem...
Definition Operation.h:93
Object object
The superclass.
Definition Operation.h:58
OperationQueue * queue
The OperationQueue this Operation was added to, if any.
Definition Operation.h:86
bool isExecuting
true when this Operation is executing, false otherwise.
Definition Operation.h:119
OperationQueues provide threads of execution for Operations.