Skip to content

Commit

Permalink
归整了代码格式
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengshuxin committed Feb 16, 2014
1 parent 5796deb commit e2bbbac
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 412 deletions.
38 changes: 21 additions & 17 deletions lib_acl/include/thread/acl_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,46 +117,49 @@ struct acl_pthread_condattr_t {
struct timespec {
time_t tv_sec; /* Seconds. */
long int tv_nsec; /* Nanoseconds. */
#if 0
long int tv_msec; /* millisecond, add by zsx */
#endif
};

/* in acl_pthread.c */
ACL_API void acl_pthread_end(void);
ACL_API int acl_pthread_once(acl_pthread_once_t *once_control, void (*init_routine)(void));
ACL_API int acl_pthread_key_create(acl_pthread_key_t *key_ptr, void (*destructor)(void*));
ACL_API int acl_pthread_once(acl_pthread_once_t *once_control,
void (*init_routine)(void));
ACL_API int acl_pthread_key_create(acl_pthread_key_t *key_ptr,
void (*destructor)(void*));
ACL_API void *acl_pthread_getspecific(acl_pthread_key_t key);
ACL_API int acl_pthread_setspecific(acl_pthread_key_t key, void *value);
ACL_API int acl_pthread_attr_init(acl_pthread_attr_t *attr);
ACL_API int acl_pthread_attr_setstacksize(acl_pthread_attr_t *attr, size_t stacksize);
ACL_API int acl_pthread_attr_setdetachstate(acl_pthread_attr_t *attr, int detached);
ACL_API int acl_pthread_attr_setstacksize(acl_pthread_attr_t *attr,
size_t stacksize);
ACL_API int acl_pthread_attr_setdetachstate(acl_pthread_attr_t *attr,
int detached);
ACL_API int acl_pthread_attr_destroy(acl_pthread_attr_t *thr_attr);
ACL_API unsigned long acl_pthread_self(void);
ACL_API int acl_pthread_create(acl_pthread_t *thread,
acl_pthread_attr_t *attr,
void * (*start_routine)(void *),
void *arg);
ACL_API int acl_pthread_create(acl_pthread_t *thread,
acl_pthread_attr_t *attr, void * (*start_routine)(void *),
void *arg);
ACL_API int acl_pthread_detach(acl_pthread_t thread);
ACL_API int acl_pthread_join(acl_pthread_t thread, void **thread_return);

/* in acl_pthread_mutex.c */
ACL_API int acl_pthread_mutex_destroy(acl_pthread_mutex_t *mutex);
ACL_API int acl_pthread_mutex_init(acl_pthread_mutex_t *mutex, const acl_pthread_mutexattr_t *mattr);
ACL_API int acl_pthread_mutex_init(acl_pthread_mutex_t *mutex,
const acl_pthread_mutexattr_t *mattr);
ACL_API int acl_pthread_mutex_lock(acl_pthread_mutex_t *mutex);
ACL_API int acl_pthread_mutex_unlock(acl_pthread_mutex_t *mutex);

#define acl_pthread_mutex_trylock acl_pthread_mutex_lock

/* in acl_pthread_cond.c */
ACL_API int acl_pthread_cond_init(acl_pthread_cond_t *cond, acl_pthread_condattr_t *cond_attr);
ACL_API int acl_pthread_cond_init(acl_pthread_cond_t *cond,
acl_pthread_condattr_t *cond_attr);
ACL_API acl_pthread_cond_t * acl_pthread_cond_create(void);
ACL_API int acl_pthread_cond_destroy(acl_pthread_cond_t *cond);
ACL_API int acl_pthread_cond_signal(acl_pthread_cond_t *cond);
ACL_API int acl_pthread_cond_broadcast(acl_pthread_cond_t *cond);
ACL_API int acl_pthread_cond_timedwait(acl_pthread_cond_t *cond, acl_pthread_mutex_t *mutex,
const struct timespec *timeout);
ACL_API int acl_pthread_cond_wait(acl_pthread_cond_t *cond, acl_pthread_mutex_t *mutex);
ACL_API int acl_pthread_cond_timedwait(acl_pthread_cond_t *cond,
acl_pthread_mutex_t *mutex, const struct timespec *timeout);
ACL_API int acl_pthread_cond_wait(acl_pthread_cond_t *cond,
acl_pthread_mutex_t *mutex);

#endif /* !ACL_HAS_PTHREAD */

Expand All @@ -176,7 +179,8 @@ ACL_API int acl_pthread_atexit_remove(void *arg, void (*free_callback)(void*));
ACL_API int acl_pthread_tls_set_max(int max);
ACL_API int acl_pthread_tls_get_max(void);
ACL_API void *acl_pthread_tls_get(acl_pthread_key_t *key_ptr);
ACL_API int acl_pthread_tls_set(acl_pthread_key_t key, void *ptr, void (*free_fn)(void *));
ACL_API int acl_pthread_tls_set(acl_pthread_key_t key, void *ptr,
void (*free_fn)(void *));
ACL_API int acl_pthread_tls_del(acl_pthread_key_t key);
ACL_API void acl_pthread_tls_once_get(acl_pthread_once_t *control_once);
ACL_API void acl_pthread_tls_once_set(acl_pthread_once_t control_once);
Expand Down
18 changes: 12 additions & 6 deletions lib_acl/include/thread/acl_pthread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ typedef struct acl_pthread_pool_attr_t {
* @param idle_timeout {int} 工作线程空闲超时退出时间(秒)
* @return {acl_pthread_pool_t*}, 如果不为空则表示成功,否则失败
*/
ACL_API acl_pthread_pool_t *acl_thread_pool_create(int threads_limit, int idle_timeout);
ACL_API acl_pthread_pool_t *acl_thread_pool_create(
int threads_limit, int idle_timeout);

/**
* 创建一个线程池对象
* @param attr {acl_pthread_pool_attr_t*} 线程池创建时的属性,如果该参数为空,
* 则采用默认参数: ACL_PTHREAD_POOL_DEF_XXX
* @return {acl_pthread_pool_t*}, 如果不为空则表示成功,否则失败
*/
ACL_API acl_pthread_pool_t *acl_pthread_pool_create(const acl_pthread_pool_attr_t *attr);
ACL_API acl_pthread_pool_t *acl_pthread_pool_create(
const acl_pthread_pool_attr_t *attr);

/**
* 当队列堆积的任务数大于空闲线程数的2倍时. 通过此函数设置添加任务的
Expand All @@ -70,7 +72,8 @@ ACL_API acl_pthread_pool_t *acl_pthread_pool_create(const acl_pthread_pool_attr_
* @param timewait_sec {int} 休眠 的时间值, 建议将此值设置为 1--5 秒内
* @return {int} 成功返回 0, 失败返回 -1
*/
ACL_API int acl_pthread_pool_set_timewait(acl_pthread_pool_t *thr_pool, int timewait_sec);
ACL_API int acl_pthread_pool_set_timewait(
acl_pthread_pool_t *thr_pool, int timewait_sec);

/**
* 添加注册函数,在线程创建后立即执行此初始化函数
Expand Down Expand Up @@ -245,21 +248,24 @@ ACL_API void acl_pthread_pool_attr_init(acl_pthread_pool_attr_t *attr);
* @param attr {acl_pthread_pool_attr_t*}
* @param size {size_t}
*/
ACL_API void acl_pthread_pool_attr_set_stacksize(acl_pthread_pool_attr_t *attr, size_t size);
ACL_API void acl_pthread_pool_attr_set_stacksize(
acl_pthread_pool_attr_t *attr, size_t size);

/**
* 设置线程池属性中的最大线程数限制值
* @param attr {acl_pthread_pool_attr_t*}
* @param threads_limit {int} 线程池中的最大线程数
*/
ACL_API void acl_pthread_pool_attr_set_threads_limit(acl_pthread_pool_attr_t *attr, int threads_limit);
ACL_API void acl_pthread_pool_attr_set_threads_limit(
acl_pthread_pool_attr_t *attr, int threads_limit);

/**
* 设置线程池属性中线程空闲超时值
* @param attr {acl_pthread_pool_attr_t*}
* @param idle_timeout {int} 线程空闲超时时间(秒)
*/
ACL_API void acl_pthread_pool_attr_set_idle_timeout(acl_pthread_pool_attr_t *attr, int idle_timeout);
ACL_API void acl_pthread_pool_attr_set_idle_timeout(
acl_pthread_pool_attr_t *attr, int idle_timeout);

#ifdef __cplusplus
}
Expand Down
35 changes: 18 additions & 17 deletions lib_acl/include/thread/acl_pthread_rwlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define ACL_PTHREAD_RWLOCK_INITIALIZER NULL

struct acl_pthread_rwlock {
acl_pthread_mutex_t lock; /* monitor lock acl_pthread_mutex_t */
int state; /* 0 = idle >0 = # of readers -1 = writer */
acl_pthread_cond_t read_signal;
acl_pthread_cond_t write_signal;
int blocked_writers;
acl_pthread_mutex_t lock; /* monitor lock acl_pthread_mutex_t */
int state; /* 0 = idle >0 = # of readers -1 = writer */
acl_pthread_cond_t read_signal;
acl_pthread_cond_t write_signal;
int blocked_writers;
};

struct acl_pthread_rwlockattr {
int pshared;
int pshared;
};

typedef struct acl_pthread_rwlock *acl_pthread_rwlock_t;
Expand All @@ -84,17 +84,18 @@ typedef struct acl_pthread_rwlockattr *acl_pthread_rwlockattr_t;
extern "C" {
#endif

int acl_pthread_rwlock_destroy (acl_pthread_rwlock_t *);
int acl_pthread_rwlock_init (acl_pthread_rwlock_t *, const acl_pthread_rwlockattr_t *);
int acl_pthread_rwlock_rdlock (acl_pthread_rwlock_t *);
int acl_pthread_rwlock_tryrdlock (acl_pthread_rwlock_t *);
int acl_pthread_rwlock_trywrlock (acl_pthread_rwlock_t *);
int acl_pthread_rwlock_unlock (acl_pthread_rwlock_t *);
int acl_pthread_rwlock_wrlock (acl_pthread_rwlock_t *);
int acl_pthread_rwlockattr_init (acl_pthread_rwlockattr_t *);
int acl_pthread_rwlockattr_getpshared (const acl_pthread_rwlockattr_t *, int *);
int acl_pthread_rwlockattr_setpshared (acl_pthread_rwlockattr_t *, int);
int acl_pthread_rwlockattr_destroy (acl_pthread_rwlockattr_t *);
ACL_API int acl_pthread_rwlock_destroy(acl_pthread_rwlock_t *);
ACL_API int acl_pthread_rwlock_init(acl_pthread_rwlock_t *,
const acl_pthread_rwlockattr_t *);
ACL_API int acl_pthread_rwlock_rdlock(acl_pthread_rwlock_t *);
ACL_API int acl_pthread_rwlock_tryrdlock(acl_pthread_rwlock_t *);
ACL_API int acl_pthread_rwlock_trywrlock(acl_pthread_rwlock_t *);
ACL_API int acl_pthread_rwlock_unlock(acl_pthread_rwlock_t *);
ACL_API int acl_pthread_rwlock_wrlock(acl_pthread_rwlock_t *);
ACL_API int acl_pthread_rwlockattr_init(acl_pthread_rwlockattr_t *);
ACL_API int acl_pthread_rwlockattr_getpshared(const acl_pthread_rwlockattr_t *, int *);
ACL_API int acl_pthread_rwlockattr_setpshared(acl_pthread_rwlockattr_t *, int);
ACL_API int acl_pthread_rwlockattr_destroy(acl_pthread_rwlockattr_t *);

#if defined(__cplusplus)
}
Expand Down
3 changes: 2 additions & 1 deletion lib_acl/include/thread/acl_sem.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ struct ACL_SEM {
unsigned int volatile count;
};

ACL_API ACL_SEM *acl_sem_create2(const char *pathname, unsigned int initial_value);
ACL_API ACL_SEM *acl_sem_create2(const char *pathname,
unsigned int initial_value);
ACL_API ACL_SEM *acl_sem_create(unsigned int initial_value);
ACL_API void acl_sem_destroy(ACL_SEM *sem);
ACL_API int acl_sem_wait_timeout(ACL_SEM *sem, unsigned int timeout);
Expand Down
Loading

0 comments on commit e2bbbac

Please sign in to comment.