#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
#include "Lock.h"
Go to the source code of this file.
◆ _Class
◆ _Lock()
Definition at line 129 of file Lock.c.
129 {
132
135 .name = "Lock",
137 .instanceSize =
sizeof(
Lock),
138 .interfaceOffset = offsetof(
Lock, interface),
139 .interfaceSize = sizeof(LockInterface),
141 });
142 });
143
144 return clazz;
145}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
static void initialize(Class *clazz)
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
Class * _Object(void)
The Object archetype.
◆ copy()
◆ dealloc()
static void dealloc |
( |
Object * |
self | ) |
|
|
static |
- See also
- Object::dealloc(Object *)
Definition at line 46 of file Lock.c.
46 {
47
49
50 pthread_mutex_destroy(this->
lock);
52
54}
#define super(type, obj, method,...)
void lock(Lock *self)
Acquire this lock, waiting indefinitely.
Object is the root Class of The Objectively Class hierarchy.
void dealloc(Object *self)
Frees all resources held by this Object.
◆ init()
Definition at line 62 of file Lock.c.
62 {
63
65 if (self) {
66
67 self->lock = calloc(1, sizeof(pthread_mutex_t));
68 assert(self->lock);
69
70 const int err = pthread_mutex_init(self->lock, NULL);
71 assert(err == 0);
72 }
73
74 return self;
75}
Condition * init(Condition *self)
Initializes this Condition.
◆ initialize()
static void initialize |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::initialize(Class *)
Definition at line 114 of file Lock.c.
114 {
115
118
123}
ident interface
The interface of the Class.
_Bool tryLock(Lock *self)
Attempt to acquire this lock immediately.
void unlock(Lock *self)
Release this Lock.
Object * copy(const Object *self)
Creates a shallow copy of this Object.
◆ lock()
static void lock |
( |
Lock * |
self | ) |
|
|
static |
Definition at line 81 of file Lock.c.
81 {
82
83 int err = pthread_mutex_lock(self->lock);
84 assert(err == 0);
85}
◆ tryLock()
static _Bool tryLock |
( |
Lock * |
self | ) |
|
|
static |
Definition at line 91 of file Lock.c.
91 {
92
93 int err = pthread_mutex_trylock(self->lock);
94 assert(err == 0 || err == EBUSY);
95
96 return err == 0;
97}
◆ unlock()
static void unlock |
( |
Lock * |
self | ) |
|
|
static |
Definition at line 103 of file Lock.c.
103 {
104
105 int err = pthread_mutex_unlock(self->lock);
106 assert(err == 0);
107}