0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-26 23:01:04 +08:00

Problem: 'bool' is not defined by default

zmq_atomic_counter_dec returned a 'bool' value, yet this isn't
defined by standard, so causes compile errors in upstream code.

Solution: return an int that can be safely converted to bool if
needed by bindings.
This commit is contained in:
Pieter Hintjens 2014-12-23 15:20:10 +01:00
parent ae53b27b70
commit 04664f0ef7
9 changed files with 49 additions and 42 deletions

View File

@ -9,7 +9,7 @@ zmq_atomic_counter_dec - decrement an atomic counter
SYNOPSIS
--------
*bool zmq_atomic_counter_dec (void *counter);*
*int zmq_atomic_counter_dec (void *counter);*
DESCRIPTION
@ -21,8 +21,8 @@ operations.
RETURN VALUE
------------
The _zmq_atomic_counter_dec()_ function returns true if the counter is
greater than zero after decrementing, or false if the counter reached
The _zmq_atomic_counter_dec()_ function returns 1 if the counter is
greater than zero after decrementing, or zero if the counter reached
zero.
@ -36,13 +36,14 @@ assert (zmq_atomic_counter_inc (counter) == 0);
assert (zmq_atomic_counter_inc (counter) == 1);
assert (zmq_atomic_counter_inc (counter) == 2);
assert (zmq_atomic_counter_value (counter) == 3);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_set (counter, 2);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_destroy (&counter);
return 0;
----

View File

@ -36,13 +36,14 @@ assert (zmq_atomic_counter_inc (counter) == 0);
assert (zmq_atomic_counter_inc (counter) == 1);
assert (zmq_atomic_counter_inc (counter) == 2);
assert (zmq_atomic_counter_value (counter) == 3);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_set (counter, 2);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_destroy (&counter);
return 0;
----

View File

@ -35,13 +35,14 @@ assert (zmq_atomic_counter_inc (counter) == 0);
assert (zmq_atomic_counter_inc (counter) == 1);
assert (zmq_atomic_counter_inc (counter) == 2);
assert (zmq_atomic_counter_value (counter) == 3);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_set (counter, 2);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_destroy (&counter);
return 0;
----

View File

@ -36,13 +36,14 @@ assert (zmq_atomic_counter_inc (counter) == 0);
assert (zmq_atomic_counter_inc (counter) == 1);
assert (zmq_atomic_counter_inc (counter) == 2);
assert (zmq_atomic_counter_value (counter) == 3);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_set (counter, 2);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_destroy (&counter);
return 0;
----

View File

@ -35,13 +35,14 @@ assert (zmq_atomic_counter_inc (counter) == 0);
assert (zmq_atomic_counter_inc (counter) == 1);
assert (zmq_atomic_counter_inc (counter) == 2);
assert (zmq_atomic_counter_value (counter) == 3);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_set (counter, 2);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_destroy (&counter);
return 0;
----

View File

@ -34,13 +34,14 @@ assert (zmq_atomic_counter_inc (counter) == 0);
assert (zmq_atomic_counter_inc (counter) == 1);
assert (zmq_atomic_counter_inc (counter) == 2);
assert (zmq_atomic_counter_value (counter) == 3);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_set (counter, 2);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_destroy (&counter);
return 0;
----

View File

@ -440,7 +440,7 @@ ZMQ_EXPORT int zmq_curve_keypair (char *z85_public_key, char *z85_secret_key);
ZMQ_EXPORT void *zmq_atomic_counter_new (void);
ZMQ_EXPORT void zmq_atomic_counter_set (void *counter, int value);
ZMQ_EXPORT int zmq_atomic_counter_inc (void *counter);
ZMQ_EXPORT bool zmq_atomic_counter_dec (void *counter);
ZMQ_EXPORT int zmq_atomic_counter_dec (void *counter);
ZMQ_EXPORT int zmq_atomic_counter_value (void *counter);
ZMQ_EXPORT void zmq_atomic_counter_destroy (void **counter_p);

View File

@ -232,11 +232,12 @@ int zmq_atomic_counter_inc (void *counter_)
return ((zmq::atomic_counter_t *) counter_)->add (1);
}
// Decrement the atomic counter and return true if still > zero
// Decrement the atomic counter and return 1 (if counter >= 1), or
// 0 if counter hit zero.
bool zmq_atomic_counter_dec (void *counter_)
int zmq_atomic_counter_dec (void *counter_)
{
return ((zmq::atomic_counter_t *) counter_)->sub (1);
return ((zmq::atomic_counter_t *) counter_)->sub (1)? 1: 0;
}
// Return actual value of atomic counter

View File

@ -27,12 +27,12 @@ int main (void)
assert (zmq_atomic_counter_inc (counter) == 1);
assert (zmq_atomic_counter_inc (counter) == 2);
assert (zmq_atomic_counter_value (counter) == 3);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_set (counter, 2);
assert (zmq_atomic_counter_dec (counter) == true);
assert (zmq_atomic_counter_dec (counter) == false);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_destroy (&counter);
return 0;
}