Skip to content

Commit

Permalink
dd
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed May 30, 2024
1 parent a6176d3 commit 913cba2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion messaging/impl_msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ volatile sig_atomic_t msgq_do_exit = 0;
void sig_handler(int signal) {
assert(signal == SIGINT || signal == SIGTERM);
msgq_do_exit = 1;
printf("sig received *************\n");
}

static bool service_exists(std::string path){
Expand Down Expand Up @@ -93,7 +94,9 @@ Message * MSGQSubSocket::receive(bool non_blocking){
MSGQMessage *r = NULL;

int rc = msgq_msg_recv(&msg, q);

static std::atomic<int> dd;
++dd;
printf("begin recev %d\n", dd.load());
// Hack to implement blocking read with a poller. Don't use this
while (!non_blocking && rc == 0 && msgq_do_exit == 0){
msgq_pollitem_t items[1];
Expand All @@ -114,6 +117,8 @@ Message * MSGQSubSocket::receive(bool non_blocking){
}
}

printf("end recev %d\n", dd.load());


if (!non_blocking){
std::signal(SIGINT, prev_handler_sigint);
Expand Down
12 changes: 11 additions & 1 deletion messaging/msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ SharedMemory::SharedMemory(const std::string &name, size_t size) :shm_name(name)
}

SharedMemory::~SharedMemory() {
printf("before ~SharedMemory\n");
munmap(shm_ptr, shm_size);
::close(shm_fd);
printf("end ~SharedMemory\n");
}

void SharedMemory::notifyAll() {
Expand All @@ -89,7 +91,13 @@ void SharedMemory::notifyAll() {
}

void SharedMemory::waitFor(const struct timespec *abstime) {

static std::atomic<int> d = 0;
++d;
printf("before wait for %d\n", d.load());
pthread_mutex_lock(&(header->mutex));
pthread_cond_timedwait(&(header->cond), &(header->mutex), abstime);
pthread_mutex_unlock(&(header->mutex));
printf("end wait for %d\n", d.load());
}

msgq_context::msgq_context() : shm("msgq_poll", 0) {
Expand Down Expand Up @@ -178,7 +186,9 @@ int msgq_new_queue(msgq_queue_t * q, const char * path, size_t size){
}

void msgq_close_queue(msgq_queue_t *q){
printf("close queue...\n");
delete q->shm;
printf("close queue finished\n");
}

void msgq_init_publisher(msgq_queue_t * q) {
Expand Down
1 change: 1 addition & 0 deletions messaging/msgq.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SharedMemory {

struct msgq_context {
msgq_context();
~msgq_context() {printf("msgq_context closed*************\n");}
SharedMemory shm;
SharedMemoryHeader *ctx;
};
Expand Down

0 comments on commit 913cba2

Please sign in to comment.