28#define _Class _OperationQueue
47 synchronized(this->condition, {
59#pragma mark - OperationQueue
72 synchronized(self->condition, {
73 operation->queue = self;
74 $(self->operations,
addObject, operation);
75 $(self->condition, signal);
139 synchronized(self->condition, {
148 $(self->condition, signal);
153 $(self->condition, wait);
157 if (operation == NULL) {
183 assert(maxConcurrentOperations);
189 assert(self->condition);
192 assert(self->operations);
195 assert(self->threadPool);
197 for (
size_t i = 0; i < maxConcurrentOperations; i++) {
213 synchronized(self->condition, {
214 count = ((
Array *) self->operations)->count;
228 synchronized(self->condition, {
244 synchronized(self->condition, {
245 operation->queue = NULL;
247 $(self->condition, signal);
257 synchronized(self->condition, {
269 synchronized(self->condition, {
284 synchronized(self->condition, {
291 if (operation == NULL) {
301#pragma mark - Class lifecycle
335 .name =
"OperationQueue",
338 .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 bool isCancelled(const Operation *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 detach(Thread *self)
static ThreadPool * initWithSize(ThreadPool *self, size_t size)
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 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...
bool isExecuting
true when this Operation is executing, false otherwise.
OperationQueues provide threads of execution for Operations.
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.
A fixed set of Threads that run ThreadFunctions on behalf of the caller.