Skip to content

Commit

Permalink
Polish implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuanqiXu9 committed Aug 5, 2024
1 parent eb05f92 commit 61bb545
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions async_simple/Executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <chrono>
#include <functional>
#include <string>
#include <ratio>
#include <thread>
#include "async_simple/MoveWrapper.h"
#include "async_simple/experimental/coroutine.h"
Expand Down
6 changes: 5 additions & 1 deletion async_simple/coro/Lazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ class LazyPromiseBase {
template <typename T>
class LazyPromise : public LazyPromiseBase {
public:
static_assert(alignof(T) <= alignof(::max_align_t),
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
static_assert(alignof(T) <= alignof(std::max_align_t),
"async_simple doesn't allow Lazy with over aligned object");
#endif

LazyPromise() noexcept {}
~LazyPromise() noexcept {}
Expand Down
1 change: 1 addition & 0 deletions async_simple/coro/Semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define ASYNC_SIMPLE_CORO_SEMAHORE_H

#include <cstddef>
#include <limits>
#include "async_simple/coro/ConditionVariable.h"
#include "async_simple/coro/SpinLock.h"

Expand Down
3 changes: 2 additions & 1 deletion async_simple/experimental/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ template <class P> struct hash<coroutine_handle<P>>;
// And the outdated <experimental/coroutine> is available for clang only(need to
// exclude msvc).
#if (__cplusplus <= 201703L && !defined(_MSC_VER)) || \
(defined(__clang__) && defined(__GLIBCXX__))
(defined(__clang__) && defined(__GLIBCXX__) && \
(__GLIBCXX__ < 20210408))
#define USE_SELF_DEFINED_COROUTINE
#endif

Expand Down
1 change: 1 addition & 0 deletions async_simple/uthread/Async.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <memory>
#include <type_traits>
#include <tuple>
#include "async_simple/uthread/Uthread.h"

namespace async_simple {
Expand Down
4 changes: 3 additions & 1 deletion async_simple/util/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
#include <iostream>
#include <thread>
#include <vector>
#include <cstdlib>

#include "async_simple/util/Queue.h"

namespace async_simple::util {
class ThreadPool {
public:
Expand Down Expand Up @@ -186,7 +188,7 @@ inline ThreadPool::ERROR_TYPE ThreadPool::scheduleById(std::function<void()> fn,
}
}

id = rand() % _threadNum;
id = std::rand() % _threadNum;
_queues[id].push(
WorkItem{/*canSteal = */ _enableWorkSteal, std::move(fn)});
} else {
Expand Down

0 comments on commit 61bb545

Please sign in to comment.