Skip to content

Commit a07bba6

Browse files
committed
TestQueues: Move the synchronisation code into the binary itself.
Thanks to Pavel Labath for the suggestion! llvm-svn: 350360
1 parent 58c61dc commit a07bba6

File tree

2 files changed

+14
-43
lines changed

2 files changed

+14
-43
lines changed

lldb/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ def setUp(self):
3030
# Find the line numbers that we will step to in main:
3131
self.main_source = "main.c"
3232

33-
def remove_token(self, name):
34-
for i in range(7):
35-
token = name+'.token.%d'%i
36-
if os.path.exists(token):
37-
os.remove(token)
38-
39-
def await_token(self, name):
40-
for i in range(7):
41-
lldbutil.wait_for_file_on_target(self, name+'.token.%d'%i)
42-
4333
def check_queue_for_valid_queue_id(self, queue):
4434
self.assertTrue(
4535
queue.GetQueueID() != 0, "Check queue %s for valid QueueID (got 0x%x)" %
@@ -122,14 +112,12 @@ def queues(self):
122112
self.main_source_spec = lldb.SBFileSpec(self.main_source)
123113
break1 = target.BreakpointCreateByName("stopper", 'a.out')
124114
self.assertTrue(break1, VALID_BREAKPOINT)
125-
self.remove_token(exe)
126115
process = target.LaunchSimple(
127-
[exe+'.token.'], None, self.get_process_working_directory())
116+
[], None, self.get_process_working_directory())
128117
self.assertTrue(process, PROCESS_IS_VALID)
129118
threads = lldbutil.get_threads_stopped_at_breakpoint(process, break1)
130119
if len(threads) != 1:
131120
self.fail("Failed to stop at breakpoint 1.")
132-
self.await_token(exe)
133121

134122
queue_submittor_1 = lldb.SBQueue()
135123
queue_performer_1 = lldb.SBQueue()
@@ -283,9 +271,8 @@ def queues_with_libBacktraceRecording(self):
283271
if self.getArchitecture() in ['arm', 'arm64', 'arm64e', 'arm64_32', 'armv7', 'armv7k']:
284272
libbtr_path = "/Developer/usr/lib/libBacktraceRecording.dylib"
285273

286-
self.remove_token(exe)
287274
process = target.LaunchSimple(
288-
[exe+'.token.'],
275+
[],
289276
[
290277
'DYLD_INSERT_LIBRARIES=%s' % (libbtr_path),
291278
'DYLD_LIBRARY_PATH=/usr/lib/system/introspection'],
@@ -297,7 +284,6 @@ def queues_with_libBacktraceRecording(self):
297284
threads = lldbutil.get_threads_stopped_at_breakpoint(process, break1)
298285
if len(threads) != 1:
299286
self.fail("Failed to stop at breakpoint 1.")
300-
self.await_token(exe)
301287

302288
libbtr_module_filespec = lldb.SBFileSpec("libBacktraceRecording.dylib")
303289
libbtr_module = target.FindModule(libbtr_module_filespec)

lldb/packages/Python/lldbsuite/test/macosx/queues/main.c

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
#include <stdio.h>
2-
#include <stdlib.h>
1+
#include <stdatomic.h>
32
#include <string.h>
43
#include <unistd.h>
54
#include <dispatch/dispatch.h>
65
#include <pthread.h>
76

87
int finished_enqueueing_work = 0;
9-
char *name = NULL;
10-
11-
void
12-
touch (const char *name, unsigned n)
13-
{
14-
char token[2048];
15-
snprintf (token, 2048, "%s%d", name, n);
16-
FILE *f = fopen (token, "wx");
17-
if (!f)
18-
exit (1);
19-
fputs ("\n", f);
20-
fflush (f);
21-
fclose (f);
22-
}
8+
atomic_int thread_count = 0;
239

2410
void
2511
doing_the_work_1(void *in)
2612
{
27-
touch (name, 0);
13+
atomic_fetch_add(&thread_count, 1);
2814
while (1)
2915
sleep (1);
3016
}
@@ -96,9 +82,6 @@ stopper ()
9682

9783
int main (int argc, const char **argv)
9884
{
99-
if (argc != 2)
100-
return 2;
101-
name = argv[1];
10285
dispatch_queue_t work_submittor_1 = dispatch_queue_create ("com.apple.work_submittor_1", DISPATCH_QUEUE_SERIAL);
10386
dispatch_queue_t work_submittor_2 = dispatch_queue_create ("com.apple.work_submittor_and_quit_2", DISPATCH_QUEUE_SERIAL);
10487
dispatch_queue_t work_submittor_3 = dispatch_queue_create ("com.apple.work_submittor_3", DISPATCH_QUEUE_SERIAL);
@@ -117,44 +100,46 @@ int main (int argc, const char **argv)
117100

118101

119102
// Spin up threads with each of the different libdispatch QoS values.
120-
121103
dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
122104
pthread_setname_np ("user initiated QoS");
123-
touch(name, 1);
105+
atomic_fetch_add(&thread_count, 1);
124106
while (1)
125107
sleep (10);
126108
});
127109
dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
128110
pthread_setname_np ("user interactive QoS");
129-
touch(name, 2);
111+
atomic_fetch_add(&thread_count, 1);
130112
while (1)
131113
sleep (10);
132114
});
133115
dispatch_async (dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
134116
pthread_setname_np ("default QoS");
135-
touch(name, 3);
117+
atomic_fetch_add(&thread_count, 1);
136118
while (1)
137119
sleep (10);
138120
});
139121
dispatch_async (dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
140122
pthread_setname_np ("utility QoS");
141-
touch(name, 4);
123+
atomic_fetch_add(&thread_count, 1);
142124
while (1)
143125
sleep (10);
144126
});
145127
dispatch_async (dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
146128
pthread_setname_np ("background QoS");
147-
touch(name, 5);
129+
atomic_fetch_add(&thread_count, 1);
148130
while (1)
149131
sleep (10);
150132
});
151133
dispatch_async (dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), ^{
152134
pthread_setname_np ("unspecified QoS");
153-
touch(name, 6);
135+
atomic_fetch_add(&thread_count, 1);
154136
while (1)
155137
sleep (10);
156138
});
157139

140+
// Unfortunately there is no pthread_barrier on darwin.
141+
while (atomic_load(&thread_count) < 7)
142+
sleep(1);
158143

159144
while (finished_enqueueing_work == 0)
160145
sleep (1);

0 commit comments

Comments
 (0)