aboutsummaryrefslogtreecommitdiffstats
path: root/executor/executor_posix.h
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-07-20 20:26:05 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-07-24 12:04:27 +0200
commit9fe4bdc5f1037a409e82299f36117030114c7b94 (patch)
treed3d73c1f69ded8152436be47684a07baa0e7f6ec /executor/executor_posix.h
parentdb7957bc09bf5715d33e4c56b8614579aa94000a (diff)
executor: overhaul
Make as much code as possible shared between all OSes. In particular main is now common across all OSes. Make more code shared between executor and csource (in particular, loop function and threaded execution logic). Also make loop and threaded logic shared across all OSes. Make more posix/unix code shared across OSes (e.g. signal handling, pthread creation, etc). Plus other changes along similar lines. Also support test OS in executor (based on portable posix) and add 4 arches that cover all execution modes (fork server/no fork server, shmem/no shmem). This change paves way for testing of executor code and allows to preserve consistency across OSes and executor/csource.
Diffstat (limited to 'executor/executor_posix.h')
-rw-r--r--executor/executor_posix.h82
1 files changed, 0 insertions, 82 deletions
diff --git a/executor/executor_posix.h b/executor/executor_posix.h
deleted file mode 100644
index 3e8b78b3e..000000000
--- a/executor/executor_posix.h
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2017 syzkaller project authors. All rights reserved.
-// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
-
-#include <pthread.h>
-
-typedef pthread_t osthread_t;
-
-void thread_start(osthread_t* t, void* (*fn)(void*), void* arg)
-{
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setstacksize(&attr, 128 << 10);
- if (pthread_create(t, &attr, fn, arg))
- exitf("pthread_create failed");
- pthread_attr_destroy(&attr);
-}
-
-struct event_t {
- pthread_mutex_t mu;
- pthread_cond_t cv;
- bool state;
-};
-
-void event_init(event_t* ev)
-{
- if (pthread_mutex_init(&ev->mu, 0))
- fail("pthread_mutex_init failed");
- if (pthread_cond_init(&ev->cv, 0))
- fail("pthread_cond_init failed");
- ev->state = false;
-}
-
-void event_reset(event_t* ev)
-{
- ev->state = false;
-}
-
-void event_set(event_t* ev)
-{
- pthread_mutex_lock(&ev->mu);
- if (ev->state)
- fail("event already set");
- ev->state = true;
- pthread_mutex_unlock(&ev->mu);
- pthread_cond_broadcast(&ev->cv);
-}
-
-void event_wait(event_t* ev)
-{
- pthread_mutex_lock(&ev->mu);
- while (!ev->state)
- pthread_cond_wait(&ev->cv, &ev->mu);
- pthread_mutex_unlock(&ev->mu);
-}
-
-bool event_isset(event_t* ev)
-{
- pthread_mutex_lock(&ev->mu);
- bool res = ev->state;
- pthread_mutex_unlock(&ev->mu);
- return res;
-}
-
-bool event_timedwait(event_t* ev, uint64 timeout_ms)
-{
- pthread_mutex_lock(&ev->mu);
- uint64 start = current_time_ms();
- for (;;) {
- if (ev->state)
- break;
- uint64 now = current_time_ms();
- if (now - start > timeout_ms)
- break;
- timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = (timeout_ms - (now - start)) * 1000 * 1000;
- pthread_cond_timedwait(&ev->cv, &ev->mu, &ts);
- }
- bool res = ev->state;
- pthread_mutex_unlock(&ev->mu);
- return res;
-}