28#define _Class _OperationQueue
47 const Array *threads = (
Array *) this->locals.threads;
49 for (
size_t i = 0; i < threads->
count; i++) {
53 synchronized(this->locals.condition, {
57 for (
size_t i = 0; i < threads->
count; i++) {
62 release(this->locals.condition);
63 release(this->locals.operations);
68#pragma mark - OperationQueue
82 operation->locals.
queue = self;
142 bool isCancelled =
false;
144 while (!isCancelled) {
161 if (operation == NULL && !isCancelled) {
166 if (operation == NULL) {
192 assert(maxConcurrentOperations);
206 for (
size_t i = 0; i < maxConcurrentOperations; i++) {
217 for (
size_t i = 0; i < threads->
count; i++) {
265 operation->locals.
queue = NULL;
311 if (operation == NULL) {
321#pragma mark - Class lifecycle
355 .name =
"OperationQueue",
359 .interfaceSize =
sizeof(OperationQueueInterface),
static ident find(const Array *self, Predicate predicate, ident data)
static ident objectAtIndex(const Array *self, size_t index)
static void removeObject(Array *self, const ident obj)
static void addObject(Array *self, const ident obj)
static ident firstObject(const Array *self)
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Class * _initialize(const ClassDef *def)
Initializes the given Class.
ident retain(ident obj)
Atomically increment the given Object's reference count.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
static void broadcast(Condition *self)
static void waitUntilFinished(const Operation *self)
static Operation * initWithFunction(Operation *self, OperationFunction function, ident data)
static void start(Operation *self)
static void cancel(Operation *self)
static bool isReady(const Operation *self)
void(* OperationFunction)(Operation *operation)
The function type for Operation execution.
Class * _OperationQueue(void)
static void resume(OperationQueue *self)
static void removeOperation(OperationQueue *self, Operation *operation)
static size_t operationCount(const OperationQueue *self)
static OperationQueue * currentQueue(void)
static void addOperation(OperationQueue *self, Operation *operation)
static void waitUntilAllOperationsAreFinished(OperationQueue *self)
static void suspend(OperationQueue *self)
static OperationQueue * initWithMaxConcurrentOperations(OperationQueue *self, size_t maxConcurrentOperations)
static Operation * addOperationWithFunction(OperationQueue *self, OperationFunction function, ident data)
static __thread OperationQueue * _currentQueue
static void cancelAllOperations(OperationQueue *self)
static ident run(Thread *thread)
ThreadFunction for the OperationQueue Threads.
static OperationQueue * init(OperationQueue *self)
static bool isOperationReady(const ident obj, ident data)
Predicate matching the next Operation eligible to start.
static Array * operations(const OperationQueue *self)
static void dealloc(Object *self)
static Object * copy(const Object *self)
static void initialize(Class *clazz)
OperationQueues provide threads of execution for Operations.
static void join(Thread *self, ident *status)
void * ident
The identity type, similar to Objective-C id.
#define do_once(once, block)
Executes the given block at most one time.
size_t count
The count of elements.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
POSIX Threads conditional variables.
Object is the root Class of The Objectively Class hierarchy.
void dealloc(Object *self)
Frees all resources held by this Object.
An abstraction for discrete units of work, or tasks.
bool isCancelled
true when this Operation has been cancelled, false otherwise.
bool isFinished
true when this Operation is finished, false otherwise.
bool isDispatched
True once an OperationQueue has dispatched this Operation to one of its Threads, so that no other Thr...
OperationQueue * queue
The OperationQueue this Operation was added to, if any.
bool isExecuting
true when this Operation is executing, false otherwise.
OperationQueues provide threads of execution for Operations.
Array * threads
The backing Threads, one per concurrently executing Operation.
size_t operationCount(const OperationQueue *self)
OperationQueue * initWithMaxConcurrentOperations(OperationQueue *self, size_t maxConcurrentOperations)
Initializes this OperationQueue with the given concurrency.
OperationQueue * init(OperationQueue *self)
Initializes this OperationQueue as a serial queue.
bool isSuspended
When true, the queue will not start any new Operations.
Array * operations
The Operations.
Condition * condition
A condition signaled on addOperation and removeOperation.
bool isCancelled
true when this Thread has been cancelled, false otherwise.