Skip to content

Commit

Permalink
build on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Dec 15, 2019
1 parent 31ac47c commit 21cf3f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ libmessaging.*
libmessaging_shared.*
services.h
.sconsign.dblite
libcereal_shared.so
libcereal_shared.*

4 changes: 2 additions & 2 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cereal_objects = env.SharedObject([
])

env.Library('cereal', cereal_objects)
env.SharedLibrary('cereal_shared', cereal_objects)
env.SharedLibrary('cereal_shared', cereal_objects, LIBS=["capnp_c"])

cereal_dir = Dir('.')
services_h = env.Command(
Expand All @@ -49,7 +49,7 @@ Depends('messaging/impl_zmq.cc', services_h)

# note, this rebuilds the deps shared, zmq is statically linked to make APK happy
# TODO: get APK to load system zmq to remove the static link
shared_lib_shared_lib = [zmq, 'm', 'stdc++'] + ["gnustl_shared"] if arch == "aarch64" else []
shared_lib_shared_lib = [zmq, 'm', 'stdc++'] + ["gnustl_shared"] if arch == "aarch64" else [zmq]
env.SharedLibrary('messaging_shared', messaging_objects, LIBS=shared_lib_shared_lib)

env.Program('messaging/bridge', ['messaging/bridge.cc'], LIBS=[messaging_lib, 'zmq'])
Expand Down
2 changes: 2 additions & 0 deletions messaging/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <csignal>
#include <map>

typedef void (*sighandler_t)(int sig);

#include "services.h"

#include "impl_msgq.hpp"
Expand Down
14 changes: 11 additions & 3 deletions messaging/msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ void msgq_init_publisher(msgq_queue_t * q) {
q->write_uid_local = uid;
}

static void thread_signal(uint32_t tid) {
#ifndef SYS_tkill
// TODO: this won't work for multithreaded programs
kill(tid, SIGUSR1);
#else
syscall(SYS_tkill, tid, SIGUSR1);
#endif
}

void msgq_init_subscriber(msgq_queue_t * q) {
assert(q != NULL);
assert(q->num_readers != NULL);
Expand All @@ -173,7 +182,7 @@ void msgq_init_subscriber(msgq_queue_t * q) {
*q->read_uids[i] = 0;

// Wake up reader in case they are in a poll
syscall(SYS_tkill, old_uid & 0xFFFFFFFF, SIGUSR1);
thread_signal(old_uid & 0xFFFFFFFF);
}

continue;
Expand Down Expand Up @@ -278,8 +287,7 @@ int msgq_msg_send(msgq_msg_t * msg, msgq_queue_t *q){
// Notify readers
for (uint64_t i = 0; i < num_readers; i++){
uint64_t reader_uid = *q->read_uids[i];

syscall(SYS_tkill, reader_uid & 0xFFFFFFFF, SIGUSR1);
thread_signal(reader_uid & 0xFFFFFFFF);
}

return msg->size;
Expand Down

0 comments on commit 21cf3f5

Please sign in to comment.