2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2019 ScyllaDB Ltd.
24 #include "syscall_work_queue.hh"
32 uint64_t _aio_threaded_fallbacks = 0;
34 syscall_work_queue inter_thread_wq;
35 posix_thread _worker_thread;
36 std::atomic<bool> _stopped = { false };
37 std::atomic<bool> _main_thread_idle = { false };
39 explicit thread_pool(reactor* r, sstring thread_name);
41 template <typename T, typename Func>
42 future<T> submit(Func func) noexcept {
43 ++_aio_threaded_fallbacks;
44 return inter_thread_wq.submit<T>(std::move(func));
46 uint64_t operation_count() const { return _aio_threaded_fallbacks; }
48 unsigned complete() { return inter_thread_wq.complete(); }
49 // Before we enter interrupt mode, we must make sure that the syscall thread will properly
50 // generate signals to wake us up. This means we need to make sure that all modifications to
51 // the pending and completed fields in the inter_thread_wq are visible to all threads.
53 // Simple release-acquire won't do because we also need to serialize all writes that happens
54 // before the syscall thread loads this value, so we'll need full seq_cst.
55 void enter_interrupt_mode() { _main_thread_idle.store(true, std::memory_order_seq_cst); }
56 // When we exit interrupt mode, however, we can safely used relaxed order. If any reordering
57 // takes place, we'll get an extra signal and complete will be called one extra time, which is
59 void exit_interrupt_mode() { _main_thread_idle.store(false, std::memory_order_relaxed); }
63 template <typename T, typename Func>
64 future<T> submit(Func func) { std::cerr << "thread_pool not yet implemented on osv\n"; abort(); }
67 void work(sstring thread_name);