tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: pthread library related
On May 30, 10:33am, charles.cui1984%gmail.com@localhost (Charles Cui) wrote:
-- Subject: Re: pthread library related
Looks good, but be careful with whitespace in general:
@@ -316,7 +316,7 @@ ksem_create(lwp_t *l, const char *name, ksem_t **ksret, mode_t mode, u_int val)
if (val > SEM_VALUE_MAX) {
return EINVAL;
}
-
+
Why extra whitespace here.
if (name != NULL) {
len = strlen(name);
if (len > SEM_MAX_NAMELEN) {
@@ -333,6 +333,14 @@ ksem_create(lwp_t *l, const char *name, ksem_t **ksret, mode_t mode, u_int val)
len = 0;
}
+ mutex_enter(&ksem_lock);
+ if (l->l_proc->p_nsems >= SEM_NSEMS_MAX) {
+ mutex_exit(&ksem_lock);
+ return -1;
+ }
+ l->l_proc->p_nsems += 1;
+ mutex_exit(&ksem_lock);
+
Mixed tabs and spaces. Better use atomics.
ks = kmem_zalloc(sizeof(ksem_t), KM_SLEEP);
mutex_init(&ks->ks_lock, MUTEX_DEFAULT, IPL_NONE);
cv_init(&ks->ks_cv, "psem");
@@ -347,6 +355,7 @@ ksem_create(lwp_t *l, const char *name, ksem_t **ksret, mode_t mode, u_int val)
ks->ks_gid = kauth_cred_getegid(uc);
atomic_inc_uint(&nsems_total);
+
*ksret = ks;
return 0;
}
Avoid touching code that has nothing to do with your change.
@@ -366,6 +375,10 @@ ksem_free(ksem_t *ks)
kmem_free(ks, sizeof(ksem_t));
atomic_dec_uint(&nsems_total);
+
+ mutex_enter(&ksem_lock);
+ curproc->p_nsems -= 1;
+ mutex_exit(&ksem_lock);
Better use atomics
}
int
Home |
Main Index |
Thread Index |
Old Index