Merge from develop
Merge from develop
This commit is contained in:
@ -29,23 +29,32 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of an atomic add operation for the X86 processor.
|
||||
* Implementation of an atomic add operation for the GCC environment, or the
|
||||
* X86 processor. If we are working within GNU C then we can use the GCC
|
||||
* atomic add built in function, which is portable across platforms that
|
||||
* implement GCC. Otherwise, this function currently supports only X86
|
||||
* architecture (without further development).
|
||||
*
|
||||
* Adds a value to the contents of a location pointed to by the first parameter.
|
||||
* The add operation is atomic and the return value is the value stored in the location
|
||||
* prior to the operation. The number that is added may be signed, therefore atomic_subtract
|
||||
* is merely an atomic add with a negative value.
|
||||
* The add operation is atomic and the return value is the value stored in the
|
||||
* location prior to the operation. The number that is added may be signed,
|
||||
* therefore atomic_subtract is merely an atomic add with a negative value.
|
||||
*
|
||||
* @param variable Pointer the the variable to add to
|
||||
* @param value Value to be added
|
||||
* @return Pointer to the value of variable before the add occured
|
||||
* @return The value of variable before the add occurred
|
||||
*/
|
||||
int
|
||||
atomic_add(int *variable, int value)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
return (int) __sync_fetch_and_add (variable, value);
|
||||
#else
|
||||
asm volatile(
|
||||
"lock; xaddl %%eax, %2;"
|
||||
:"=a" (value)
|
||||
: "a" (value), "m" (*variable)
|
||||
: "memory" );
|
||||
return value;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ SERVER *server;
|
||||
server = allServers;
|
||||
while (server)
|
||||
{
|
||||
if (strcmp(server->unique_name, name) == 0)
|
||||
if (server->unique_name && strcmp(server->unique_name, name) == 0)
|
||||
break;
|
||||
server = server->next;
|
||||
}
|
||||
|
||||
@ -63,13 +63,14 @@ char *status;
|
||||
ss_info_dassert(server == server_find_by_unique_name("uniquename"), "Should find by unique name.");
|
||||
ss_dfprintf(stderr, "\t..done\nTesting Status Setting for Server.");
|
||||
status = server_status(server);
|
||||
ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down prior to being set.");
|
||||
ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running by default.");
|
||||
if (NULL != status) free(status);
|
||||
server_set_status(server, SERVER_MASTER);
|
||||
status = server_status(server);
|
||||
ss_info_dassert(0 == strcmp("Master, Down", status), "Should find correct status.");
|
||||
ss_info_dassert(0 == strcmp("Master, Running", status), "Should find correct status.");
|
||||
server_clear_status(server, SERVER_MASTER);
|
||||
ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down after status cleared.");
|
||||
status = server_status(server);
|
||||
ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running after master status cleared.");
|
||||
if (NULL != status) free(status);
|
||||
ss_dfprintf(stderr, "\t..done\nRun Prints for Server and all Servers.");
|
||||
printServer(server);
|
||||
|
||||
@ -41,7 +41,8 @@
|
||||
static int
|
||||
test1()
|
||||
{
|
||||
USERS *users;
|
||||
USERS *users;
|
||||
char *authdata;
|
||||
int result, count;
|
||||
|
||||
/* Poll tests */
|
||||
@ -52,13 +53,17 @@ int result, count;
|
||||
ss_dfprintf(stderr, "\t..done\nAdd a user");
|
||||
count = users_add(users, "username", "authorisation");
|
||||
ss_info_dassert(1 == count, "Should add one user");
|
||||
ss_info_dassert(strcmp("authorisation", users_fetch(users, "username")), "User authorisation should be correct");
|
||||
authdata = users_fetch(users, "username");
|
||||
ss_info_dassert(NULL != authdata, "Fetch valid user must not return NULL");
|
||||
ss_info_dassert(0 == strcmp("authorisation", authdata), "User authorisation should be correct");
|
||||
ss_dfprintf(stderr, "\t..done\nPrint users");
|
||||
usersPrint(users);
|
||||
ss_dfprintf(stderr, "\t..done\nUpdate a user");
|
||||
count = users_update(users, "username", "newauth");
|
||||
ss_info_dassert(1 == count, "Should update just one user");
|
||||
ss_info_dassert(strcmp("newauth", users_fetch(users, "username")), "User authorisation should be correctly updated");
|
||||
authdata = users_fetch(users, "username");
|
||||
ss_info_dassert(NULL != authdata, "Fetch valid user must not return NULL");
|
||||
ss_info_dassert(0 == strcmp("newauth", authdata), "User authorisation should be correctly updated");
|
||||
ss_dfprintf(stderr, "\t..done\nDelete a user.");
|
||||
count = users_delete(users, "username");
|
||||
ss_info_dassert(1 == count, "Should delete just one user");
|
||||
|
||||
Reference in New Issue
Block a user