Skip to content

Commit

Permalink
adjust compilation:
Browse files Browse the repository at this point in the history
in thread/test/
g++ -std=c++17 -I ../../include/ -DThreadUT test.cpp x.cpp ../thread-pool.cpp ../workerpool.cpp ../thread-key.cpp ../../common/identity-pool.cpp ../../common/alog.cpp -lgtest -lgflags -O2
  • Loading branch information
lihuiba committed Sep 13, 2023
1 parent 968406c commit 5043029
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions common/alog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifdef _WIN64
#define _POSIX_C_SOURCE 1
#endif
#include "alog.h"
#include "lockfree_queue.h"
#include "photon/thread/thread.h"
Expand Down Expand Up @@ -251,7 +254,11 @@ class LogOutputFile final : public BaseLogOutput {
if (log_file_fd < 0) return;
uint64_t length = end - begin;
iovec iov{(void*)begin, length};
#ifndef _WIN64
::writev(log_file_fd, &iov, 1); // writev() is atomic, whereas write() is not
#else
::write(log_file_fd, iov.iov_base, iov.iov_len);
#endif
throttle_block();
if (log_file_name && log_file_size_limit) {
log_file_size += length;
Expand Down
8 changes: 7 additions & 1 deletion thread/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,8 +1465,14 @@ TEST(workpool, async_work_lambda_threadpool_append) {
LOG_INFO("DONE");
}

#if defined(_WIN64)
#define SAVE_REG(R) register uint64_t R asm(#R); volatile uint64_t saved_##R = R;
#define CHECK_REG(R) asm volatile ("" : "=r"(saved_##R) : "0"(saved_##R)); if (saved_##R != R) puts("differs after context switch!" #R);
#define CHECK_REG(R) asm volatile ("" : "=m"(saved_##R)); if (saved_##R != R) puts(#R " differs after context switch!");
#else
#define SAVE_REG(R)
#define CHECK_REG(R)
#endif

void* waiter(void* arg) {
auto p = (int*)arg;
LOG_INFO("Start", VALUE(p), VALUE(*p));
Expand Down
2 changes: 1 addition & 1 deletion thread/test/x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int DevNull(void* x, int)

int (*pDevNull)(void*, int) = &DevNull;

#ifdef TEST
#ifdef ThreadUT

#include "../thread.h"
namespace photon {
Expand Down

0 comments on commit 5043029

Please sign in to comment.