forked from DeckerSU/yiimp-stratum-equihash
-
Notifications
You must be signed in to change notification settings - Fork 3
/
object.cpp
103 lines (79 loc) · 1.74 KB
/
object.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "stratum.h"
YAAMP_OBJECT *object_find(CommonList *list, int id, bool lock)
{
if(lock) list->Enter();
for(CLI li = list->first; li; li = li->next)
{
YAAMP_OBJECT *object = (YAAMP_OBJECT *)li->data;
if(object->id == id)
{
if(lock)
{
object_lock(object);
list->Leave();
}
return object;
}
}
if(lock) list->Leave();
return NULL;
}
void object_lock(YAAMP_OBJECT *object)
{
if(!object) return;
object->lock_count++;
}
void object_unlock(YAAMP_OBJECT *object)
{
if(!object) return;
object->lock_count--;
}
void object_delete(YAAMP_OBJECT *object)
{
if(!object) return;
object->deleted = true;
}
void object_prune(CommonList *list, YAAMP_OBJECT_DELETE_FUNC deletefunc)
{
list->Enter();
for(CLI li = list->first; li && list->count > 0; )
{
CLI todel = li;
YAAMP_OBJECT *object = (YAAMP_OBJECT *)li->data;
li = li->next;
if(!object) continue;
if(object->deleted && !object->lock_count)
{
deletefunc(object);
todel->data = NULL;
list->Delete(todel);
}
else if(object->lock_count && object->unlock)
object->lock_count--;
}
list->Leave();
}
void object_prune_debug(CommonList *list, YAAMP_OBJECT_DELETE_FUNC deletefunc)
{
list->Enter();
for(CLI li = list->first; li && list->count > 0; )
{
CLI todel = li;
YAAMP_OBJECT *object = (YAAMP_OBJECT *)li->data;
li = li->next;
if(!object) continue;
if(object->deleted && object->lock_count)
debuglog("object set for delete is locked\n");
if(object->deleted && !object->lock_count)
{
deletefunc(object);
todel->data = NULL;
list->Delete(todel);
}
else if(object->lock_count && object->unlock)
object->lock_count--;
}
if (list->count)
debuglog("still %d objects in list\n", list->count);
list->Leave();
}