Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Officeyutong committed Aug 21, 2024
1 parent 01ef162 commit ff88223
Showing 1 changed file with 30 additions and 49 deletions.
79 changes: 30 additions & 49 deletions runtime/src/bpftime_shm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,35 @@

#ifdef __APPLE__
// Custom implementation for sigtimedwait
int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout) {
struct timespec start, now;
clock_gettime(CLOCK_REALTIME, &start);
int sig;

while (true) {
// Try to wait for a signal
if (sigwait(set, &sig) == 0) {
if (info != nullptr) {
memset(info, 0, sizeof(*info));
info->si_signo = sig;
}
return sig;
}

// Check if the timeout has expired
clock_gettime(CLOCK_REALTIME, &now);
if ((now.tv_sec - start.tv_sec) > timeout->tv_sec ||
((now.tv_sec - start.tv_sec) == timeout->tv_sec && (now.tv_nsec - start.tv_nsec) > timeout->tv_nsec)) {
errno = EAGAIN;
return -1;
}

// Sleep for a short time before retrying
usleep(1000); // Sleep for 1ms before retrying
}
int sigtimedwait(const sigset_t *set, siginfo_t *info,
const struct timespec *timeout)
{
struct timespec start, now;
clock_gettime(CLOCK_REALTIME, &start);
int sig;

while (true) {
// Try to wait for a signal
if (sigwait(set, &sig) == 0) {
if (info != nullptr) {
memset(info, 0, sizeof(*info));
info->si_signo = sig;
}
return sig;
}

// Check if the timeout has expired
clock_gettime(CLOCK_REALTIME, &now);
if ((now.tv_sec - start.tv_sec) > timeout->tv_sec ||
((now.tv_sec - start.tv_sec) == timeout->tv_sec &&
(now.tv_nsec - start.tv_nsec) > timeout->tv_nsec)) {
errno = EAGAIN;
return -1;
}

// Sleep for a short time before retrying
usleep(1000); // Sleep for 1ms before retrying
}
}
#endif

Expand Down Expand Up @@ -210,28 +213,6 @@ void bpftime_close(int fd)
shm_holder.global_shared_memory.close_fd(fd);
}

const char * expand_filename(const char *filename)
{
const char *home_dir = getenv("HOME");
if (home_dir == NULL) {
SPDLOG_INFO("Error: HOME environment variable is not set");
return NULL;
}

size_t size = strlen(home_dir) + strlen(filename) + 1;
char *absolute_path = (char *)malloc(size);
if (absolute_path == NULL) {
SPDLOG_INFO("Error: Memory allocation failed");
return NULL;
}

sprintf(absolute_path, "%s/%s", home_dir, filename);
const char *result = strdup(absolute_path);
free(absolute_path);

return result;
}

int bpftime_map_get_info(int fd, bpftime::bpf_map_attr *out_attr,
const char **out_name, bpftime::bpf_map_type *type)
{
Expand Down Expand Up @@ -566,7 +547,7 @@ int bpftime_shared_perf_event_output(int map_fd, const void *buf, size_t sz)
return -1;
}
}
#endif
#endif

int bpftime_is_prog_array(int fd)
{
Expand Down

0 comments on commit ff88223

Please sign in to comment.