mirror of
https://github.com/upa/mscp.git
synced 2026-02-27 18:54:42 +08:00
add message.h and message.c, mscp_set|get_error()
Instead of pr_err(), libmscp uses mscp_set_error() and applications use mscp_get_errror() to get error message.
This commit is contained in:
26
src/atomic.h
26
src/atomic.h
@@ -2,8 +2,10 @@
|
||||
#define _ATOMIC_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <message.h>
|
||||
|
||||
typedef int refcnt;
|
||||
|
||||
@@ -28,31 +30,13 @@ static inline void lock_init(lock *l)
|
||||
static inline void lock_acquire(lock *l)
|
||||
{
|
||||
int ret = pthread_mutex_lock(l);
|
||||
if (ret < 0) {
|
||||
switch (ret) {
|
||||
case EINVAL:
|
||||
pr_err("invalid mutex\n");
|
||||
exit(1);
|
||||
case EDEADLK:
|
||||
pr_err("a deadlock would occur\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
assert(ret == 0);
|
||||
}
|
||||
|
||||
static inline void lock_release(lock *l)
|
||||
{
|
||||
int ret = pthread_mutex_unlock(l);
|
||||
if (ret < 0) {
|
||||
switch (ret) {
|
||||
case EINVAL:
|
||||
pr_err("invalid mutex\n");
|
||||
exit(1);
|
||||
case EPERM:
|
||||
pr_err("this thread does not hold this mutex\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
assert(ret == 0);
|
||||
}
|
||||
|
||||
static inline void lock_release_via_cleanup(void *l)
|
||||
|
||||
Reference in New Issue
Block a user