[Spread-cvs] commit: r486 - in libspreadutil/trunk: . include src
jonathan at spread.org
jonathan at spread.org
Mon Mar 5 17:48:30 EST 2012
Author: jonathan
Date: 2012-03-05 17:48:30 -0500 (Mon, 05 Mar 2012)
New Revision: 486
Modified:
libspreadutil/trunk/Changelog
libspreadutil/trunk/include/spu_memory.h
libspreadutil/trunk/src/events.c
libspreadutil/trunk/src/memory.c
Log:
Add obj_name field to Mem_init_object() function. This is API change.
Modified: libspreadutil/trunk/Changelog
===================================================================
--- libspreadutil/trunk/Changelog 2012-03-05 21:15:49 UTC (rev 485)
+++ libspreadutil/trunk/Changelog 2012-03-05 22:48:30 UTC (rev 486)
@@ -1,3 +1,9 @@
+Mon Mar 5 17:21:14 2012 Jonathan Stanton <jonathan at spreadconcepts.com>
+
+ * src/memory.c (Mem_init_object): Add "obj_name" field to Mem_init_object() to provide a
+ nice name to print in error messages. This replaces the hard-coded string names in
+ Objnum_to_String(). This is a API change.
+
March 04, 2012
--------------
Complete changes to add new independant configure based build system for the library, with support for windows and autoconf systems.
Modified: libspreadutil/trunk/include/spu_memory.h
===================================================================
--- libspreadutil/trunk/include/spu_memory.h 2012-03-05 21:15:49 UTC (rev 485)
+++ libspreadutil/trunk/include/spu_memory.h 2012-03-05 22:48:30 UTC (rev 486)
@@ -50,17 +50,17 @@
* Function Declarations
************************************/
-/* Input: valid object type, size of object, threshold/watermark value for this object,
+/* Input: valid object type, name of object, size of object, threshold/watermark value for this object,
* number of initial objects to create
* Output: error code
* Effects: registers type, sets watermark for type,creates initial memory buffers and updates global vars
* Should ONLY be called once per execution of the program, but must be called before any other
* memory management function is used on that object
*/
-int Mem_init_object(int32u obj_type, int32u size, unsigned int threshold, unsigned int initial);
+int Mem_init_object(int32u obj_type, char *obj_name, int32u size, unsigned int threshold, unsigned int initial);
/* This calls Mem_init_object and if any error results it EXIT's with a printed error */
-void Mem_init_object_abort( int32u obj_type, int32u size, unsigned int threshold, unsigned int initial );
+void Mem_init_object_abort( int32u obj_type, char *obj_name, int32u size, unsigned int threshold, unsigned int initial );
/* This initializes the status reporting of the memory module and should be called from
* status.c after the Group, Recod, and RefRecord objects are mem_init'ed.
Modified: libspreadutil/trunk/src/events.c
===================================================================
--- libspreadutil/trunk/src/events.c 2012-03-05 21:15:49 UTC (rev 485)
+++ libspreadutil/trunk/src/events.c 2012-03-05 22:48:30 UTC (rev 486)
@@ -127,7 +127,7 @@
Time_queue = NULL;
- ret = Mem_init_object(TIME_EVENT, sizeof(time_event), 100,0);
+ ret = Mem_init_object(TIME_EVENT, "time_event", sizeof(time_event), 100,0);
if (ret < 0)
{
Alarm(EXIT, "E_Init: Failure to Initialize TIME_EVENT memory objects\n");
Modified: libspreadutil/trunk/src/memory.c
===================================================================
--- libspreadutil/trunk/src/memory.c 2012-03-05 21:15:49 UTC (rev 485)
+++ libspreadutil/trunk/src/memory.c 2012-03-05 22:48:30 UTC (rev 486)
@@ -84,6 +84,10 @@
size_t block_len;
} mem_header;
+#define MAX_OBJNAME 35
+#define DEFAULT_OBJNAME "Unknown Obj"
+
+
/* NOTE: Only num_obj_inpool is updated when debugging is turned off
* (i.e. define NDEBUG) it is NECESSARY to track buffer pool size
*/
@@ -92,6 +96,7 @@
bool exist; /* 1 = object registered, 0 = unused object number */
size_t size; /* size of object in bytes (should be from sizeof so aligned ) */
unsigned int threshold;
+ char obj_name[MAX_OBJNAME + 1]; /* Name of the object */
#ifndef NDEBUG
unsigned int bytes_allocated;
unsigned int max_bytes;
@@ -266,23 +271,21 @@
return;
#endif
}
-void Mem_init_object_abort( int32u obj_type, int32u size, unsigned int threshold, unsigned int initial )
+void Mem_init_object_abort( int32u obj_type, char *obj_name, int32u size, unsigned int threshold, unsigned int initial )
{
- char *obj_name;
int ret;
- ret = Mem_init_object( obj_type, size, threshold, initial );
+ ret = Mem_init_object( obj_type, obj_name, size, threshold, initial );
if (ret < 0 ) {
- obj_name = Objnum_to_String( obj_type );
Alarm( EXIT, "Mem_init_object_abort: Failed to initialize a/an %s object\n", obj_name);
}
}
-/* Input: valid object type, threshold/watermark value for this object, initial objects to create
+/* Input: valid object type, name of object, threshold/watermark value for this object, initial objects to create
* Output: none
* Effects: sets watermark for type,creates initial memory buffers and updates global vars
* Should ONLY be called once per execution of the program
*/
-int Mem_init_object(int32u obj_type, int32u size, unsigned int threshold, unsigned int initial)
+int Mem_init_object(int32u obj_type, char *obj_name, int32u size, unsigned int threshold, unsigned int initial)
{
int mem_error = 0;
#ifdef SPREAD_STATUS
@@ -321,6 +324,14 @@
Mem[obj_type].exist = TRUE;
Mem[obj_type].size = size;
Mem[obj_type].threshold = threshold;
+
+ if (obj_name == NULL || strlen(obj_name) > MAX_OBJNAME) {
+ strncpy(Mem[obj_type].obj_name, DEFAULT_OBJNAME, MAX_OBJNAME);
+ } else {
+ strncpy(Mem[obj_type].obj_name, obj_name, MAX_OBJNAME);
+ }
+ Mem[obj_type].obj_name[MAX_OBJNAME] = '\0';
+
/* Only enabled when MEM_DISABLE_CACHE set. Disable threshold so all memory is dellocated at dispose() */
#ifdef MEM_DISABLE_CACHE
Mem[obj_type].threshold = 0;
@@ -823,100 +834,12 @@
char *Objnum_to_String(int32u oid)
{
+ if (Mem[oid].exist) {
+ return(Mem[oid].obj_name);
+ } else {
+ return("NO SUCH OBJECT");
+ }
-#if ( SPREAD_PROTOCOL == 3 )
-
- switch(oid)
- {
- case BASE_OBJ:
- return("base_obj");
- case PACK_HEAD_OBJ:
- return("pack_head_obj");
- case MESSAGE_OBJ:
- return("message_obj");
- case MSG_FRAG_OBJ:
- return("msg_frag_obj");
- case RET_REQ_OBJ:
- return("ret_req_obj");
- case LINK_ACK_OBJ:
- return("link_ack_obj");
- case ARU_UPDATE_OBJ:
- return("aru_update_obj");
- case TOKEN_HEAD_OBJ:
- return("token_head_obj");
- case TOKEN_BODY_OBJ:
- return("token_body_obj");
- case JOIN_OBJ:
- return("join_obj");
- case REFER_OBJ:
- return("refer_obj");
- case ALIVE_OBJ:
- return("alive_obj");
- case SCATTER:
- return("scatter");
- case QUEUE_ELEMENT:
- return("queue_element");
- case QUEUE:
- return("queue");
- case RETRANS_ENTRY:
- return("retrans_entry");
- case RING_LINK_OBJ:
- return("ring_link_obj");
- case HOP_LINK_OBJ:
- return("hop_link_obj");
- case MESSAGE_LINK:
- return("message_link");
- case DOWN_LINK:
- return("down_link");
- case TREE_NODE:
- return("tree_node");
- case MESSAGE_FRAG_LIST:
- return("message_frag_list");
- case LBUCKET:
- return("leaky_bucket");
- case GROUP:
- return("group");
- case MEMBER:
- return("member");
- case MSG_LIST_ENTRY:
- return("msg_list_entry");
- case SESS_SEQ_ENTRY:
- return("sess_seq_entry");
- case TIME_EVENT:
- return("time_event");
- case ROUTE_WEIGHTS:
- return("route_weights");
- case PROF_FUNCT:
- return("prof_funct");
- case QUEUE_SET:
- return("queue_set");
- case MQUEUE_ELEMENT:
- return("mqueue_element");
- case TCP_LINK_OBJ:
- return("tcp_link_object");
- case MESSAGE_META_OBJ:
- return("message_meta_object");
- case PROC_RECORD:
- return("proc_info");
- case SYS_SCATTER:
- return("sys_scatter");
- case STAT_RECORD:
- return("status_record");
- case STAT_GROUP:
- return("status_group");
- case STAT_REFRECORD:
- return("status_refrecord");
- case STATETRANS_OBJ:
- return("statetrans_obj");
- case PACKET_BODY:
- return("packet_body");
- case SESSION_AUTH_INFO:
- return("session_auth_info");
- default:
- return("Unknown_obj");
- }
-#endif
- return("Unknown_obj");
}
More information about the Spread-cvs
mailing list