Skip to content

Commit

Permalink
make polling atomic and use mtx_alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Jun 20, 2022
1 parent cde832f commit c503223
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct re {
int nfds; /**< Number of active file descriptors */
enum poll_method method; /**< The current polling method */
bool update; /**< File descriptor set need updating */
bool polling; /**< Is polling flag */
RE_ATOMIC bool polling; /**< Is polling flag */
int sig; /**< Last caught signal */
struct list tmrl; /**< List of timers */

Expand All @@ -99,7 +99,7 @@ struct re {
struct kevent *evlist;
int kqfd;
#endif
mtx_t mutex; /**< Mutex for thread synchronization */
mtx_t *mutex; /**< Mutex for thread synchronization */
mtx_t *mutexp; /**< Pointer to active mutex */
thrd_t tid; /**< Thread id */
RE_ATOMIC bool thread_enter; /**< Thread enter is called */
Expand All @@ -117,7 +117,7 @@ static void re_destructor(void *arg)
struct re *re = arg;

poll_close(re);
mtx_destroy(&re->mutex);
mem_deref(re->mutex);
}


Expand Down Expand Up @@ -145,12 +145,12 @@ static int re_alloc(struct re **rep)
if (!re)
return ENOMEM;

err = mtx_init(&re->mutex, mtx_plain);
err = mtx_alloc(&re->mutex);
if (err) {
DEBUG_WARNING("thread_init: mtx_init error\n");
goto out;
}
re->mutexp = &re->mutex;
re->mutexp = re->mutex;

list_init(&re->tmrl);
re->tid = thrd_current();
Expand Down Expand Up @@ -1285,8 +1285,6 @@ void re_thread_close(void)

/**
* Enter an 're' thread
*
* @note Must only be called from a non-re thread
*/
void re_thread_enter(void)
{
Expand All @@ -1298,14 +1296,15 @@ void re_thread_enter(void)
}

re_lock(re);
re->thread_enter = true;

/* set only for non-re threads */
if (!thrd_equal(re->tid, thrd_current()))
re->thread_enter = true;
}


/**
* Leave an 're' thread
*
* @note Must only be called from a non-re thread
*/
void re_thread_leave(void)
{
Expand Down Expand Up @@ -1335,7 +1334,7 @@ void re_set_mutex(void *mutexp)
return;
}

re->mutexp = mutexp ? mutexp : &re->mutex;
re->mutexp = mutexp ? mutexp : re->mutex;
}


Expand Down

0 comments on commit c503223

Please sign in to comment.