From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: <86ipx4s36p.fsf@cmarib.ramside> <86ei7ry76s.fsf@cmarib.ramside> <86zkqf46vz.fsf@cmarib.ramside> <86mxmfuiep.fsf_-_@cmarib.ramside> Date: Thu, 17 Feb 2011 21:34:18 -0800 Message-ID: From: Paul Lalonde To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [9fans] Modern development language for Plan 9, WAS: Re: RESOLVED: recoving important header file rudely Topicbox-Message-UUID: b0168250-ead6-11e9-9d60-3106f5b1d025 Best recent c99 example: int foo[] =3D { [0] =3D 1, [1] =3D 2, [2] =3D 4, [3] =3D 8, [4] =3D 16, [5] =3D 32 }; I shudder to think about foo[6]. Paul On Thursday, February 17, 2011, ron minnich wrote: > I was looking at another fine example of modern programming from glibc > and just had to share it. > > Where does the getpid happen? It's anyone's guess. This is just so > readable too ... I'm glad they want to such effort to optimize getpid. > > ron > > #ifndef NOT_IN_libc > static inline __attribute__((always_inline)) pid_t really_getpid (pid_t o= ldval); > > static inline __attribute__((always_inline)) pid_t > really_getpid (pid_t oldval) > { > =A0if (__builtin_expect (oldval =3D=3D 0, 1)) > =A0 =A0{ > =A0 =A0 =A0pid_t selftid =3D THREAD_GETMEM (THREAD_SELF, tid); > =A0 =A0 =A0if (__builtin_expect (selftid !=3D 0, 1)) > =A0 =A0 =A0 =A0return selftid; > =A0 =A0} > > =A0INTERNAL_SYSCALL_DECL (err); > =A0pid_t result =3D INTERNAL_SYSCALL (getpid, err, 0); > > =A0/* We do not set the PID field in the TID here since we might be > =A0 =A0 called from a signal handler while the thread executes fork. =A0= */ > =A0if (oldval =3D=3D 0) > =A0 =A0THREAD_SETMEM (THREAD_SELF, tid, result); > =A0return result; > } > #endif > > pid_t > __getpid (void) > { > #ifdef NOT_IN_libc > =A0INTERNAL_SYSCALL_DECL (err); > =A0pid_t result =3D INTERNAL_SYSCALL (getpid, err, 0); > #else > =A0pid_t result =3D THREAD_GETMEM (THREAD_SELF, pid); > =A0if (__builtin_expect (result <=3D 0, 0)) > =A0 =A0result =3D really_getpid (result); > #endif > =A0return result; > } > > libc_hidden_def (__getpid) > weak_alias (__getpid, getpid) > libc_hidden_def (getpid) > > --=20 I'm migrating my email. plalonde@telus.net will soon be disconnected. Please use paul.a.lalonde@gmail.com from now on.