Skip to content

Commit

Permalink
Merge pull request #88 from alessandropellegrini/hotfix-msgchannel-1r…
Browse files Browse the repository at this point in the history
…eader

Transition from (M,N) to (M,1) msg channel
  • Loading branch information
alessandropellegrini authored Feb 1, 2018
2 parents ffb90cb + 5dc66ea commit 9293c5a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
10 changes: 2 additions & 8 deletions src/datatypes/msgchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* ROOT-Sim; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @file bh.c
* @brief
* @file msgchannel.c
* @brief This module implements an (M, 1) channel to transfer message pointers.
* @author Francesco Quaglia
*/

Expand Down Expand Up @@ -80,7 +80,6 @@ msg_channel *init_channel(void) {
if(mc->buffers[M_READ]->buffer == NULL || mc->buffers[M_WRITE]->buffer == NULL)
rootsim_error(true, "%s:%d: Unable to allocate message channel\n", __FILE__, __LINE__);

spinlock_init(&mc->read_lock);
spinlock_init(&mc->write_lock);

return mc;
Expand All @@ -94,15 +93,13 @@ void insert_msg(msg_channel *mc, msg_t *msg) {
// Reallocate the live BH buffer. Don't touch the other buffer,
// as in this way the critical section is much shorter
if(mc->buffers[M_WRITE]->written == mc->buffers[M_WRITE]->size) {
spin_lock(&mc->read_lock);

mc->buffers[M_WRITE]->size *= 2;
mc->buffers[M_WRITE]->buffer = rsrealloc((void *)mc->buffers[M_WRITE]->buffer, mc->buffers[M_WRITE]->size * sizeof(msg_t *));

if(mc->buffers[M_WRITE]->buffer == NULL)
rootsim_error(true, "%s:%d: Unable to reallocate message channel\n", __FILE__, __LINE__);

spin_unlock(&mc->read_lock);
}

#ifndef NDEBUG
Expand All @@ -118,8 +115,6 @@ void insert_msg(msg_channel *mc, msg_t *msg) {
void *get_msg(msg_channel *mc) {
msg_t *msg = NULL;

spin_lock(&mc->read_lock);

if(mc->buffers[M_READ]->read == mc->buffers[M_READ]->written) {
spin_lock(&mc->write_lock);
switch_channel_buffers(mc);
Expand All @@ -140,7 +135,6 @@ void *get_msg(msg_channel *mc) {
#endif

leave:
spin_unlock(&mc->read_lock);
return msg;
}

3 changes: 1 addition & 2 deletions src/datatypes/msgchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @file msgchannel.h
* @brief This module implements an (M, N) channel to transfer message pointers.
* @brief This module implements an (M, 1) channel to transfer message pointers.
* @author Francesco Quaglia
* @author Alessandro Pellegrini
*/
Expand All @@ -39,7 +39,6 @@ struct _msg_buff {
typedef struct _msg_channel {
struct _msg_buff *volatile buffers[2];
atomic_t size;
spinlock_t read_lock;
spinlock_t write_lock;
} msg_channel;

Expand Down

0 comments on commit 9293c5a

Please sign in to comment.