Skip to content

Commit

Permalink
Add mosquitto_threaded_set().
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Jul 2, 2014
1 parent 0fb064e commit 5c7512b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Client library:
- Fix compilation for WITH_THREADING=no.
- Break out of select() when calling mosquitto_loop_stop().
- Reject invalid un/subscriptions e.g. foo/+bar #/bar.
- Add mosquitto_threaded_set().

Clients:
- Fix keepalive value on mosquitto_pub.
Expand Down
5 changes: 5 additions & 0 deletions lib/cpp/mosquittopp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ bool mosquittopp::want_write()
return mosquitto_want_write(m_mosq);
}

int mosquittopp::threaded_set(bool threaded)
{
return mosquitto_threaded_set(m_mosq, threaded);
}

void mosquittopp::user_data_set(void *userdata)
{
mosquitto_user_data_set(m_mosq, userdata);
Expand Down
1 change: 1 addition & 0 deletions lib/cpp/mosquittopp.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class mosqpp_EXPORT mosquittopp {
int loop_start();
int loop_stop(bool force=false);
bool want_write();
int threaded_set(bool threaded=true);

virtual void on_connect(int rc) {return;};
virtual void on_disconnect(int rc) {return;};
Expand Down
5 changes: 5 additions & 0 deletions lib/linker.version
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ MOSQ_1.3 {
global:
mosquitto_connect_srv;
} MOSQ_1.2;

MOSQ_1.4 {
global:
mosquitto_threaded_set;
} MOSQ_1.3;
17 changes: 17 additions & 0 deletions lib/mosquitto.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,23 @@ libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq);
*/
libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq);

/*
* Function: mosquitto_threaded_set
*
* Used to tell the library that your application is using threads, but not
* using <mosquitto_loop_start>. The library operates slightly differently when
* not in threaded mode in order to simplify its operation. If you are managing
* your own threads and do not use this function you will experience crashes
* due to race conditions.
*
* When using <mosquitto_loop_start>, this is set automatically.
*
* Parameters:
* mosq - a valid mosquitto instance.
* threaded - true if your application is using threads, false otherwise.
*/
libmosq_EXPORT int mosquitto_threaded_set(struct mosquitto *mosq, bool threaded);

/*
* Function: mosquitto_tls_set
*
Expand Down
8 changes: 8 additions & 0 deletions lib/thread_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ void *_mosquitto_thread_main(void *obj)
}
#endif

int mosquitto_threaded_set(struct mosquitto *mosq, bool threaded)
{
if(!mosq) return MOSQ_ERR_INVAL;

mosq->threaded = threaded;

return MOSQ_ERR_SUCCESS;
}

0 comments on commit 5c7512b

Please sign in to comment.