add macro PTHREAD_MUTEX_LOCK
parent
7149a54128
commit
b9cae5de7f
|
|
@ -1344,9 +1344,6 @@ static inline int checkInitDynamicContentArray()
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
logInfo("file: "__FILE__", line: %d, func: %s, "
|
||||
"init_pthread_lock", __LINE__, __FUNCTION__);
|
||||
return init_pthread_lock(&g_dynamic_content_array.lock);
|
||||
}
|
||||
|
||||
|
|
@ -1380,9 +1377,6 @@ static int checkAllocDynamicContentArray()
|
|||
free(g_dynamic_content_array.contents);
|
||||
}
|
||||
|
||||
logInfo("file: "__FILE__", line: %d, func: %s, "
|
||||
"alloc count: %d", __LINE__, __FUNCTION__, alloc);
|
||||
|
||||
g_dynamic_content_array.contents = contents;
|
||||
g_dynamic_content_array.alloc = alloc;
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,32 @@ extern "C" {
|
|||
int init_pthread_lock(pthread_mutex_t *pthread_lock);
|
||||
int init_pthread_attr(pthread_attr_t *pattr, const int stack_size);
|
||||
|
||||
#define PTHREAD_MUTEX_LOCK(lock) \
|
||||
do { \
|
||||
int lock_res; \
|
||||
if ((lock_res=pthread_mutex_lock(lock)) != 0) \
|
||||
{ \
|
||||
logWarning("file: "__FILE__", line: %d, " \
|
||||
"call pthread_mutex_lock fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, lock_res, STRERROR(lock_res)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define PTHREAD_MUTEX_UNLOCK(lock) \
|
||||
do { \
|
||||
int unlock_res; \
|
||||
if ((unlock_res=pthread_mutex_unlock(lock)) != 0) \
|
||||
{ \
|
||||
logWarning("file: "__FILE__", line: %d, " \
|
||||
"call pthread_mutex_unlock fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, unlock_res, STRERROR(unlock_res)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
int create_work_threads(int *count, void *(*start_func)(void *),
|
||||
void **args, pthread_t *tids, const int stack_size);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,11 @@ int main(int argc, char *argv[])
|
|||
"%"PRId64" ms\n", int_to_comma_str(LOOP_COUNT, time_buff),
|
||||
sum, get_current_time_ms() - start_time);
|
||||
|
||||
printf("lock 1: %d\n", pthread_mutex_lock(&lock));
|
||||
printf("lock 2: %d\n", pthread_mutex_lock(&lock));
|
||||
printf("unlock 1: %d\n", pthread_mutex_unlock(&lock));
|
||||
printf("unlock 2: %d\n", pthread_mutex_unlock(&lock));
|
||||
|
||||
start_time = get_current_time_ms();
|
||||
sum = 0;
|
||||
for (k=1; k<=LOOP_COUNT; k++) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue