Changeset 105 in libcf
- Timestamp:
- 05/29/13 14:10:04 (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cf_base.h
r82 r105 5 5 * 6 6 * @remarks 기본 정의 7 *8 * @example test.c9 7 * 10 8 * @mainpage -
trunk/test/log.c
r103 r105 4 4 */ 5 5 #include "cf_log.h" 6 #include "cf_thread.h" 7 #include "cf_debug.h" 8 6 9 #include <stdio.h> 10 11 CF_Mutex globalMutex; 12 13 #define LOG_MT 1 14 15 int test_log_mt (void * arg) 16 { 17 static int cnt = 0; 18 int i = 0; 19 int th = 0; 20 21 if (CF_Mutex_Lock (&globalMutex) < 0) { // for critical section 22 // error 23 } 24 th = cnt++; 25 if (CF_Mutex_Unlock (&globalMutex) < 0) { // for critical section 26 // error 27 } 28 29 CF_DEBUG_PRINT (stderr, "created %dth thread\n", th); 30 31 for (i = 0 ; i < 100000 ; i++) 32 { 33 CF_Log_Write (LOG_MT, "LOG_MT", "[%d] multi-threadedlogging test %d\n", th, i); 34 } 35 36 CF_DEBUG_PRINT (stderr, "end %dth thread\n", th); 37 38 return 0; 39 } 7 40 8 41 int main (void) 9 42 { 10 43 int i, j; 11 char logname[16] = {0x00,}; 44 char idname[16] = {0x00,}; 45 CF_Thread tid[10]; 12 46 13 if (CF_Log_Initialize (10, CF_LOG_NO_LEVEL) < 0) 47 /* initialize */ 48 if (CF_Log_Initialize (10, 2) < 0) 14 49 { 15 50 fprintf (stderr, "failed to init. log\n"); … … 19 54 for (i = 0 ; i < 10 ; i++) 20 55 { 21 sprintf ( logname, "logid%d.txt", i);22 if (CF_Log_Open (i, logname, CF_LOG_NO_BUFFER) < 0)56 sprintf (idname, "logid%d.txt", i); 57 if (CF_Log_Open (i, idname, CF_LOG_NO_BUFFER) < 0) 23 58 fprintf (stderr, "failed to open log\n"); 24 59 } … … 37 72 } 38 73 74 /* mt {{{ */ 75 if (CF_Log_Open (LOG_MT, "log_mt.txt", CF_LOG_DEFAULT_BUFFER) < 0) 76 CF_DEBUG_PRINT (stderr, "create log ctx error\n"); 77 78 if (CF_Log_SetMT (LOG_MT, CF_TRUE) < 0) 79 CF_DEBUG_PRINT (stderr, "set multi-threading mode error\n"); 80 81 if (CF_Mutex_Create (&globalMutex) < 0) { 82 // error 83 } 84 85 for (i = 0 ; i < 10 ; i++) 86 { 87 if (CF_Thread_Create (&tid[i], test_log_mt, &i) < 0) 88 { 89 CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", i); 90 return -2; 91 } 92 } 93 94 for (i = 0 ; i < 10 ; i++) 95 { 96 if (CF_Thread_Join (&tid[i]) < 0) 97 CF_DEBUG_PRINT (stderr, "failed to join %dth thread\n", i); 98 if (CF_Thread_Release (&tid[i]) < 0) 99 CF_DEBUG_PRINT (stderr, "failed to release %dth thread\n", i); 100 } 101 102 if (CF_Mutex_Destory (&globalMutex) < 0) { 103 // error 104 } 105 /* }}} mt */ 106 107 /* finalize */ 39 108 CF_Log_Finalize (); 40 109 -
trunk/test/makefile
r84 r105 8 8 # env 9 9 #---------------------------------------------------------- 10 FILES = \11 test \12 13 TARGET_NAME = test14 15 10 TARGET_PATH = ../_build 16 11 OBJ_PATH = ../_obj 17 TARGET = $(TARGET_PATH)/$(TARGET_NAME).$(EXT_EXECUTE)18 SRCS = $(addsuffix .$(SOURCE_TYPE),$(FILES))19 OBJS = $(addprefix $(OBJ_PATH)/,$(addsuffix .o,$(FILES)))20 12 21 13 INCLUDES = -I../include … … 27 19 # label 28 20 #---------------------------------------------------------- 29 all: dep $(TARGET)21 all: dep 30 22 @echo ========== Complete CHEROXY compilation ========== 31 23 dep: $(OBJ_PATH) $(TARGET_PATH) $(LIB_CF) … … 37 29 $(LIB_CF): dummy 38 30 cd ../src; make all; 31 32 test: 33 make $(shell ls *.c | awk -F. '{ print $$1 }') 39 34 40 35 %: %.c -
trunk/windows/test/test.vcproj
r14 r105 174 174 > 175 175 <File 176 RelativePath="..\..\test\test.c" 176 RelativePath="..\..\test\codec.c" 177 > 178 </File> 179 <File 180 RelativePath="..\..\test\debug.c" 181 > 182 </File> 183 <File 184 RelativePath="..\..\test\file.c" 185 > 186 </File> 187 <File 188 RelativePath="..\..\test\log.c" 189 > 190 </File> 191 <File 192 RelativePath="..\..\test\socket.c" 193 > 194 </File> 195 <File 196 RelativePath="..\..\test\thread.c" 177 197 > 178 198 </File>
Note:
See TracChangeset
for help on using the changeset viewer.